Fix board preference (#1807)

Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
Alex 2022-05-20 14:19:45 +07:00 committed by GitHub
parent 06867083d1
commit 4ae5e95280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 25 deletions

View File

@ -14,7 +14,7 @@
// //
// To help typescript locate view plugin properly // To help typescript locate view plugin properly
import type { Board, Card, CardDate, CardLabel, MenuPage, LabelsCompactMode } from '@anticrm/board' import type { Board, Card, CardDate, CardLabel, MenuPage, CommonBoardPreference } from '@anticrm/board'
import type { Employee } from '@anticrm/contact' import type { Employee } from '@anticrm/contact'
import { DOMAIN_MODEL, IndexKind, Markup, Ref, Timestamp, Type } from '@anticrm/core' import { DOMAIN_MODEL, IndexKind, Markup, Ref, Timestamp, Type } from '@anticrm/core'
import { import {
@ -36,7 +36,7 @@ import contact from '@anticrm/model-contact'
import core, { TAttachedDoc, TDoc, TObj } from '@anticrm/model-core' import core, { TAttachedDoc, TDoc, TObj } from '@anticrm/model-core'
import task, { TSpaceWithStates, TTask } from '@anticrm/model-task' import task, { TSpaceWithStates, TTask } from '@anticrm/model-task'
import view, { actionTemplates, createAction } from '@anticrm/model-view' import view, { actionTemplates, createAction } from '@anticrm/model-view'
import workbench from '@anticrm/model-workbench' import workbench, { Application } from '@anticrm/model-workbench'
import { IntlString } from '@anticrm/platform' import { IntlString } from '@anticrm/platform'
import type { AnyComponent } from '@anticrm/ui' import type { AnyComponent } from '@anticrm/ui'
import preference, { TPreference } from '@anticrm/model-preference' import preference, { TPreference } from '@anticrm/model-preference'
@ -72,10 +72,12 @@ export class TCardLabel extends TAttachedDoc implements CardLabel {
isHidden?: boolean isHidden?: boolean
} }
@Model(board.class.LabelsCompactMode, preference.class.Preference) @Model(board.class.CommonBoardPreference, preference.class.Preference)
export class TLabelsCompactMode extends TPreference implements LabelsCompactMode { export class TCommonBoardPreference extends TPreference implements CommonBoardPreference {
@Prop(TypeRef(board.class.Board), board.string.LabelsCompactMode) @Prop(TypeRef(workbench.class.Application), board.string.CommonBoardPreference)
attachedTo!: Ref<Board> attachedTo!: Ref<Application>
cardLabelsCompactMode!: boolean
} }
@Model(board.class.Card, task.class.Task) @Model(board.class.Card, task.class.Task)
@ -123,7 +125,7 @@ export class TMenuPage extends TDoc implements MenuPage {
} }
export function createModel (builder: Builder): void { export function createModel (builder: Builder): void {
builder.createModel(TBoard, TCard, TCardLabel, TCardDate, TMenuPage, TLabelsCompactMode) builder.createModel(TBoard, TCard, TCardLabel, TCardDate, TMenuPage, TCommonBoardPreference)
builder.createDoc(board.class.MenuPage, core.space.Model, { builder.createDoc(board.class.MenuPage, core.space.Model, {
component: board.component.Archive, component: board.component.Archive,

View File

@ -55,6 +55,6 @@ export default mergeIds(boardId, board, {
Table: '' as Ref<ViewletDescriptor> Table: '' as Ref<ViewletDescriptor>
}, },
string: { string: {
LabelsCompactMode: '' as IntlString CommonBoardPreference: '' as IntlString
} }
}) })

View File

@ -13,14 +13,13 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import type { Card, CardLabel, LabelsCompactMode } from '@anticrm/board' import type { Card, CardLabel } from '@anticrm/board'
import { getClient } from '@anticrm/presentation'
import preference from '@anticrm/preference'
import { createQuery, getClient } from '@anticrm/presentation'
import { Button, IconAdd } from '@anticrm/ui' import { Button, IconAdd } from '@anticrm/ui'
import { invokeAction } from '@anticrm/view-resources' import { invokeAction } from '@anticrm/view-resources'
import board from '../../plugin' import board from '../../plugin'
import { commonBoardPreference } from '../../utils/BoardUtils'
import { getCardActions } from '../../utils/CardActionUtils' import { getCardActions } from '../../utils/CardActionUtils'
import LabelPresenter from '../presenters/LabelPresenter.svelte' import LabelPresenter from '../presenters/LabelPresenter.svelte'
@ -28,14 +27,12 @@
export let isInline: boolean = false export let isInline: boolean = false
const client = getClient() const client = getClient()
const query = createQuery()
let labels: CardLabel[] let labels: CardLabel[]
let labelsHandler: (e: Event) => void let labelsHandler: (e: Event) => void
let isHovered: boolean = false let isHovered: boolean = false
let modePreference: LabelsCompactMode | undefined
$: isCompact = isInline ? !!modePreference : false $: isCompact = $commonBoardPreference?.cardLabelsCompactMode
$: if (value.labels && value.labels.length > 0) { $: if (value.labels && value.labels.length > 0) {
client.findAll(board.class.CardLabel, { _id: { $in: value.labels } }).then((result) => { client.findAll(board.class.CardLabel, { _id: { $in: value.labels } }).then((result) => {
@ -44,9 +41,6 @@
} else { } else {
labels = [] labels = []
} }
$: query.query(board.class.LabelsCompactMode, { attachedTo: value.space }, (result) => {
;[modePreference] = result
})
if (!isInline) { if (!isInline) {
getCardActions(client, { getCardActions(client, {
@ -60,8 +54,7 @@
function toggleCompact () { function toggleCompact () {
if (!isInline) return if (!isInline) return
if (modePreference) client.remove(modePreference) client.update($commonBoardPreference, { cardLabelsCompactMode: !isCompact })
else client.createDoc(board.class.LabelsCompactMode, preference.space.Preference, { attachedTo: value.space })
} }
function hoverIn () { function hoverIn () {
@ -88,7 +81,7 @@
{#each labels as label} {#each labels as label}
<LabelPresenter <LabelPresenter
value={label} value={label}
size={isCompact ? 'tiny' : isInline ? 'x-small' : undefined} size={isInline ? (isCompact ? 'tiny' : 'x-small') : undefined}
{isHovered} {isHovered}
on:click={labelsHandler} on:click={labelsHandler}
/> />

View File

@ -1,7 +1,10 @@
import board, { Board, CardLabel, Card } from '@anticrm/board' import { readable } from 'svelte/store'
import board, { Board, CardLabel, Card, CommonBoardPreference } from '@anticrm/board'
import core, { Ref, TxOperations, Space } from '@anticrm/core' import core, { Ref, TxOperations, Space } from '@anticrm/core'
import type { KanbanTemplate, TodoItem } from '@anticrm/task' import type { KanbanTemplate, TodoItem } from '@anticrm/task'
import preference from '@anticrm/preference'
import { createKanban } from '@anticrm/task' import { createKanban } from '@anticrm/task'
import { createQuery, getClient } from '@anticrm/presentation'
import { import {
hexColorToNumber, hexColorToNumber,
FernColor, FernColor,
@ -127,3 +130,13 @@ export function getDateIcon (item: TodoItem): 'normal' | 'warning' | 'overdue' {
const dueDate = new Date(item.dueTo) const dueDate = new Date(item.dueTo)
return areDatesEqual(date, dueDate) ? 'warning' : dueDate < date ? 'overdue' : 'normal' return areDatesEqual(date, dueDate) ? 'warning' : dueDate < date ? 'overdue' : 'normal'
} }
export const commonBoardPreference = readable<CommonBoardPreference>(undefined, (set) => {
createQuery().query(board.class.CommonBoardPreference, { attachedTo: board.app.Board }, (result) => {
if (result.total > 0) return set(result[0])
void getClient().createDoc(board.class.CommonBoardPreference, preference.space.Preference, {
attachedTo: board.app.Board,
cardLabelsCompactMode: false
})
})
})

View File

@ -102,8 +102,8 @@ export interface MenuPage extends Doc {
/** /**
* @public * @public
*/ */
export interface LabelsCompactMode extends Preference { export interface CommonBoardPreference extends Preference {
attachedTo: Ref<Board> cardLabelsCompactMode: boolean
} }
/** /**
* @public * @public
@ -123,7 +123,7 @@ const boards = plugin(boardId, {
CardDate: '' as Ref<Class<CardDate>>, CardDate: '' as Ref<Class<CardDate>>,
CardLabel: '' as Ref<Class<CardLabel>>, CardLabel: '' as Ref<Class<CardLabel>>,
MenuPage: '' as Ref<Class<MenuPage>>, MenuPage: '' as Ref<Class<MenuPage>>,
LabelsCompactMode: '' as Ref<Class<LabelsCompactMode>> CommonBoardPreference: '' as Ref<Class<CommonBoardPreference>>
}, },
category: { category: {
Card: '' as Ref<ActionCategory> Card: '' as Ref<ActionCategory>