From 6c3070c85d15861ef5fafa24ed4b7ccfc5578fc4 Mon Sep 17 00:00:00 2001 From: Alex <41288429+Dvinyanin@users.noreply.github.com> Date: Fri, 24 Jun 2022 14:46:53 +0700 Subject: [PATCH] Update window title (#2138) Signed-off-by: Dvinyanin Alexandr --- models/tracker/src/index.ts | 4 +++ models/view/src/index.ts | 7 +++++ plugins/tracker-resources/src/index.ts | 5 ++- plugins/tracker-resources/src/plugin.ts | 6 +++- plugins/tracker-resources/src/utils.ts | 12 ++++++- plugins/view/src/index.ts | 8 +++++ .../src/components/Workbench.svelte | 31 +++++++++++++++++-- 7 files changed, 68 insertions(+), 5 deletions(-) diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index d130abd9a6..abe16af2e6 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -409,6 +409,10 @@ export function createModel (builder: Builder): void { presenter: tracker.component.IssuePreview }) + builder.mixin(tracker.class.Issue, core.class.Class, view.mixin.ObjectTitle, { + titleProvider: tracker.function.getIssueTitle + }) + builder.mixin(tracker.class.TypeIssuePriority, core.class.Class, view.mixin.AttributePresenter, { presenter: tracker.component.PriorityPresenter }) diff --git a/models/view/src/index.ts b/models/view/src/index.ts index 8e62a3ebf6..b457a7d455 100644 --- a/models/view/src/index.ts +++ b/models/view/src/index.ts @@ -40,6 +40,7 @@ import type { ObjectEditor, ObjectEditorHeader, ObjectFactory, + ObjectTitle, ObjectValidator, PreviewPresenter, SpaceHeader, @@ -158,6 +159,11 @@ export class TObjectFactory extends TClass implements ObjectFactory { component!: AnyComponent } +@Mixin(view.mixin.ObjectTitle, core.class.Class) +export class TObjectTitle extends TClass implements ObjectTitle { + titleProvider!: Resource<(client: Client, ref: Ref) => Promise> +} + @Model(view.class.ViewletPreference, preference.class.Preference) export class TViewletPreference extends TPreference implements ViewletPreference { attachedTo!: Ref @@ -276,6 +282,7 @@ export function createModel (builder: Builder): void { TActionCategory, TObjectValidator, TObjectFactory, + TObjectTitle, TObjectEditorHeader, THTMLPresenter, TSpaceHeader, diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index 6e8339a3d9..5fa4076e8e 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -56,7 +56,7 @@ import SetParentIssueActionPopup from './components/SetParentIssueActionPopup.sv import Views from './components/views/Views.svelte' import KanbanView from './components/issues/KanbanView.svelte' import tracker from './plugin' -import { getIssueId } from './utils' +import { getIssueId, getIssueTitle } from './utils' export async function queryIssue ( _class: Ref>, @@ -148,5 +148,8 @@ export default async (): Promise => ({ }, completion: { IssueQuery: async (client: Client, query: string) => await queryIssue(tracker.class.Issue, client, query) + }, + function: { + getIssueTitle } }) diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index 8f3dd3a676..d5ecfb8900 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. // -import type { IntlString } from '@anticrm/platform' +import type { IntlString, Resource } from '@anticrm/platform' import { mergeIds } from '@anticrm/platform' import tracker, { trackerId } from '../../tracker/lib' import { AnyComponent } from '@anticrm/ui' +import { Client, Doc, Ref } from '@anticrm/core' export default mergeIds(trackerId, tracker, { string: { @@ -209,5 +210,8 @@ export default mergeIds(trackerId, tracker, { Roadmap: '' as AnyComponent, TeamProjects: '' as AnyComponent, IssuePreview: '' as AnyComponent + }, + function: { + getIssueTitle: '' as Resource<(client: Client, ref: Ref) => Promise> } }) diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index 210443d32e..a472af39a5 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -14,7 +14,7 @@ // import contact, { Employee, formatName } from '@anticrm/contact' -import { DocumentQuery, Ref, SortingOrder, TxOperations } from '@anticrm/core' +import { Doc, DocumentQuery, Ref, SortingOrder, TxOperations } from '@anticrm/core' import { Asset, IntlString, translate } from '@anticrm/platform' import { IssuePriority, @@ -504,3 +504,13 @@ export async function getKanbanStatuses ( } return [] } + +export async function getIssueTitle (client: TxOperations, ref: Ref): Promise { + const issue = await client.findOne( + tracker.class.Issue, + { _id: ref as Ref }, + { lookup: { space: tracker.class.Team } } + ) + if (issue?.$lookup?.space === undefined) throw new Error(`Issue Team not found, _id: ${ref}`) + return getIssueId(issue.$lookup.space, issue) +} diff --git a/plugins/view/src/index.ts b/plugins/view/src/index.ts index 28700cba13..8dde03cf9e 100644 --- a/plugins/view/src/index.ts +++ b/plugins/view/src/index.ts @@ -154,6 +154,13 @@ export interface ObjectValidator extends Class { validator: Resource<(doc: T, client: Client) => Promise> } +/** + * @public + */ +export interface ObjectTitle extends Class { + titleProvider: Resource<(client: Client, ref: Ref) => Promise> +} + /** * @public */ @@ -384,6 +391,7 @@ const view = plugin(viewId, { ObjectEditorHeader: '' as Ref>, ObjectValidator: '' as Ref>, ObjectFactory: '' as Ref>, + ObjectTitle: '' as Ref>, SpaceHeader: '' as Ref>, SpaceName: '' as Ref>, IgnoreActions: '' as Ref>, diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index ee460a06f4..cf03c54d45 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -15,10 +15,10 @@