From 63466eb4fa758b0dd5940e16e03a9c2c057a19db Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Mon, 13 Dec 2021 15:04:12 +0600 Subject: [PATCH] Stable kanban (#613) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- .../src/components/KanbanPanel.svelte | 4 +- .../src/components/KanbanView.svelte | 76 ++++--------------- 2 files changed, 16 insertions(+), 64 deletions(-) diff --git a/plugins/view-resources/src/components/KanbanPanel.svelte b/plugins/view-resources/src/components/KanbanPanel.svelte index f997f73a66..c5d0245c8d 100644 --- a/plugins/view-resources/src/components/KanbanPanel.svelte +++ b/plugins/view-resources/src/components/KanbanPanel.svelte @@ -23,7 +23,7 @@ export let addAction: () => void | undefined -
+
@@ -36,7 +36,7 @@
-
+
diff --git a/plugins/view-resources/src/components/KanbanView.svelte b/plugins/view-resources/src/components/KanbanView.svelte index cd31a068a2..afd0dbf8ac 100644 --- a/plugins/view-resources/src/components/KanbanView.svelte +++ b/plugins/view-resources/src/components/KanbanView.svelte @@ -1,15 +1,15 @@ @@ -20,7 +20,7 @@ import { getResource } from '@anticrm/platform' import { createQuery, getClient } from '@anticrm/presentation' import type { AnySvelteComponent } from '@anticrm/ui' - import { AnyComponent, Loading, ScrollBox, showPopup } from '@anticrm/ui' + import { AnyComponent, Loading, ScrollBox } from '@anticrm/ui' import type { Kanban } from '@anticrm/view' import view from '@anticrm/view' import KanbanPanel from './KanbanPanel.svelte' @@ -58,8 +58,6 @@ return x } - - const statesQuery = createQuery() $: if (kanbanStates.length > 0) statesQuery.query(core.class.State, { _id: { $in: kanbanStates } }, result => { rawStates = result }) $: states = sort(kanban, rawStates) @@ -77,10 +75,7 @@ } } - let currentOp: Promise | undefined - - async function move (to: number, state: Ref) { - console.log('INITIAL', dragCardInitialPosition, 'TO', to) + async function move (state: Ref) { const id = dragCard._id const txes: TxCUD[] = [] @@ -92,73 +87,25 @@ } else { client.updateDoc(_class, space, id, { state }) } - // txes.push(client.txFactory.createTxUpdateDoc(_class, space, id, { state })) } - if (dragCardInitialPosition !== to) { + if (dragCardInitialPosition !== dragCardEndPosition) { client.updateDoc(view.class.Kanban, space, kanban._id, { $move: { order: { $value: id, - $position: to + $position: dragCardEndPosition } } }) - - // txes.push(client.txFactory.createTxUpdateDoc(view.class.Kanban, space, kanban._id, { - // $move: { - // order: { - // $value: id, - // $position: to - // } - // } - // })) - - // await client.updateDoc(core.class.SpaceWithStates, core.space.Model, space, { - // $pull: { - // order: id - // } - // }) - - // client.updateDoc(core.class.SpaceWithStates, core.space.Model, space, { - // $push: { - // order: { - // $each: [id], - // $position: to - // } - // } - // }) } - - // if (txes.length > 0) { - // const updateTx = client.txFactory.createTxBulkWrite(space, txes) - // if (currentOp) { - // await currentOp - // } - // currentOp = client.tx(updateTx).then(() => console.log('move done')).catch(err => console.log('move error ' + err)) - // } - } - - function getValue (doc: Doc, key: string): any { - if (key.length === 0) - { return doc } - const path = key.split('.') - const len = path.length - let obj = doc as any - for (let i = 0; i < len; i++) { - obj = obj?.[path[i]] - } - return obj } const client = getClient() - function onClick (object: Doc) { - showPopup(open, { object, space }, 'float') - } - let dragCard: Doc let dragCardInitialPosition: number + let dragCardEndPosition: number let dragCardInitialState: Ref async function cardPresenter (_class: Ref>): Promise { @@ -182,6 +129,9 @@ if (dragCard.state !== state._id) { dragCard.state = state._id } + }} + on:drop={() => { + move(state._id) }}> {#each objects as object, j (object)} @@ -190,15 +140,17 @@ class="step-tb75" on:dragover|preventDefault={(ev) => { dragover(ev, object) + dragCardEndPosition = j }} on:drop|preventDefault={() => { - move(j, state._id) + dragCardEndPosition = j }} > { dragCardInitialState = state._id dragCardInitialPosition = j + dragCardEndPosition = j dragCard = objects[j] }}/>