diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index eb69a72a5a..1afb7571ea 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -940,7 +940,7 @@ export function createModel (builder: Builder): void { }) builder.mixin(tracker.class.IssueTemplate, core.class.Class, view.mixin.ClassFilters, { - filters: ['priority', 'assignee', 'project', 'sprint', 'estimation', 'modifiedOn'] + filters: ['priority', 'assignee', 'project', 'sprint', 'modifiedOn'] }) builder.createDoc( diff --git a/packages/core/src/operator.ts b/packages/core/src/operator.ts index a4e37d6e26..b6925505d9 100644 --- a/packages/core/src/operator.ts +++ b/packages/core/src/operator.ts @@ -50,7 +50,7 @@ function $pull (document: Doc, keyval: Record): void { doc[key] = [] } const arr = doc[key] as Array - if (typeof keyval[key] === 'object') { + if (typeof keyval[key] === 'object' && keyval[key] !== null) { const { $in } = keyval[key] as PullArray doc[key] = arr.filter((val) => { diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index 65975ed3eb..27dee6cd12 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -45,10 +45,23 @@ let client: TxOperations const txListeners: Array<(tx: Tx) => void> = [] +/** + * @public + */ export function addTxListener (l: (tx: Tx) => void): void { txListeners.push(l) } +/** + * @public + */ +export function removeTxListener (l: (tx: Tx) => void): void { + const pos = txListeners.findIndex((it) => it === l) + if (pos !== -1) { + txListeners.splice(pos, 1) + } +} + class UIClient extends TxOperations implements Client { constructor (client: Client, private readonly liveQuery: LQ) { super(client, getCurrentAccount()._id) @@ -59,10 +72,16 @@ class UIClient extends TxOperations implements Client { } } +/** + * @public + */ export function getClient (): TxOperations { return client } +/** + * @public + */ export function setClient (_client: Client): void { liveQuery = new LQ(_client) client = new UIClient(_client, liveQuery) @@ -73,6 +92,9 @@ export function setClient (_client: Client): void { } } +/** + * @public + */ export class LiveQuery { private oldClass: Ref> | undefined private oldQuery: DocumentQuery | undefined @@ -128,10 +150,16 @@ export class LiveQuery { } } +/** + * @public + */ export function createQuery (dontDestroy?: boolean): LiveQuery { return new LiveQuery(dontDestroy) } +/** + * @public + */ export function getFileUrl (file: string, size: IconSize = 'full'): string { const uploadUrl = getMetadata(login.metadata.UploadUrl) const token = getMetadata(login.metadata.LoginToken) @@ -139,6 +167,9 @@ export function getFileUrl (file: string, size: IconSize = 'full'): string { return url } +/** + * @public + */ export async function getBlobURL (blob: Blob): Promise { return await new Promise((resolve) => { const reader = new FileReader() @@ -148,6 +179,9 @@ export async function getBlobURL (blob: Blob): Promise { }) } +/** + * @public + */ export async function copyTextToClipboard (text: string): Promise { try { // Safari specific behavior @@ -162,9 +196,16 @@ export async function copyTextToClipboard (text: string): Promise { } } +/** + * @public + */ export type AttributeCategory = 'attribute' | 'inplace' | 'collection' | 'array' +/** + * @public + */ export const AttributeCategoryOrder = { attribute: 0, inplace: 1, collection: 2, array: 2 } + /** * @public */ diff --git a/plugins/tracker-resources/src/components/CreateIssue.svelte b/plugins/tracker-resources/src/components/CreateIssue.svelte index 981e345881..4dedc606d8 100644 --- a/plugins/tracker-resources/src/components/CreateIssue.svelte +++ b/plugins/tracker-resources/src/components/CreateIssue.svelte @@ -132,12 +132,27 @@ templateQuery.unsubscribe() } - function updateObject (template: IssueTemplate): void { + function tagAsRef (tag: TagElement): TagReference { + return { + _class: tags.class.TagReference, + _id: generateId() as Ref, + attachedTo: '' as Ref, + attachedToClass: tracker.class.Issue, + collection: 'labels', + space: tags.space.Tags, + modifiedOn: 0, + modifiedBy: '' as Ref, + title: tag.title, + tag: tag._id, + color: tag.color + } + } + async function updateObject (template: IssueTemplate): Promise { if (object.template?.template === template._id) { return } - const { _class, _id, space, children, comments, attachments, labels, dueDate, ...templBase } = template + const { _class, _id, space, children, comments, attachments, labels: labels_, ...templBase } = template subIssues = template.children @@ -148,6 +163,8 @@ template: template._id } } + const tagElements = await client.findAll(tags.class.TagElement, { _id: { $in: labels_ } }) + labels = tagElements.map(tagAsRef) } function updateTemplate (template?: IssueTemplate): void { if (template !== undefined) { @@ -304,7 +321,7 @@ rank: calcRank(lastOne, undefined), comments: 0, subIssues: 0, - dueDate: subIssue.dueDate, + dueDate: null, parents: parentIssue ? [ { parentId: objectId, parentTitle: value.title }, @@ -313,7 +330,7 @@ ] : [{ parentId: objectId, parentTitle: value.title }], reportedTime: 0, - estimation: object.estimation, + estimation: subIssue.estimation, reports: 0, relations: [], childInfo: [] @@ -405,22 +422,7 @@ } function addTagRef (tag: TagElement): void { - labels = [ - ...labels, - { - _class: tags.class.TagReference, - _id: generateId() as Ref, - attachedTo: '' as Ref, - attachedToClass: tracker.class.Issue, - collection: 'labels', - space: tags.space.Tags, - modifiedOn: 0, - modifiedBy: '' as Ref, - title: tag.title, - tag: tag._id, - color: tag.color - } - ] + labels = [...labels, tagAsRef(tag)] } function handleTemplateChange (evt: CustomEvent>): void { if (templateId == null) { diff --git a/plugins/tracker-resources/src/components/templates/CreateIssueTemplate.svelte b/plugins/tracker-resources/src/components/templates/CreateIssueTemplate.svelte index bdf9bc38ec..d02a4c98c2 100644 --- a/plugins/tracker-resources/src/components/templates/CreateIssueTemplate.svelte +++ b/plugins/tracker-resources/src/components/templates/CreateIssueTemplate.svelte @@ -27,6 +27,7 @@ import PriorityEditor from '../issues/PriorityEditor.svelte' import ProjectSelector from '../ProjectSelector.svelte' import SprintSelector from '../sprints/SprintSelector.svelte' + import EstimationEditor from './EstimationEditor.svelte' import SubIssueTemplates from './IssueTemplateChilds.svelte' export let space: Ref @@ -35,7 +36,6 @@ export let project: Ref | null = $activeProject ?? null export let sprint: Ref | null = $activeSprint ?? null - const dueDate: number | undefined = undefined let labels: TagElement[] = [] let objectId: Ref = generateId() @@ -46,7 +46,6 @@ project: project, sprint: sprint, priority: priority, - dueDate: dueDate ?? null, estimation: 0, children: [], labels: [], @@ -89,7 +88,6 @@ project: object.project, sprint: object.sprint, priority: object.priority, - dueDate: dueDate ?? null, estimation: object.estimation, children: object.children, comments: 0, @@ -211,9 +209,7 @@ labels = labels.filter((it) => it._id !== evt.detail) }} /> - - + diff --git a/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte b/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte index b6791904b6..b202c9454b 100644 --- a/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte +++ b/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte @@ -21,6 +21,7 @@ import presentation, { createQuery, getClient, MessageViewer } from '@hcengineering/presentation' import setting, { settingId } from '@hcengineering/setting' import type { IssueTemplate, IssueTemplateChild, Team } from '@hcengineering/tracker' + import tags from '@hcengineering/tags' import { Button, EditBox, @@ -85,7 +86,7 @@ description = template.description currentTeam = template.$lookup?.space }, - { lookup: { space: tracker.class.Team } } + { lookup: { space: tracker.class.Team, labels: tags.class.TagElement } } ) $: canSave = title.trim().length > 0 diff --git a/plugins/tracker-resources/src/components/templates/EstimationEditor.svelte b/plugins/tracker-resources/src/components/templates/EstimationEditor.svelte index bfa3e8030a..d1cb1888d3 100644 --- a/plugins/tracker-resources/src/components/templates/EstimationEditor.svelte +++ b/plugins/tracker-resources/src/components/templates/EstimationEditor.svelte @@ -13,6 +13,7 @@ // limitations under the License. -->
@@ -58,10 +83,24 @@ - - + + + { + await client.update(issue, { $push: { labels: evt.detail._id } }) + }} + on:delete={onTagDelete} + />