Skip to content

Commit

Permalink
Merge branch 'hcengineering:main' into vacancies-explicit-hide-archiv…
Browse files Browse the repository at this point in the history
…ed-viewoptions-hcengineering#4003
  • Loading branch information
Syarg authored Dec 20, 2023
2 parents 1b38e1d + 5062feb commit 379159f
Show file tree
Hide file tree
Showing 43 changed files with 481 additions and 500 deletions.
101 changes: 72 additions & 29 deletions models/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { getEmbeddedLabel, type Asset, type IntlString } from '@hcengineering/pl
import setting from '@hcengineering/setting'
import tags from '@hcengineering/tags'
import {
type TaskStatusFactory,
calculateStatuses,
findStatusAttr,
type KanbanCard,
Expand Down Expand Up @@ -489,7 +490,7 @@ export function createModel (builder: Builder): void {
ofAttribute: task.attribute.State,
label: task.string.StateBacklog,
icon: task.icon.TaskState,
color: PaletteColorIndexes.Coin,
color: PaletteColorIndexes.Cloud,
defaultStatusName: 'Backlog',
order: 0
},
Expand All @@ -503,7 +504,7 @@ export function createModel (builder: Builder): void {
ofAttribute: task.attribute.State,
label: task.string.StateActive,
icon: task.icon.TaskState,
color: PaletteColorIndexes.Blueberry,
color: PaletteColorIndexes.Porpoise,
defaultStatusName: 'New state',
order: 0
},
Expand All @@ -517,7 +518,7 @@ export function createModel (builder: Builder): void {
ofAttribute: task.attribute.State,
label: task.string.DoneStatesWon,
icon: task.icon.TaskState,
color: PaletteColorIndexes.Houseplant,
color: PaletteColorIndexes.Grass,
defaultStatusName: 'Won',
order: 0
},
Expand All @@ -531,7 +532,7 @@ export function createModel (builder: Builder): void {
ofAttribute: task.attribute.State,
label: task.string.DoneStatesLost,
icon: task.icon.TaskState,
color: PaletteColorIndexes.Firework,
color: PaletteColorIndexes.Coin,
defaultStatusName: 'Lost',
order: 0
},
Expand Down Expand Up @@ -602,7 +603,10 @@ export function createModel (builder: Builder): void {
/**
* @public
*/
export type FixTaskData = Omit<Data<TaskType>, 'space' | 'statuses' | 'parent'> & { _id?: TaskType['_id'] }
export type FixTaskData = Omit<Data<TaskType>, 'space' | 'statuses' | 'statusCategories' | 'parent'> & {
_id?: TaskType['_id']
statusCategories: TaskType['statusCategories'] | TaskStatusFactory[]
}
export interface FixTaskResult {
taskTypes: TaskType[]
projectTypes: ProjectType[]
Expand Down Expand Up @@ -694,35 +698,74 @@ export async function fixTaskTypes (
const statusAttr = findStatusAttr(client.hierarchy, data.ofClass)
// Ensure we have at leas't one item in every category.
for (const c of data.statusCategories) {
const cat = await client.model.findOne(core.class.StatusCategory, { _id: c })
const st = statuses.find((it) => it.category === c)
const category = typeof c === 'string' ? c : c.category
const cat = await client.model.findOne(core.class.StatusCategory, { _id: category })

const st = statuses.find((it) => it.category === category)
const newStatuses: Ref<Status>[] = []
if (st === undefined) {
// We need to add new status into missing category
const statusId: Ref<Status> = generateId()
await client.create<Status>(DOMAIN_STATUS, {
_id: statusId,
_class: data.statusClass,
category: c,
modifiedBy: core.account.ConfigUser,
modifiedOn: Date.now(),
name: cat?.defaultStatusName ?? 'New state',
space: task.space.Statuses,
ofAttribute: statusAttr._id
})
dStatuses.push(statusId)

await client.update(
DOMAIN_SPACE,
{
_id: t._id
},
{ $push: { statuses: { _id: statusId } } }
)
t.statuses.push({ _id: statusId, taskType: taskTypeId })
if (typeof c === 'string') {
// We need to add new status into missing category
const statusId: Ref<Status> = generateId()
await client.create<Status>(DOMAIN_STATUS, {
_id: statusId,
_class: data.statusClass,
category,
modifiedBy: core.account.ConfigUser,
modifiedOn: Date.now(),
name: cat?.defaultStatusName ?? 'New state',
space: task.space.Statuses,
ofAttribute: statusAttr._id
})
newStatuses.push(statusId)
dStatuses.push(statusId)

await client.update(
DOMAIN_SPACE,
{
_id: t._id
},
{ $push: { statuses: newStatuses.map((it) => ({ _id: it })) } }
)
t.statuses.push(...newStatuses.map((it) => ({ _id: it, taskType: taskTypeId })))
} else {
for (const sts of c.statuses) {
const stsName = Array.isArray(sts) ? sts[0] : sts
const color = Array.isArray(sts) ? sts[1] : undefined
const st = statuses.find((it) => it.name.toLowerCase() === stsName.toLowerCase())
if (st === undefined) {
// We need to add new status into missing category
const statusId: Ref<Status> = generateId()
await client.create<Status>(DOMAIN_STATUS, {
_id: statusId,
_class: data.statusClass,
category,
modifiedBy: core.account.ConfigUser,
modifiedOn: Date.now(),
name: stsName,
color,
space: task.space.Statuses,
ofAttribute: statusAttr._id
})
newStatuses.push(statusId)
dStatuses.push(statusId)
}

await client.update(
DOMAIN_SPACE,
{
_id: t._id
},
{ $push: { statuses: newStatuses.map((it) => ({ _id: it })) } }
)
t.statuses.push(...newStatuses.map((it) => ({ _id: it, taskType: taskTypeId })))
}
}
}
}
const taskType: TaskType = {
...data,
statusCategories: data.statusCategories.map((it) => (typeof it === 'string' ? it : it.category)),
parent: t._id,
_id: taskTypeId,
_class: task.class.TaskType,
Expand Down
83 changes: 4 additions & 79 deletions models/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
//

import activity from '@hcengineering/activity'
import chunter from '@hcengineering/chunter'
import { type Builder } from '@hcengineering/model'
import core from '@hcengineering/model-core'
import { generateClassNotificationTypes } from '@hcengineering/model-notification'
import presentation from '@hcengineering/model-presentation'
import task from '@hcengineering/model-task'
import view from '@hcengineering/model-view'
import workbench from '@hcengineering/model-workbench'
import notification from '@hcengineering/notification'
import setting from '@hcengineering/setting'
import { trackerId } from '@hcengineering/tracker'
import { generateClassNotificationTypes } from '@hcengineering/model-notification'
import presentation from '@hcengineering/model-presentation'
import { PaletteColorIndexes } from '@hcengineering/ui/src/colors'
import chunter from '@hcengineering/chunter'

import tracker from './plugin'
import { createActions as defineActions } from './actions'
import tracker from './plugin'
import { definePresenters } from './presenters'
import {
TComponent,
Expand Down Expand Up @@ -130,78 +129,6 @@ function defineNotifications (builder: Builder): void {
)
}

function defineStatusCategories (builder: Builder): void {
builder.createDoc(
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryBacklog,
icon: tracker.icon.CategoryBacklog,
color: PaletteColorIndexes.Cloud,
defaultStatusName: 'Backlog',
order: 0
},
tracker.issueStatusCategory.Backlog
)

builder.createDoc(
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryUnstarted,
icon: tracker.icon.CategoryUnstarted,
color: PaletteColorIndexes.Porpoise,
defaultStatusName: 'Todo',
order: 1
},
tracker.issueStatusCategory.Unstarted
)

builder.createDoc(
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryStarted,
icon: tracker.icon.CategoryStarted,
color: PaletteColorIndexes.Cerulean,
defaultStatusName: 'In Progress',
order: 2
},
tracker.issueStatusCategory.Started
)

builder.createDoc(
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryCompleted,
icon: tracker.icon.CategoryCompleted,
color: PaletteColorIndexes.Grass,
defaultStatusName: 'Done',
order: 3
},
tracker.issueStatusCategory.Completed
)

builder.createDoc(
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryCanceled,
icon: tracker.icon.CategoryCanceled,
color: PaletteColorIndexes.Coin,
defaultStatusName: 'Canceled',
order: 4
},
tracker.issueStatusCategory.Canceled
)
}

/**
* Define filters
*/
Expand Down Expand Up @@ -483,8 +410,6 @@ export function createModel (builder: Builder): void {

defineViewlets(builder)

defineStatusCategories(builder)

const issuesId = 'issues'
const componentsId = 'components'
const milestonesId = 'milestones'
Expand Down
Loading

0 comments on commit 379159f

Please sign in to comment.