From 07986b476b39fcec6787c554ced1a35ff91cc283 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 17 Feb 2023 15:26:44 +0600 Subject: [PATCH] Create vacancy related issues fix (#2655) Signed-off-by: Denis Bykhov --- .../src/components/CreateVacancy.svelte | 107 ++++++++++-------- .../src/components/list/List.svelte | 1 + 2 files changed, 61 insertions(+), 47 deletions(-) diff --git a/plugins/recruit-resources/src/components/CreateVacancy.svelte b/plugins/recruit-resources/src/components/CreateVacancy.svelte index c7fa0e8c09..d019cce247 100644 --- a/plugins/recruit-resources/src/components/CreateVacancy.svelte +++ b/plugins/recruit-resources/src/components/CreateVacancy.svelte @@ -18,8 +18,9 @@ import core, { FindResult, generateId, getCurrentAccount, Ref, SortingOrder } from '@hcengineering/core' import { Card, createQuery, getClient, UserBox } from '@hcengineering/presentation' import { Vacancy as VacancyClass } from '@hcengineering/recruit' + import tags from '@hcengineering/tags' import task, { createKanban, KanbanTemplate } from '@hcengineering/task' - import tracker, { calcRank, Issue, IssueStatus, IssueTemplate } from '@hcengineering/tracker' + import tracker, { calcRank, Issue, IssueStatus, IssueTemplate, IssueTemplateData, Team } from '@hcengineering/tracker' import { Button, Component, createFocusManager, EditBox, FocusHandler, IconAttachment } from '@hcengineering/ui' import { createEventDispatcher } from 'svelte' import recruit from '../plugin' @@ -60,6 +61,61 @@ issueTemplates = result }) + async function saveIssue ( + id: Ref, + space: Ref, + template: IssueTemplateData, + parent: Ref = tracker.ids.NoParent + ): Promise> { + const lastOne = await client.findOne( + tracker.class.Issue, + { space }, + { sort: { rank: SortingOrder.Descending } } + ) + const incResult = await client.updateDoc( + tracker.class.Team, + core.space.Space, + space, + { + $inc: { sequence: 1 } + }, + true + ) + const team = await client.findOne(tracker.class.Team, { _id: space }) + const rank = calcRank(lastOne, undefined) + const resId = await client.addCollection(tracker.class.Issue, space, parent, tracker.class.Issue, 'subIssues', { + title: template.title + ` (${name})`, + description: template.description, + assignee: template.assignee, + project: template.project, + sprint: template.sprint, + number: (incResult as any).object.sequence, + status: team?.defaultIssueStatus as Ref, + priority: template.priority, + rank, + comments: 0, + subIssues: 0, + dueDate: null, + parents: [], + reportedTime: 0, + estimation: template.estimation, + reports: 0, + relations: [{ _id: id, _class: recruit.class.Vacancy }], + childInfo: [] + }) + if ((template.labels?.length ?? 0) > 0) { + const tagElements = await client.findAll(tags.class.TagElement, { _id: { $in: template.labels } }) + for (const label of tagElements) { + await client.addCollection(tags.class.TagReference, space, resId, tracker.class.Issue, 'labels', { + title: label.title, + color: label.color, + tag: label._id + }) + } + } + return resId + } + async function createVacancy () { if ( templateId !== undefined && @@ -86,52 +142,9 @@ if (issueTemplates.length > 0) { for (const issueTemplate of issueTemplates) { - // we need find for each because it can be in another space - const lastOne = await client.findOne( - tracker.class.Issue, - { space: issueTemplate.space }, - { sort: { rank: SortingOrder.Descending } } - ) - const incResult = await client.updateDoc( - tracker.class.Team, - core.space.Space, - issueTemplate.space, - { - $inc: { sequence: 1 } - }, - true - ) - const team = await client.findOne(tracker.class.Team, { _id: issueTemplate.space }) - const rank = calcRank(lastOne, undefined) - await client.addCollection( - tracker.class.Issue, - issueTemplate.space, - tracker.ids.NoParent, - tracker.class.Issue, - 'subIssues', - { - title: issueTemplate.title, - description: issueTemplate.description, - assignee: issueTemplate.assignee, - project: issueTemplate.project, - sprint: issueTemplate.sprint, - number: (incResult as any).object.sequence, - status: team?.defaultIssueStatus as Ref, - priority: issueTemplate.priority, - rank, - comments: 0, - subIssues: 0, - dueDate: null, - parents: [], - reportedTime: 0, - estimation: issueTemplate.estimation, - reports: 0, - relations: [{ _id: id, _class: recruit.class.Vacancy }], - childInfo: [] - } - ) - if (lastOne !== undefined) { - lastOne.rank = rank + const issue = await saveIssue(id, issueTemplate.space, issueTemplate) + for (const sub of issueTemplate.children) { + await saveIssue(id, issueTemplate.space, sub, issue) } } } diff --git a/plugins/view-resources/src/components/list/List.svelte b/plugins/view-resources/src/components/list/List.svelte index 909acaeb05..68e5dc699c 100644 --- a/plugins/view-resources/src/components/list/List.svelte +++ b/plugins/view-resources/src/components/list/List.svelte @@ -70,6 +70,7 @@ } else { docsQuery.unsubscribe() docs = documents + dispatch('content', docs) } const dispatch = createEventDispatcher()