From 9d6e2f2076ae970f3fccb82e524aaea76f162e55 Mon Sep 17 00:00:00 2001 From: Ilya Sumbatyants Date: Tue, 14 Dec 2021 20:33:30 +0700 Subject: [PATCH] Update doneStates of existing kanban cards (#625) Signed-off-by: Ilya Sumbatyants --- models/all/src/migration.ts | 2 + models/lead/src/migration.ts | 15 ++++++ models/recruit/src/index.ts | 2 + models/recruit/src/migration.ts | 54 +++++++++++++++++++ models/task/src/migration.ts | 14 +++++ .../src/components/KanbanView.svelte | 19 +++++-- 6 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 models/recruit/src/migration.ts diff --git a/models/all/src/migration.ts b/models/all/src/migration.ts index 69e5c3a7b6..e49deae781 100644 --- a/models/all/src/migration.ts +++ b/models/all/src/migration.ts @@ -19,11 +19,13 @@ import { MigrateOperation } from '@anticrm/model' import { taskOperation } from '@anticrm/model-task' import { attachmentOperation } from '@anticrm/model-attachment' import { leadOperation } from '@anticrm/model-lead' +import { recruitOperation } from '@anticrm/model-recruit' import { viewOperation } from '@anticrm/model-view' export const migrateOperations: MigrateOperation[] = [ taskOperation, attachmentOperation, leadOperation, + recruitOperation, viewOperation ] diff --git a/models/lead/src/migration.ts b/models/lead/src/migration.ts index 3533e90869..98577289eb 100644 --- a/models/lead/src/migration.ts +++ b/models/lead/src/migration.ts @@ -42,5 +42,20 @@ export const leadOperation: MigrateOperation = { } else { console.log('Lead: => default funnel Kanban is ok') } + + const outdatedLeads = (await client.findAll(lead.class.Lead, {})) + .filter((x) => x.doneState === undefined) + + await Promise.all( + outdatedLeads.map(async (lead) => { + console.info('Upgrade lead:', lead._id) + + try { + await ops.updateDoc(lead._class, lead.space, lead._id, { doneState: null }) + } catch (err: unknown) { + console.error(err) + } + }) + ) } } diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 68c6384035..fd12b63967 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -251,3 +251,5 @@ export function createModel (builder: Builder): void { } export { default } from './plugin' + +export { recruitOperation } from './migration' diff --git a/models/recruit/src/migration.ts b/models/recruit/src/migration.ts new file mode 100644 index 0000000000..20d2551102 --- /dev/null +++ b/models/recruit/src/migration.ts @@ -0,0 +1,54 @@ +// +// Copyright © 2020, 2021 Anticrm Platform Contributors. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import { TxOperations } from '@anticrm/core' +import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import core from '@anticrm/model-core' + +import recruit from './plugin' + +export const recruitOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise { + + }, + async upgrade (client: MigrationUpgradeClient): Promise { + console.log('Recruit: Performing model upgrades') + + const ops = new TxOperations(client, core.account.System) + + const outdatedApplications = (await client.findAll(recruit.class.Applicant, {})) + .filter((x) => x.doneState === undefined) + + await Promise.all( + outdatedApplications.map(async (application) => { + console.info('Upgrade application:', application._id) + + try { + await ops.updateCollection( + application._class, + application.space, + application._id, + application.attachedTo, + application.attachedToClass, + application.collection, + { doneState: null } + ) + } catch (err: unknown) { + console.error(err) + } + }) + ) + } +} diff --git a/models/task/src/migration.ts b/models/task/src/migration.ts index 06853b1a93..74a6f6fc5b 100644 --- a/models/task/src/migration.ts +++ b/models/task/src/migration.ts @@ -51,5 +51,19 @@ export const taskOperation: MigrateOperation = { } else { console.log('Task: => public project Kanban is ok') } + + const outdatedTasks = (await client.findAll(task.class.Task, {})) + .filter((x) => x.doneState === undefined) + + await Promise.all( + outdatedTasks.map(async (task) => { + console.info('Upgrade task:', task._id) + try { + await ops.updateDoc(task._class, task.space, task._id, { doneState: null }) + } catch (err: unknown) { + console.error(err) + } + }) + ) } } diff --git a/plugins/view-resources/src/components/KanbanView.svelte b/plugins/view-resources/src/components/KanbanView.svelte index fc8c899517..594e101d7c 100644 --- a/plugins/view-resources/src/components/KanbanView.svelte +++ b/plugins/view-resources/src/components/KanbanView.svelte @@ -129,9 +129,22 @@ } const onDone = (state: DoneState) => async () => { - await client.updateDoc(dragCard._class, dragCard.space, dragCard._id, { - doneState: state._id - }) + if (client.getHierarchy().isDerived(_class, core.class.AttachedDoc)) { + const adoc: AttachedDoc = dragCard as Doc as AttachedDoc + await client.updateCollection( + _class, + space, + adoc._id as Ref as Ref, + adoc.attachedTo, + adoc.attachedToClass, + adoc.collection, + { doneState: state._id } + ) + } else { + await client.updateDoc(dragCard._class, dragCard.space, dragCard._id, { + doneState: state._id + }) + } isDragging = false hoveredDoneState = undefined