Skip to content

Commit

Permalink
TSK-955: Fix status display (#2840)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo committed Mar 27, 2023
1 parent 948f39d commit 7ce5b93
Show file tree
Hide file tree
Showing 45 changed files with 654 additions and 319 deletions.
6 changes: 5 additions & 1 deletion models/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ import {
TVersion
} from './core'
import { TAccount, TSpace } from './security'
import { TStatus, TStatusCategory } from './status'
import { TUserStatus } from './transient'
import { TTx, TTxApplyIf, TTxCollectionCUD, TTxCreateDoc, TTxCUD, TTxMixin, TTxRemoveDoc, TTxUpdateDoc } from './tx'

export * from './core'
export { coreOperation } from './migration'
export * from './security'
export * from './tx'
export * from './status'
export { core as default }

export function createModel (builder: Builder): void {
Expand Down Expand Up @@ -114,7 +116,9 @@ export function createModel (builder: Builder): void {
TFullTextSearchContext,
TConfiguration,
TConfigurationElement,
TIndexConfiguration
TIndexConfiguration,
TStatus,
TStatusCategory
)

builder.createDoc(
Expand Down
52 changes: 52 additions & 0 deletions models/core/src/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright © 2023 Hardcore Engineering Inc.
//
// 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 { Attribute, Domain, DOMAIN_MODEL, Ref, Status, StatusCategory } from '@hcengineering/core'
import { Model, Prop, TypeRef, UX } from '@hcengineering/model'
import { Asset, IntlString } from '@hcengineering/platform'
import core from './component'
import { TDoc } from './core'

export const DOMAIN_STATUS = 'status' as Domain

// S P A C E

@Model(core.class.Status, core.class.Doc, DOMAIN_STATUS)
@UX(core.string.Status)
export class TStatus extends TDoc implements Status {
// We attach to attribute, so we could distinguish between
ofAttribute!: Ref<Attribute<Status>>

@Prop(TypeRef(core.class.StatusCategory), core.string.StatusCategory)
category!: Ref<StatusCategory>

name!: string
color!: number
description!: string
rank!: string
}

@Model(core.class.StatusCategory, core.class.Doc, DOMAIN_MODEL)
@UX(core.string.StatusCategory)
export class TStatusCategory extends TDoc implements StatusCategory {
// We attach to attribute, so we could distinguish between
ofAttribute!: Ref<Attribute<Status>>

icon!: Asset
label!: IntlString
color!: number
defaultStatusName!: string
order!: number
}
69 changes: 25 additions & 44 deletions models/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
} from '@hcengineering/model'
import attachment from '@hcengineering/model-attachment'
import chunter from '@hcengineering/model-chunter'
import core, { DOMAIN_SPACE, TAttachedDoc, TDoc, TSpace, TType } from '@hcengineering/model-core'
import core, { DOMAIN_SPACE, DOMAIN_STATUS, TAttachedDoc, TDoc, TSpace, TStatus, TType } from '@hcengineering/model-core'
import view, { actionTemplates, classPresenter, createAction } from '@hcengineering/model-view'
import workbench, { createNavigateAction } from '@hcengineering/model-workbench'
import notification from '@hcengineering/notification'
Expand All @@ -61,7 +61,6 @@ import {
IssueParentInfo,
IssuePriority,
IssueStatus,
IssueStatusCategory,
IssueTemplate,
IssueTemplateChild,
Component,
Expand Down Expand Up @@ -89,33 +88,8 @@ export const DOMAIN_TRACKER = 'tracker' as Domain
/**
* @public
*/
@Model(tracker.class.IssueStatus, core.class.AttachedDoc, DOMAIN_TRACKER)
export class TIssueStatus extends TAttachedDoc implements IssueStatus {
@Index(IndexKind.Indexed)
name!: string

description?: string
color?: number

@Prop(TypeRef(tracker.class.IssueStatusCategory), tracker.string.StatusCategory)
@Index(IndexKind.Indexed)
category!: Ref<IssueStatusCategory>

@Prop(TypeString(), tracker.string.Rank)
@Hidden()
rank!: string
}

/**
* @public
*/
@Model(tracker.class.IssueStatusCategory, core.class.Doc, DOMAIN_MODEL)
export class TIssueStatusCategory extends TDoc implements IssueStatusCategory {
label!: IntlString
icon!: Asset
color!: number
defaultStatusName!: string
order!: number
@Model(tracker.class.IssueStatus, core.class.Status)
export class TIssueStatus extends TStatus implements IssueStatus {
}

/**
Expand Down Expand Up @@ -498,7 +472,6 @@ export function createModel (builder: Builder): void {
TIssue,
TIssueTemplate,
TIssueStatus,
TIssueStatusCategory,
TTypeIssuePriority,
TTypeComponentStatus,
TSprint,
Expand Down Expand Up @@ -773,9 +746,10 @@ export function createModel (builder: Builder): void {
)

builder.createDoc(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryBacklog,
icon: tracker.icon.CategoryBacklog,
color: 12,
Expand All @@ -786,9 +760,10 @@ export function createModel (builder: Builder): void {
)

builder.createDoc(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryUnstarted,
icon: tracker.icon.CategoryUnstarted,
color: 13,
Expand All @@ -799,9 +774,10 @@ export function createModel (builder: Builder): void {
)

builder.createDoc(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryStarted,
icon: tracker.icon.CategoryStarted,
color: 14,
Expand All @@ -812,9 +788,10 @@ export function createModel (builder: Builder): void {
)

builder.createDoc(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryCompleted,
icon: tracker.icon.CategoryCompleted,
color: 15,
Expand All @@ -825,9 +802,10 @@ export function createModel (builder: Builder): void {
)

builder.createDoc(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
core.space.Model,
{
ofAttribute: tracker.attribute.IssueStatus,
label: tracker.string.CategoryCanceled,
icon: tracker.icon.CategoryCanceled,
color: 16,
Expand Down Expand Up @@ -870,6 +848,14 @@ export function createModel (builder: Builder): void {
presenters: [tracker.component.IssueStatistics]
})

builder.mixin(tracker.class.IssueStatus, core.class.Class, view.mixin.ObjectPresenter, {
presenter: tracker.component.StatusPresenter
})

builder.mixin(tracker.class.IssueStatus, core.class.Class, view.mixin.AttributePresenter, {
presenter: tracker.component.StatusRefPresenter
})

builder.mixin(tracker.class.IssueStatus, core.class.Class, view.mixin.SortFuncs, {
func: tracker.function.IssueStatusSort
})
Expand All @@ -890,14 +876,6 @@ export function createModel (builder: Builder): void {
component: view.component.ValueFilter
})

builder.mixin(tracker.class.IssueStatus, core.class.Class, view.mixin.ObjectPresenter, {
presenter: tracker.component.StatusPresenter
})

builder.mixin(tracker.class.IssueStatus, core.class.Class, view.mixin.AttributePresenter, {
presenter: tracker.component.StatusRefPresenter
})

builder.mixin(tracker.class.TypeIssuePriority, core.class.Class, view.mixin.AttributePresenter, {
presenter: tracker.component.PriorityRefPresenter
})
Expand Down Expand Up @@ -1337,7 +1315,7 @@ export function createModel (builder: Builder): void {

const statusOptions: FindOptions<IssueStatus> = {
lookup: {
category: tracker.class.IssueStatusCategory
category: core.class.StatusCategory
},
sort: { rank: SortingOrder.Ascending }
}
Expand Down Expand Up @@ -1372,6 +1350,9 @@ export function createModel (builder: Builder): void {
attribute: 'status',
_class: tracker.class.IssueStatus,
placeholder: tracker.string.SetStatus,
query: {
ofAttribute: tracker.attribute.IssueStatus
},
fillQuery: {
space: 'space'
},
Expand Down
39 changes: 23 additions & 16 deletions models/tracker/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import core, {
generateId,
Ref,
SortingOrder,
StatusCategory,
TxCollectionCUD,
TxCreateDoc,
TxOperations,
TxResult,
TxUpdateDoc
} from '@hcengineering/core'
import { createOrUpdate, MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model'
import { DOMAIN_SPACE } from '@hcengineering/model-core'
import { DOMAIN_SPACE, DOMAIN_STATUS } from '@hcengineering/model-core'
import tags from '@hcengineering/tags'
import {
calcRank,
genRanks,
Issue,
IssueStatus,
IssueStatusCategory,
IssueTemplate,
IssueTemplateChild,
Project,
Expand All @@ -55,9 +55,9 @@ enum DeprecatedIssueStatus {
interface CreateProjectIssueStatusesArgs {
tx: TxOperations
projectId: Ref<Project>
categories: IssueStatusCategory[]
categories: StatusCategory[]
defaultStatusId?: Ref<IssueStatus>
defaultCategoryId?: Ref<IssueStatusCategory>
defaultCategoryId?: Ref<StatusCategory>
}

const categoryByDeprecatedIssueStatus = {
Expand All @@ -81,15 +81,14 @@ async function createProjectIssueStatuses ({
const { _id: category, defaultStatusName } = statusCategory
const rank = issueStatusRanks[i]

await tx.addCollection(
tracker.class.IssueStatus,
attachedTo,
attachedTo,
tracker.class.Project,
'issueStatuses',
{ name: defaultStatusName, category, rank },
category === defaultCategoryId ? defaultStatusId : undefined
)
if (defaultStatusName !== undefined) {
await tx.createDoc(
tracker.class.IssueStatus,
attachedTo,
{ ofAttribute: tracker.attribute.IssueStatus, name: defaultStatusName, category, rank },
category === defaultCategoryId ? defaultStatusId : undefined
)
}
}
}

Expand All @@ -106,7 +105,7 @@ async function createDefaultProject (tx: TxOperations): Promise<void> {
if (current === undefined && currentDeleted === undefined) {
const defaultStatusId: Ref<IssueStatus> = generateId()
const categories = await tx.findAll(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
{},
{ sort: { order: SortingOrder.Ascending } }
)
Expand Down Expand Up @@ -137,7 +136,7 @@ async function fixProjectIssueStatusesOrder (tx: TxOperations, project: Project)
const statuses = await tx.findAll(
tracker.class.IssueStatus,
{ attachedTo: project._id },
{ lookup: { category: tracker.class.IssueStatusCategory } }
{ lookup: { category: core.class.StatusCategory } }
)
statuses.sort((a, b) => (a.$lookup?.category?.order ?? 0) - (b.$lookup?.category?.order ?? 0))
const issueStatusRanks = genRanks(statuses.length)
Expand Down Expand Up @@ -171,7 +170,7 @@ async function upgradeProjectIssueStatuses (tx: TxOperations): Promise<void> {

if (projects.length > 0) {
const categories = await tx.findAll(
tracker.class.IssueStatusCategory,
core.class.StatusCategory,
{},
{ sort: { order: SortingOrder.Ascending } }
)
Expand Down Expand Up @@ -754,6 +753,14 @@ export const trackerOperation: MigrateOperation = {
await fillRank(client)
await renameProject(client)
await setCreate(client)

// Move all status objects into status domain
await client.move(DOMAIN_TRACKER, {
_class: tracker.class.IssueStatus
}, DOMAIN_STATUS)
await client.update(DOMAIN_STATUS, { _class: tracker.class.IssueStatus, ofAttribute: { $exists: false } }, {
ofAttribute: tracker.attribute.IssueStatus
})
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
Expand Down
12 changes: 12 additions & 0 deletions models/view/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,18 @@ export function createModel (builder: Builder): void {
},
view.action.Open
)

builder.mixin(core.class.Status, core.class.Class, view.mixin.SortFuncs, {
func: view.function.StatusSort
})

builder.mixin(core.class.Status, core.class.Class, view.mixin.ObjectPresenter, {
presenter: view.component.StatusPresenter
})

builder.mixin(core.class.Status, core.class.Class, view.mixin.AttributePresenter, {
presenter: view.component.StatusRefPresenter
})
}

export default view
4 changes: 3 additions & 1 deletion models/view/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export default mergeIds(viewId, view, {
ListView: '' as AnyComponent,
IndexedDocumentPreview: '' as AnyComponent,
SpaceRefPresenter: '' as AnyComponent,
EnumPresenter: '' as AnyComponent
EnumPresenter: '' as AnyComponent,
StatusPresenter: '' as AnyComponent,
StatusRefPresenter: '' as AnyComponent
},
string: {
Table: '' as IntlString,
Expand Down
Loading

0 comments on commit 7ce5b93

Please sign in to comment.