diff --git a/plugins/tracker-resources/src/components/CreateIssue.svelte b/plugins/tracker-resources/src/components/CreateIssue.svelte index d39d6b2164..d13a784df3 100644 --- a/plugins/tracker-resources/src/components/CreateIssue.svelte +++ b/plugins/tracker-resources/src/components/CreateIssue.svelte @@ -40,12 +40,12 @@ import tags, { TagElement, TagReference } from '@hcengineering/tags' import { calcRank, + DraftIssueChild, Issue, IssueDraft, IssuePriority, IssueStatus, IssueTemplate, - IssueTemplateChild, Project, Sprint, Team @@ -80,7 +80,7 @@ import SetDueDateActionPopup from './SetDueDateActionPopup.svelte' import SetParentIssueActionPopup from './SetParentIssueActionPopup.svelte' import SprintSelector from './sprints/SprintSelector.svelte' - import IssueTemplateChilds from './templates/IssueTemplateChilds.svelte' + import SubIssues from './SubIssues.svelte' export let space: Ref export let status: Ref | undefined = undefined @@ -96,6 +96,8 @@ const draft: IssueDraft | undefined = shouldSaveDraft ? getUserDraft(tracker.class.IssueDraft) : undefined + let subIssuesComponent: SubIssues + let issueStatuses: WithLookup[] | undefined let labels: TagReference[] = draft?.labels || [] let objectId: Ref = draft?.issueId || generateId() @@ -147,9 +149,8 @@ templateId = undefined template = undefined object = { ...defaultIssue } - subIssues = [] if (!originalIssue && !draft) { - updateIssueStatusId(_space, status) + updateIssueStatusId(currentTeam, status) } } @@ -158,7 +159,7 @@ let template: IssueTemplate | undefined = undefined const templateQuery = createQuery() - let subIssues: IssueTemplateChild[] = draft?.subIssues || [] + let subIssues: DraftIssueChild[] = draft?.subIssues || [] $: if (templateId !== undefined) { templateQuery.query(tracker.class.IssueTemplate, { _id: templateId }, (res) => { @@ -192,7 +193,9 @@ const { _class, _id, space, children, comments, attachments, labels: labels_, ...templBase } = template - subIssues = template.children + subIssues = template.children.map((p) => { + return { ...p, status: currentTeam?.defaultIssueStatus ?? ('' as Ref) } + }) object = { ...object, @@ -226,7 +229,7 @@ } $: _space = draft?.team || space - $: !originalIssue && !draft && updateIssueStatusId(_space, status) + $: !originalIssue && !draft && updateIssueStatusId(currentTeam, status) $: canSave = getTitle(object.title ?? '').length > 0 $: statusesQuery.query( @@ -300,16 +303,14 @@ } } - async function updateIssueStatusId (teamId: Ref, issueStatusId?: Ref) { + async function updateIssueStatusId (currentTeam: Team | undefined, issueStatusId?: Ref) { if (issueStatusId !== undefined) { object.status = issueStatusId return } - const team = await client.findOne(tracker.class.Team, { _id: teamId }) - - if (team?.defaultIssueStatus) { - object.status = team.defaultIssueStatus + if (currentTeam?.defaultIssueStatus) { + object.status = currentTeam.defaultIssueStatus } } @@ -342,9 +343,9 @@ } } - // if (object.attachments && object.attachments > 0) { - // return false - // } + if (object.attachments && object.attachments > 0) { + return false + } if (draft.project && draft.project !== defaultIssue.project) { return false @@ -358,10 +359,8 @@ return true } - const team = await client.findOne(tracker.class.Team, { _id: _space }) - - if (team?.defaultIssueStatus) { - return draft.status === team.defaultIssueStatus + if (currentTeam?.defaultIssueStatus) { + return draft.status === currentTeam.defaultIssueStatus } return false @@ -470,66 +469,14 @@ } } } - for (const subIssue of subIssues) { - const lastOne = await client.findOne(tracker.class.Issue, {}, { sort: { rank: SortingOrder.Descending } }) - const incResult = await client.updateDoc( - tracker.class.Team, - core.space.Space, - _space, - { - $inc: { sequence: 1 } - }, - true - ) - const childId: Ref = generateId() - const cvalue: AttachedData = { - title: getTitle(subIssue.title), - description: subIssue.description, - assignee: subIssue.assignee, - project: subIssue.project, - sprint: subIssue.sprint, - number: (incResult as any).object.sequence, - status: object.status, - priority: subIssue.priority, - rank: calcRank(lastOne, undefined), - comments: 0, - subIssues: 0, - dueDate: null, - parents: parentIssue - ? [ - { parentId: objectId, parentTitle: value.title }, - { parentId: parentIssue._id, parentTitle: parentIssue.title }, - ...parentIssue.parents - ] - : [{ parentId: objectId, parentTitle: value.title }], - reportedTime: 0, - estimation: subIssue.estimation, - reports: 0, - relations: [], - childInfo: [] - } - - await client.addCollection( - tracker.class.Issue, - _space, - objectId, - tracker.class.Issue, - 'subIssues', - cvalue, - childId - ) - - if ((subIssue.labels?.length ?? 0) > 0) { - const tagElements = await client.findAll(tags.class.TagElement, { _id: { $in: subIssue.labels } }) - for (const label of tagElements) { - await client.addCollection(tags.class.TagReference, _space, childId, tracker.class.Issue, 'labels', { - title: label.title, - color: label.color, - tag: label._id - }) - } - } - } + const parents = parentIssue + ? [ + { parentId: objectId, parentTitle: value.title }, + { parentId: parentIssue._id, parentTitle: parentIssue.title }, + ...parentIssue.parents + ] + : [{ parentId: objectId, parentTitle: value.title }] + await subIssuesComponent.save(parents) addNotification(await translate(tracker.string.IssueCreated, {}), getTitle(object.title), IssueNotification, { issueId: objectId, subTitlePostfix: (await translate(tracker.string.Created, { value: 1 })).toLowerCase(), @@ -677,14 +624,6 @@
- {/key} - + {#if issueStatuses} + + {/if} {#if issueStatuses}
diff --git a/plugins/tracker-resources/src/components/SubIssues.svelte b/plugins/tracker-resources/src/components/SubIssues.svelte new file mode 100644 index 0000000000..b5b03aa80a --- /dev/null +++ b/plugins/tracker-resources/src/components/SubIssues.svelte @@ -0,0 +1,252 @@ + + + +
+ {#if hasSubIssues} +
+{#if hasSubIssues} + +
+ + + +
+
+{/if} +{#if isCreating && team} + + { + isCreating = false + }} + on:create={(evt) => { + if (subIssues === undefined) { + subIssues = [] + } + subIssues = [...subIssues, evt.detail] + }} + on:changeContent + /> + +{/if} + + diff --git a/plugins/tracker-resources/src/components/issues/StatusEditor.svelte b/plugins/tracker-resources/src/components/issues/StatusEditor.svelte index 1be7f6ee1d..077a5297d1 100644 --- a/plugins/tracker-resources/src/components/issues/StatusEditor.svelte +++ b/plugins/tracker-resources/src/components/issues/StatusEditor.svelte @@ -15,7 +15,7 @@ + +
+
+ +
+ {#key newIssue.id} + + {/key} +
+
+
+
+ (newIssue.status = detail)} + /> + (newIssue.priority = detail)} + /> + {#key newIssue.assignee} + (newIssue.assignee = detail)} + /> + {/key} + { + newIssue.estimation = evt.detail + }} + /> + { + addTagRef(evt.detail) + }} + on:delete={(evt) => { + labels = labels.filter((it) => it._id !== evt.detail) + }} + /> +
+
+
+
+
diff --git a/plugins/tracker-resources/src/components/templates/DraftIssueChildList.svelte b/plugins/tracker-resources/src/components/templates/DraftIssueChildList.svelte new file mode 100644 index 0000000000..6e7227be76 --- /dev/null +++ b/plugins/tracker-resources/src/components/templates/DraftIssueChildList.svelte @@ -0,0 +1,264 @@ + + + + + +{#each issues as issue, index (issue.id)} + +
draggingIndex && index === hoveringIndex} + animate:flip={{ duration: 400 }} + draggable={true} + on:click|self={(evt) => openIssue(evt, issue)} + on:dragstart={(ev) => handleDragStart(ev, index)} + on:dragover|preventDefault={() => false} + on:dragenter={() => (hoveringIndex = index)} + on:drop|preventDefault={(ev) => handleDrop(ev, index)} + on:dragend={resetDrag} + > +
+
+
+
+ (issue.status = detail)} + /> + { + dispatch('update-issue', { id: issue.id, priority: evt.detail }) + issue.priority = evt.detail + }} + /> + + openIssue(evt, issue)}> + + {getIssueTemplateId(currentTeam, issue)} + + + openIssue(evt, issue)}> + {issue.title} + +
+
+ { + dispatch('update-issue', { id: issue.id, estimation: evt.detail }) + issue.estimation = evt.detail + }} + /> + { + dispatch('update-issue', { id: issue.id, assignee: evt.detail }) + issue.assignee = evt.detail + }} + /> +
+
+{/each} + + diff --git a/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte b/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte index 97c9b5c083..202a7ff3a2 100644 --- a/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte +++ b/plugins/tracker-resources/src/components/templates/EditIssueTemplate.svelte @@ -13,15 +13,15 @@ // limitations under the License. --> @@ -127,7 +138,7 @@ openIssue(evt, issue)}> - {getIssueTemplateId(teamId, issue)} + {getIssueTemplateId(currentTeam, issue)} openIssue(evt, issue)}> diff --git a/plugins/tracker-resources/src/components/templates/IssueTemplateChilds.svelte b/plugins/tracker-resources/src/components/templates/IssueTemplateChilds.svelte index 4c4ea5a7bd..bdbd21cfcd 100644 --- a/plugins/tracker-resources/src/components/templates/IssueTemplateChilds.svelte +++ b/plugins/tracker-resources/src/components/templates/IssueTemplateChilds.svelte @@ -14,10 +14,9 @@ -->