Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Board: Checklists model adjustments #1633

Merged
merged 15 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions models/board/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<CardLabel>[]
labels!: Ref<CardLabel>[]

@Prop(TypeString(), board.string.Location)
@Index(IndexKind.FullText)
Expand Down
13 changes: 11 additions & 2 deletions models/board/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -76,8 +76,17 @@ async function createDefaults (tx: TxOperations): Promise<void> {
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 = {
async migrate (client: MigrationClient): Promise<void> {},
async migrate (client: MigrationClient): Promise<void> {
await Promise.all([migrateLabels(client)])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const ops = new TxOperations(client, core.account.System)
await createDefaults(ops)
Expand Down
10 changes: 8 additions & 2 deletions models/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,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<Employee> | 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)
Expand Down
17 changes: 16 additions & 1 deletion models/task/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -176,8 +177,22 @@ async function createDefaults (tx: TxOperations): Promise<void> {
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 = {
async migrate (client: MigrationClient): Promise<void> {},
async migrate (client: MigrationClient): Promise<void> {
await Promise.all([migrateTodoItems(client)])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
await createDefaults(tx)
Expand Down
1 change: 1 addition & 0 deletions plugins/board-resources/src/components/CreateCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
assignee: null,
description: '',
members: [],
labels: [],
location: ''
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
assignee: null,
description: '',
members: [],
labels: [],
location: ''
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
description: '',
members: [],
location: '',
labels
labels: labels ?? []
}

await client.addCollection(
Expand Down
2 changes: 1 addition & 1 deletion plugins/board-resources/src/utils/BoardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion plugins/board/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface Card extends Task {

members?: Ref<Employee>[]

labels?: Ref<CardLabel>[]
labels: Ref<CardLabel>[]

location?: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
</script>
Expand Down
8 changes: 5 additions & 3 deletions plugins/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -72,9 +72,11 @@ export interface Task extends AttachedDoc, DocWithRank {
* @public
*/
export interface TodoItem extends AttachedDoc {
name: string
name: Markup
assignee: Ref<Employee> | null
done: boolean
dueTo?: Timestamp
dueTo: Timestamp | null
items?: number
}

/**
Expand Down