Board: Checklists model adjustments (#1633)

Signed-off-by: Anna No <anna.no@xored.com>
This commit is contained in:
Anna No 2022-05-04 20:52:31 +07:00 committed by GitHub
parent 113161e092
commit dfbf2d5263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 60 additions and 15 deletions

View File

@ -16,7 +16,17 @@
// To help typescript locate view plugin properly // To help typescript locate view plugin properly
import type { Board, Card, CardAction, CardDate, CardLabel, MenuPage } from '@anticrm/board' import type { Board, Card, CardAction, CardDate, CardLabel, MenuPage } from '@anticrm/board'
import type { Employee } from '@anticrm/contact' 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 { import {
ArrOf, ArrOf,
Builder, Builder,
@ -86,10 +96,10 @@ export class TCard extends TTask implements Card {
@Prop(TypeMarkup(), board.string.Description) @Prop(TypeMarkup(), board.string.Description)
@Index(IndexKind.FullText) @Index(IndexKind.FullText)
description!: string description!: Markup
@Prop(Collection(board.class.CardLabel), board.string.Labels) @Prop(Collection(board.class.CardLabel), board.string.Labels)
labels?: Ref<CardLabel>[] labels!: Ref<CardLabel>[]
@Prop(TypeString(), board.string.Location) @Prop(TypeString(), board.string.Location)
@Index(IndexKind.FullText) @Index(IndexKind.FullText)

View File

@ -16,7 +16,7 @@
import { Doc, Ref, Space, TxOperations } from '@anticrm/core' import { Doc, Ref, Space, TxOperations } from '@anticrm/core'
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model'
import core from '@anticrm/model-core' 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 task, { createKanban, KanbanTemplate } from '@anticrm/task'
import board from './plugin' import board from './plugin'
@ -76,8 +76,17 @@ async function createDefaults (tx: TxOperations): Promise<void> {
await createDefaultKanban(tx) await createDefaultKanban(tx)
} }
async function migrateLabels (client: MigrationClient): Promise<void> {
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 = { export const boardOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {}, async migrate (client: MigrationClient): Promise<void> {
await Promise.all([migrateLabels(client)])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> { async upgrade (client: MigrationUpgradeClient): Promise<void> {
const ops = new TxOperations(client, core.account.System) const ops = new TxOperations(client, core.account.System)
await createDefaults(ops) await createDefaults(ops)

View File

@ -122,15 +122,21 @@ export class TTask extends TAttachedDoc implements Task {
@Model(task.class.TodoItem, core.class.AttachedDoc, DOMAIN_TASK) @Model(task.class.TodoItem, core.class.AttachedDoc, DOMAIN_TASK)
@UX(task.string.Todo) @UX(task.string.Todo)
export class TTodoItem extends TAttachedDoc implements TodoItem { 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) @Index(IndexKind.FullText)
name!: string name!: string
@Prop(TypeRef(contact.class.Employee), task.string.TaskAssignee)
assignee!: Ref<Employee> | null
@Prop(TypeBoolean(), task.string.TaskDone) @Prop(TypeBoolean(), task.string.TaskDone)
done!: boolean done!: boolean
@Prop(TypeDate(), task.string.TaskDueTo) @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) @Model(task.class.SpaceWithStates, core.class.Space)

View File

@ -17,6 +17,7 @@ import { Class, Doc, Ref, Space, TxOperations } from '@anticrm/core'
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model'
import core from '@anticrm/model-core' import core from '@anticrm/model-core'
import { KanbanTemplate, StateTemplate, DoneStateTemplate, genRanks, createKanban } from '@anticrm/task' import { KanbanTemplate, StateTemplate, DoneStateTemplate, genRanks, createKanban } from '@anticrm/task'
import { DOMAIN_TASK } from '.'
import task from './plugin' import task from './plugin'
/** /**
@ -176,8 +177,22 @@ async function createDefaults (tx: TxOperations): Promise<void> {
await createDefaultKanban(tx) await createDefaultKanban(tx)
} }
async function migrateTodoItems (client: MigrationClient): Promise<void> {
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 = { export const taskOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {}, async migrate (client: MigrationClient): Promise<void> {
await Promise.all([migrateTodoItems(client)])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> { async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System) const tx = new TxOperations(client, core.account.System)
await createDefaults(tx) await createDefaults(tx)

View File

@ -64,6 +64,7 @@
assignee: null, assignee: null,
description: '', description: '',
members: [], members: [],
labels: [],
location: '' location: ''
} }

View File

@ -52,6 +52,7 @@
assignee: null, assignee: null,
description: '', description: '',
members: [], members: [],
labels: [],
location: '' location: ''
} }

View File

@ -52,7 +52,7 @@
description: '', description: '',
members: [], members: [],
location: '', location: '',
labels labels: labels ?? []
} }
await client.addCollection( await client.addCollection(

View File

@ -92,7 +92,7 @@ export async function createMissingLabels (
const targetBoardLabels = await getBoardLabels(client, targetBoard) const targetBoardLabels = await getBoardLabels(client, targetBoard)
const missingLabels = sourceBoardLabels.filter((srcLabel) => { 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 return targetBoardLabels.findIndex((targetLabel) => isEqualLabel(targetLabel, srcLabel)) === -1
}) })

View File

@ -69,7 +69,7 @@ export interface Card extends Task {
members?: Ref<Employee>[] members?: Ref<Employee>[]
labels?: Ref<CardLabel>[] labels: Ref<CardLabel>[]
location?: string location?: string

View File

@ -41,8 +41,9 @@
async function createTodo () { async function createTodo () {
await client.addCollection(task.class.TodoItem, space, objectId, _class, 'todos', { await client.addCollection(task.class.TodoItem, space, objectId, _class, 'todos', {
name, name,
assignee: null,
done, done,
dueTo: dueTo ?? undefined dueTo: dueTo ?? null
}) })
} }
</script> </script>

View File

@ -14,7 +14,7 @@
// //
import type { Employee } from '@anticrm/contact' 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 type { Asset, IntlString, Plugin } from '@anticrm/platform'
import { plugin } from '@anticrm/platform' import { plugin } from '@anticrm/platform'
import type { AnyComponent } from '@anticrm/ui' import type { AnyComponent } from '@anticrm/ui'
@ -72,9 +72,11 @@ export interface Task extends AttachedDoc, DocWithRank {
* @public * @public
*/ */
export interface TodoItem extends AttachedDoc { export interface TodoItem extends AttachedDoc {
name: string name: Markup
assignee: Ref<Employee> | null
done: boolean done: boolean
dueTo?: Timestamp dueTo: Timestamp | null
items?: number
} }
/** /**