From 1b10e7b3e4c30612b016a0036536b4c262dda6ec Mon Sep 17 00:00:00 2001 From: Andrey Platov Date: Sat, 9 Oct 2021 17:02:32 +0200 Subject: [PATCH] move `order` and `statuses` to `Kanban` Signed-off-by: Andrey Platov --- models/view/src/index.ts | 3 ++- .../src/components/CreateVacancy.svelte | 6 +++--- .../src/components/KanbanView.svelte | 12 ++++------- plugins/view/src/index.ts | 3 ++- .../src/components/EditStatuses.svelte | 21 ++++++++++--------- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/models/view/src/index.ts b/models/view/src/index.ts index 4639d11a3f..8625f5ca67 100644 --- a/models/view/src/index.ts +++ b/models/view/src/index.ts @@ -14,7 +14,7 @@ // import type { IntlString, Asset, Resource } from '@anticrm/platform' -import type { Ref, Class, Space, Doc, Arr, Domain } from '@anticrm/core' +import type { Ref, Class, Space, Doc, Arr, Domain, State } from '@anticrm/core' import { DOMAIN_MODEL } from '@anticrm/core' import { Model, Mixin, Builder } from '@anticrm/model' import type { AnyComponent } from '@anticrm/ui' @@ -76,6 +76,7 @@ export class TActionTarget extends TDoc implements ActionTarget { @Model(view.class.Kanban, core.class.Doc, DOMAIN_KANBAN) export class TKanban extends TDoc implements Kanban { attachedTo!: Ref + states!: Arr> order!: Arr> } diff --git a/plugins/recruit-resources/src/components/CreateVacancy.svelte b/plugins/recruit-resources/src/components/CreateVacancy.svelte index b4f3778e1d..4d5c606e1e 100644 --- a/plugins/recruit-resources/src/components/CreateVacancy.svelte +++ b/plugins/recruit-resources/src/components/CreateVacancy.svelte @@ -72,11 +72,11 @@ title: 'Final', color: colors[0] }) - await client.updateDoc(recruit.class.Vacancy, core.space.Model, id, { - states: [s1, s2, s3, s4, s5, s6] - }) + // await client.updateDoc(recruit.class.Vacancy, core.space.Model, id, { + // }) await client.createDoc(view.class.Kanban, id, { attachedTo: id, + states: [s1, s2, s3, s4, s5, s6], order: [] }) } diff --git a/plugins/view-resources/src/components/KanbanView.svelte b/plugins/view-resources/src/components/KanbanView.svelte index d3cb7261cf..1ad65d0d45 100644 --- a/plugins/view-resources/src/components/KanbanView.svelte +++ b/plugins/view-resources/src/components/KanbanView.svelte @@ -39,32 +39,28 @@ export let options: FindOptions | undefined export let config: string[] - let _space: SpaceWithStates | undefined let kanban: Kanban let states: State[] = [] let objects: (Doc & { state: Ref })[] = [] - const spaceQuery = createQuery() - $: spaceQuery.query(core.class.SpaceWithStates, { _id: space }, result => { _space = result[0] }) - const kanbanQuery = createQuery() $: kanbanQuery.query(view.class.Kanban, { attachedTo: space }, result => { kanban = result[0] }) function sort(states: State[]): State[] { - if (_space === undefined || states.length === 0) { return [] } + if (kanban === undefined || states.length === 0) { return [] } const map = states.reduce((map, state) => { map.set(state._id, state); return map }, new Map, State>()) - return _space.states.map(id => map.get(id) as State ) + return kanban.states.map(id => map.get(id) as State ) } function sortObjects (objects: T[]): T[] { - if (_space === undefined || objects.length === 0) { return [] } + if (kanban === undefined || objects.length === 0) { return [] } const map = objects.reduce((map, doc) => { map.set(doc._id, doc); return map }, new Map, Doc>()) const x = kanban.order.map(id => map.get(id) as T) return x } const statesQuery = createQuery() - $: statesQuery.query(core.class.State, { _id: { $in: _space?.states ?? [] } }, result => { states = sort(result) }) + $: statesQuery.query(core.class.State, { _id: { $in: kanban?.states ?? [] } }, result => { states = sort(result) }) const query = createQuery() $: query.query(_class, { space }, result => { objects = sortObjects(result) }, options) diff --git a/plugins/view/src/index.ts b/plugins/view/src/index.ts index 1a2806c4bb..b96cde3b80 100644 --- a/plugins/view/src/index.ts +++ b/plugins/view/src/index.ts @@ -16,7 +16,7 @@ import type { Plugin, Asset, Resource } from '@anticrm/platform' import { plugin } from '@anticrm/platform' -import type { Ref, Mixin, UXObject, Space, FindOptions, Class, Doc, Arr } from '@anticrm/core' +import type { Ref, Mixin, UXObject, Space, FindOptions, Class, Doc, Arr, State } from '@anticrm/core' import type { AnyComponent } from '@anticrm/ui' @@ -86,6 +86,7 @@ export interface ActionTarget extends Doc { */ export interface Kanban extends Doc { attachedTo: Ref + states: Arr> order: Arr> } diff --git a/plugins/workbench-resources/src/components/EditStatuses.svelte b/plugins/workbench-resources/src/components/EditStatuses.svelte index f488cc7e63..dfee0b3650 100644 --- a/plugins/workbench-resources/src/components/EditStatuses.svelte +++ b/plugins/workbench-resources/src/components/EditStatuses.svelte @@ -18,6 +18,7 @@ import type { Ref, SpaceWithStates, State } from '@anticrm/core' import { CircleButton, IconAdd, Label, IconMoreH, ActionIcon, showPopup, ScrollBox } from '@anticrm/ui' import { createQuery, getClient, AttributeEditor } from '@anticrm/presentation' + import type { Kanban } from '@anticrm/view' import { createEventDispatcher } from 'svelte' import Close from './icons/Close.svelte' import Circles from './icons/Circles.svelte' @@ -25,10 +26,11 @@ import ColorsPopup from './ColorsPopup.svelte' import core from '@anticrm/core' + import view from '@anticrm/view' export let _id: Ref - let space: SpaceWithStates | undefined + let kanban: Kanban | undefined let states: State[] = [] let elements: HTMLElement[] = [] @@ -36,20 +38,19 @@ const client = getClient() function sort(states: State[]): State[] { - if (space === undefined || states.length === 0) { return [] } + if (kanban === undefined || states.length === 0) { return [] } console.log(states) const map = states.reduce((map, state) => { map.set(state._id, state); return map }, new Map, State>()) - console.log(space.states) - const x = space.states.map(id => map.get(id) as State ) - // console.log(x) + console.log(kanban.states) + const x = kanban.states.map(id => map.get(id) as State ) return x } - const spaceQuery = createQuery() - $: spaceQuery.query(core.class.SpaceWithStates, { _id }, result => { space = result[0] }) + const kanbanQuery = createQuery() + $: kanbanQuery.query(view.class.Kanban, { attachedTo: _id }, result => { kanban = result[0] }) const query = createQuery() - $: query.query(core.class.State, { _id: { $in: space?.states ?? [] } }, result => { states = sort(result) }) + $: query.query(core.class.State, { _id: { $in: kanban?.states ?? [] } }, result => { states = sort(result) }) let selected: number | undefined let dragState: Ref @@ -77,7 +78,7 @@ } async function move(to: number) { - client.updateDoc(core.class.SpaceWithStates, core.space.Model, _id, { + client.updateDoc(view.class.Kanban, _id, (kanban as Kanban)._id, { $move: { states: { $value: dragState, @@ -94,7 +95,7 @@ title: 'New State', color: '#7C6FCD' }) - await client.updateDoc(core.class.SpaceWithStates, core.space.Model, _id, { + await client.updateDoc(view.class.Kanban, _id, (kanban as Kanban)._id, { $push: { states: state }