diff --git a/models/board/src/index.ts b/models/board/src/index.ts index db0ecd50b6..b26129140e 100644 --- a/models/board/src/index.ts +++ b/models/board/src/index.ts @@ -16,7 +16,17 @@ // To help typescript locate view plugin properly import type { Board, Card, CardAction, CardDate, CardLabel, MenuPage } from '@anticrm/board' import type { Employee } from '@anticrm/contact' -import { TxOperations as Client, Doc, DOMAIN_MODEL, FindOptions, IndexKind, Ref, Type, Timestamp } from '@anticrm/core' +import { + TxOperations as Client, + Doc, + DOMAIN_MODEL, + FindOptions, + IndexKind, + Ref, + Type, + Timestamp, + Markup +} from '@anticrm/core' import { ArrOf, Builder, @@ -86,10 +96,10 @@ export class TCard extends TTask implements Card { @Prop(TypeMarkup(), board.string.Description) @Index(IndexKind.FullText) - description!: string + description!: Markup @Prop(Collection(board.class.CardLabel), board.string.Labels) - labels?: Ref[] + labels!: Ref[] @Prop(TypeString(), board.string.Location) @Index(IndexKind.FullText) diff --git a/models/board/src/migration.ts b/models/board/src/migration.ts index bb2037c09f..41b1ebe30d 100644 --- a/models/board/src/migration.ts +++ b/models/board/src/migration.ts @@ -16,7 +16,7 @@ import { Doc, Ref, Space, TxOperations } from '@anticrm/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' import core from '@anticrm/model-core' -import { createKanbanTemplate, createSequence } from '@anticrm/model-task' +import { createKanbanTemplate, createSequence, DOMAIN_TASK } from '@anticrm/model-task' import task, { createKanban, KanbanTemplate } from '@anticrm/task' import board from './plugin' @@ -76,8 +76,17 @@ async function createDefaults (tx: TxOperations): Promise { await createDefaultKanban(tx) } +async function migrateLabels (client: MigrationClient): Promise { + const cards = await client.find(DOMAIN_TASK, { _class: board.class.Card, labels: { $exists: false, $in: [null] } }) + for (const card of cards) { + await client.update(DOMAIN_TASK, { _id: card._id }, { labels: [] }) + } +} + export const boardOperation: MigrateOperation = { - async migrate (client: MigrationClient): Promise {}, + async migrate (client: MigrationClient): Promise { + await Promise.all([migrateLabels(client)]) + }, async upgrade (client: MigrationUpgradeClient): Promise { const ops = new TxOperations(client, core.account.System) await createDefaults(ops) diff --git a/models/task/src/index.ts b/models/task/src/index.ts index 8a04c1fedc..35bbdd9c3f 100644 --- a/models/task/src/index.ts +++ b/models/task/src/index.ts @@ -122,15 +122,21 @@ export class TTask extends TAttachedDoc implements Task { @Model(task.class.TodoItem, core.class.AttachedDoc, DOMAIN_TASK) @UX(task.string.Todo) export class TTodoItem extends TAttachedDoc implements TodoItem { - @Prop(TypeString(), task.string.TodoName, task.icon.Task) + @Prop(TypeMarkup(), task.string.TodoName, task.icon.Task) @Index(IndexKind.FullText) name!: string + @Prop(TypeRef(contact.class.Employee), task.string.TaskAssignee) + assignee!: Ref | null + @Prop(TypeBoolean(), task.string.TaskDone) done!: boolean @Prop(TypeDate(), task.string.TaskDueTo) - dueTo?: Timestamp + dueTo!: Timestamp | null + + @Prop(Collection(task.class.TodoItem), task.string.Todos) + items!: number } @Model(task.class.SpaceWithStates, core.class.Space) diff --git a/models/task/src/migration.ts b/models/task/src/migration.ts index 6b96248d53..ea8633a5c5 100644 --- a/models/task/src/migration.ts +++ b/models/task/src/migration.ts @@ -17,6 +17,7 @@ import { Class, Doc, Ref, Space, TxOperations } from '@anticrm/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' import core from '@anticrm/model-core' import { KanbanTemplate, StateTemplate, DoneStateTemplate, genRanks, createKanban } from '@anticrm/task' +import { DOMAIN_TASK } from '.' import task from './plugin' /** @@ -176,8 +177,22 @@ async function createDefaults (tx: TxOperations): Promise { await createDefaultKanban(tx) } +async function migrateTodoItems (client: MigrationClient): Promise { + const assigneeTodos = await client.find(DOMAIN_TASK, { _class: task.class.TodoItem, assignee: { $exists: false } }) + for (const todo of assigneeTodos) { + await client.update(DOMAIN_TASK, { _id: todo._id }, { assignee: null }) + } + + const dueToTodos = await client.find(DOMAIN_TASK, { _class: task.class.TodoItem, dueTo: { $exists: false } }) + for (const todo of dueToTodos) { + await client.update(DOMAIN_TASK, { _id: todo._id }, { dueTo: null }) + } +} + export const taskOperation: MigrateOperation = { - async migrate (client: MigrationClient): Promise {}, + async migrate (client: MigrationClient): Promise { + await Promise.all([migrateTodoItems(client)]) + }, async upgrade (client: MigrationUpgradeClient): Promise { const tx = new TxOperations(client, core.account.System) await createDefaults(tx) diff --git a/plugins/board-resources/src/components/CreateCard.svelte b/plugins/board-resources/src/components/CreateCard.svelte index 221d4b9a3a..30ae6eb117 100644 --- a/plugins/board-resources/src/components/CreateCard.svelte +++ b/plugins/board-resources/src/components/CreateCard.svelte @@ -64,6 +64,7 @@ assignee: null, description: '', members: [], + labels: [], location: '' } diff --git a/plugins/board-resources/src/components/add-card/AddCard.svelte b/plugins/board-resources/src/components/add-card/AddCard.svelte index fa100aa0a2..17c96ea847 100644 --- a/plugins/board-resources/src/components/add-card/AddCard.svelte +++ b/plugins/board-resources/src/components/add-card/AddCard.svelte @@ -52,6 +52,7 @@ assignee: null, description: '', members: [], + labels: [], location: '' } diff --git a/plugins/board-resources/src/components/popups/CopyCard.svelte b/plugins/board-resources/src/components/popups/CopyCard.svelte index 61d496d15c..1b542a7663 100644 --- a/plugins/board-resources/src/components/popups/CopyCard.svelte +++ b/plugins/board-resources/src/components/popups/CopyCard.svelte @@ -52,7 +52,7 @@ description: '', members: [], location: '', - labels + labels: labels ?? [] } await client.addCollection( diff --git a/plugins/board-resources/src/utils/BoardUtils.ts b/plugins/board-resources/src/utils/BoardUtils.ts index 6f9b7fc6b6..e24b753520 100644 --- a/plugins/board-resources/src/utils/BoardUtils.ts +++ b/plugins/board-resources/src/utils/BoardUtils.ts @@ -92,7 +92,7 @@ export async function createMissingLabels ( const targetBoardLabels = await getBoardLabels(client, targetBoard) const missingLabels = sourceBoardLabels.filter((srcLabel) => { - if (object.labels?.includes(srcLabel._id) === false) return false + if (!object.labels?.includes(srcLabel._id)) return false return targetBoardLabels.findIndex((targetLabel) => isEqualLabel(targetLabel, srcLabel)) === -1 }) diff --git a/plugins/board/src/index.ts b/plugins/board/src/index.ts index 73e9bfbbf9..caa25f375b 100644 --- a/plugins/board/src/index.ts +++ b/plugins/board/src/index.ts @@ -69,7 +69,7 @@ export interface Card extends Task { members?: Ref[] - labels?: Ref[] + labels: Ref[] location?: string diff --git a/plugins/task-resources/src/components/todos/CreateTodo.svelte b/plugins/task-resources/src/components/todos/CreateTodo.svelte index 10e3367807..a69b35c68a 100644 --- a/plugins/task-resources/src/components/todos/CreateTodo.svelte +++ b/plugins/task-resources/src/components/todos/CreateTodo.svelte @@ -41,8 +41,9 @@ async function createTodo () { await client.addCollection(task.class.TodoItem, space, objectId, _class, 'todos', { name, + assignee: null, done, - dueTo: dueTo ?? undefined + dueTo: dueTo ?? null }) } diff --git a/plugins/task/src/index.ts b/plugins/task/src/index.ts index 7fd5313f61..8c60b21032 100644 --- a/plugins/task/src/index.ts +++ b/plugins/task/src/index.ts @@ -14,7 +14,7 @@ // import type { Employee } from '@anticrm/contact' -import { AttachedDoc, Class, Doc, Interface, Mixin, Ref, Space, Timestamp, TxOperations } from '@anticrm/core' +import { AttachedDoc, Class, Doc, Interface, Markup, Mixin, Ref, Space, Timestamp, TxOperations } from '@anticrm/core' import type { Asset, IntlString, Plugin } from '@anticrm/platform' import { plugin } from '@anticrm/platform' import type { AnyComponent } from '@anticrm/ui' @@ -72,9 +72,11 @@ export interface Task extends AttachedDoc, DocWithRank { * @public */ export interface TodoItem extends AttachedDoc { - name: string + name: Markup + assignee: Ref | null done: boolean - dueTo?: Timestamp + dueTo: Timestamp | null + items?: number } /**