move order and statuses to Kanban

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-10-09 17:02:32 +02:00
parent 901e781803
commit 1b10e7b3e4
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
5 changed files with 22 additions and 23 deletions

View File

@ -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<Space>
states!: Arr<Ref<State>>
order!: Arr<Ref<Doc>>
}

View File

@ -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: []
})
}

View File

@ -39,32 +39,28 @@
export let options: FindOptions<Doc> | undefined
export let config: string[]
let _space: SpaceWithStates | undefined
let kanban: Kanban
let states: State[] = []
let objects: (Doc & { state: Ref<State> })[] = []
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<Ref<State>, State>())
return _space.states.map(id => map.get(id) as State )
return kanban.states.map(id => map.get(id) as State )
}
function sortObjects<T extends Doc> (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<Ref<Doc>, 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)

View File

@ -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<Space>
states: Arr<Ref<State>>
order: Arr<Ref<Doc>>
}

View File

@ -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<SpaceWithStates>
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<Ref<State>, 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<State>
@ -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
}