From 643015a664277bd0e9b4aa06b8158626321e8efd Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Sun, 3 Mar 2024 22:46:45 +0600 Subject: [PATCH] UBERF-5861 (#4861) Signed-off-by: Denis Bykhov --- models/tracker/src/index.ts | 4 + plugins/task-resources/src/index.ts | 119 ++++++++++++++---------- plugins/tracker-resources/src/index.ts | 11 ++- plugins/tracker-resources/src/plugin.ts | 1 + 4 files changed, 85 insertions(+), 50 deletions(-) diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 19b043a742..5f826f29c3 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -81,6 +81,10 @@ function defineSortAndGrouping (builder: Builder): void { builder.mixin(tracker.class.Milestone, core.class.Class, view.mixin.AllValuesFunc, { func: tracker.function.GetAllMilestones }) + + builder.mixin(tracker.class.IssueStatus, core.class.Class, view.mixin.AllValuesFunc, { + func: tracker.function.GetAllStates + }) } function defineNotifications (builder: Builder): void { diff --git a/plugins/task-resources/src/index.ts b/plugins/task-resources/src/index.ts index fd085fac83..7ee5ff6f61 100644 --- a/plugins/task-resources/src/index.ts +++ b/plugins/task-resources/src/index.ts @@ -14,7 +14,6 @@ // limitations under the License. // -import { get, writable } from 'svelte/store' import { toIdMap, type Attribute, @@ -39,9 +38,9 @@ import task, { import { getCurrentLocation, navigate, showPopup } from '@hcengineering/ui' import { type ViewletDescriptor } from '@hcengineering/view' import { CategoryQuery, statusStore } from '@hcengineering/view-resources' +import { get, writable } from 'svelte/store' import AssignedTasks from './components/AssignedTasks.svelte' -import CreateStatePopup from './components/state/CreateStatePopup.svelte' import Dashboard from './components/Dashboard.svelte' import DueDateEditor from './components/DueDateEditor.svelte' import KanbanTemplatePresenter from './components/KanbanTemplatePresenter.svelte' @@ -54,26 +53,27 @@ import TemplatesIcon from './components/TemplatesIcon.svelte' import TypesView from './components/TypesView.svelte' import KanbanView from './components/kanban/KanbanView.svelte' import ProjectEditor from './components/projectTypes/ProjectEditor.svelte' +import ProjectTypePresenter from './components/projectTypes/ProjectTypePresenter.svelte' import ProjectTypeSelector from './components/projectTypes/ProjectTypeSelector.svelte' +import CreateStatePopup from './components/state/CreateStatePopup.svelte' import StateEditor from './components/state/StateEditor.svelte' +import StateIconPresenter from './components/state/StateIconPresenter.svelte' import StatePresenter from './components/state/StatePresenter.svelte' import StateRefPresenter from './components/state/StateRefPresenter.svelte' import TypeStatesPopup from './components/state/TypeStatesPopup.svelte' -import TaskTypeClassPresenter from './components/taskTypes/TaskTypeClassPresenter.svelte' import ProjectTypeClassPresenter from './components/taskTypes/ProjectTypeClassPresenter.svelte' -import TaskTypePresenter from './components/taskTypes/TaskTypePresenter.svelte' -import ProjectTypePresenter from './components/projectTypes/ProjectTypePresenter.svelte' -import StateIconPresenter from './components/state/StateIconPresenter.svelte' import TaskKindSelector from './components/taskTypes/TaskKindSelector.svelte' +import TaskTypeClassPresenter from './components/taskTypes/TaskTypeClassPresenter.svelte' +import TaskTypePresenter from './components/taskTypes/TaskTypePresenter.svelte' import ManageProjects from './components/projectTypes/ManageProjects.svelte' -import ManageProjectsTools from './components/projectTypes/ManageProjectsTools.svelte' import ManageProjectsContent from './components/projectTypes/ManageProjectsContent.svelte' +import ManageProjectsTools from './components/projectTypes/ManageProjectsTools.svelte' export { default as AssigneePresenter } from './components/AssigneePresenter.svelte' export { default as TypeSelector } from './components/TypeSelector.svelte' export * from './utils' -export { StatePresenter, StateRefPresenter, TypeStatesPopup, TaskKindSelector } +export { StatePresenter, StateRefPresenter, TaskKindSelector, TypeStatesPopup } async function editStatuses (object: Project, ev: Event): Promise { const loc = getCurrentLocation() @@ -140,57 +140,78 @@ export default async (): Promise => ({ } }) -async function getAllStates ( +export async function getAllStates ( query: DocumentQuery | undefined, onUpdate: () => void, queryId: Ref, - attr: Attribute + attr: Attribute, + filterDone: boolean = true ): Promise { const typeId = get(selectedTypeStore) - const taskTypeId = get(selectedTaskTypeStore) - if (taskTypeId === undefined) { - return [] - } const type = typeId !== undefined ? get(typeStore).get(typeId) : undefined - const taskType = get(taskTypeStore).get(taskTypeId) - if (taskType === undefined) { - return [] - } - if (type !== undefined) { - const statusMap = get(statusStore).byId - const statuses = (taskType.statuses.map((p) => statusMap.get(p)) as Status[]) ?? [] - return statuses - .filter((p) => p?.category !== task.statusCategory.Lost && p?.category !== task.statusCategory.Won) - .map((p) => p?._id) - } - const _space = query?.space - if (_space !== undefined) { - const promise = new Promise>>((resolve, reject) => { - let refresh: boolean = false - const lq = CategoryQuery.getLiveQuery(queryId) - refresh = lq.query(task.class.Project, { _id: _space as Ref }, (res) => { - const statusMap = get(statusStore).byId - const statuses = (taskType.statuses.map((p) => statusMap.get(p)) as Status[]) ?? [] - const result = statuses + const taskTypeId = get(selectedTaskTypeStore) + if (taskTypeId !== undefined) { + const taskType = get(taskTypeStore).get(taskTypeId) + if (taskType === undefined) { + return [] + } + if (type !== undefined) { + const statusMap = get(statusStore).byId + const statuses = (taskType.statuses.map((p) => statusMap.get(p)) as Status[]) ?? [] + if (filterDone) { + return statuses .filter((p) => p?.category !== task.statusCategory.Lost && p?.category !== task.statusCategory.Won) .map((p) => p?._id) - CategoryQuery.results.set(queryId, result) - resolve(result) - onUpdate() - }) - - if (!refresh) { - resolve(CategoryQuery.results.get(queryId) ?? []) + } else { + return statuses.map((p) => p?._id) } - }) - return await promise + } + const _space = query?.space + if (_space !== undefined) { + const promise = new Promise>>((resolve, reject) => { + let refresh: boolean = false + const lq = CategoryQuery.getLiveQuery(queryId) + refresh = lq.query(task.class.Project, { _id: _space as Ref }, (res) => { + const statusMap = get(statusStore).byId + const statuses = (taskType.statuses.map((p) => statusMap.get(p)) as Status[]) ?? [] + let result: Array> = [] + if (filterDone) { + result = statuses + .filter((p) => p?.category !== task.statusCategory.Lost && p?.category !== task.statusCategory.Won) + .map((p) => p?._id) + } else { + result = statuses.map((p) => p?._id) + } + CategoryQuery.results.set(queryId, result) + resolve(result) + onUpdate() + }) + + if (!refresh) { + resolve(CategoryQuery.results.get(queryId) ?? []) + } + }) + return await promise + } + } else if (type !== undefined) { + const statusMap = get(statusStore).byId + const statuses = (type.statuses.map((p) => statusMap.get(p._id)) as Status[]) ?? [] + if (filterDone) { + return statuses + .filter((p) => p?.category !== task.statusCategory.Lost && p?.category !== task.statusCategory.Won) + .map((p) => p?._id) + } else { + return statuses.map((p) => p?._id) + } + } + const allStates = get(statusStore).array.filter((p) => p.ofAttribute === attr._id) + if (filterDone) { + return allStates + .filter((p) => p?.category !== task.statusCategory.Lost && p?.category !== task.statusCategory.Won) + .map((p) => p?._id) + } else { + return allStates.map((p) => p?._id) } - return get(statusStore) - .array.filter( - (p) => - p.ofAttribute === attr._id && p.category !== task.statusCategory.Lost && p.category !== task.statusCategory.Won - ) - .map((p) => p._id) } async function statusSort ( diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index a7ed438728..3b88b338d4 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -15,10 +15,12 @@ import { Analytics } from '@hcengineering/analytics' import core, { + type Attribute, ClassifierKind, DOMAIN_CONFIGURATION, DOMAIN_MODEL, getCurrentAccount, + type Space, toIdMap, type AttachedDoc, type Class, @@ -29,7 +31,7 @@ import core, { type RelatedDocument, type TxOperations } from '@hcengineering/core' -import { translate, type Resources } from '@hcengineering/platform' +import { type Status, translate, type Resources } from '@hcengineering/platform' import { getClient, MessageBox, type ObjectSearchResult } from '@hcengineering/presentation' import { type Issue, type Milestone, type Project } from '@hcengineering/tracker' import { getCurrentLocation, navigate, showPopup, themeStore } from '@hcengineering/ui' @@ -156,6 +158,7 @@ import ProjectSpacePresenter from './components/projects/ProjectSpacePresenter.s import { get } from 'svelte/store' import { settingId } from '@hcengineering/setting' +import { getAllStates } from '@hcengineering/task-resources' import EstimationValueEditor from './components/issues/timereport/EstimationValueEditor.svelte' import TimePresenter from './components/issues/timereport/TimePresenter.svelte' @@ -527,6 +530,12 @@ export default async (): Promise => ({ GetAllPriority: getAllPriority, GetAllComponents: getAllComponents, GetAllMilestones: getAllMilestones, + GetAllStates: async ( + query: DocumentQuery> | undefined, + onUpdate: () => void, + queryId: Ref>, + attr: Attribute + ) => await getAllStates(query, onUpdate, queryId, attr, false), GetVisibleFilters: getVisibleFilters, IssueChatTitleProvider: getIssueChatTitle, IsProjectJoined: async (project: Project) => !project.private || project.members.includes(getCurrentAccount()._id), diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index 41b6d2557f..116cf39fd9 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -390,6 +390,7 @@ export default mergeIds(trackerId, tracker, { GetAllPriority: '' as GetAllValuesFunc, GetAllComponents: '' as GetAllValuesFunc, GetAllMilestones: '' as GetAllValuesFunc, + GetAllStates: '' as GetAllValuesFunc, GetVisibleFilters: '' as Resource<(filters: KeyFilter[], space?: Ref) => Promise>, IsProjectJoined: '' as Resource<(space: Space) => Promise>, IssueChatTitleProvider: '' as Resource<(object: Doc) => string>,