From 938a630056ade08b84e759edda16e42d5a52b380 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 19 Apr 2023 22:17:41 +0600 Subject: [PATCH] =?UTF-8?q?TSK-1253=20=D0=92=20=D0=BD=D0=B0=D0=B7=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=B1=D1=80=D0=B0=D1=83=D0=B7=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B7=D0=BB=D0=B8=D1=87=D0=B8=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=A2=D0=B0=D0=BB=D0=B0=D0=BD=D1=82=D1=8B=20(#3019)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Denis Bykhov --- models/contact/src/index.ts | 4 ++++ models/contact/src/plugin.ts | 5 +++-- plugins/contact-resources/src/index.ts | 4 +++- plugins/contact-resources/src/utils.ts | 8 +++++++- plugins/recruit-resources/src/utils.ts | 7 ++++++- .../src/components/Workbench.svelte | 15 +++++++++------ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index 904be893ef..b7f28582f3 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -551,6 +551,10 @@ export function createModel (builder: Builder): void { value: true }) + builder.mixin(contact.class.Contact, core.class.Class, view.mixin.ObjectTitle, { + titleProvider: contact.function.ContactTitleProvider + }) + builder.createDoc( presentation.class.ObjectSearchCategory, core.space.Model, diff --git a/models/contact/src/plugin.ts b/models/contact/src/plugin.ts index 290afc1135..cd2cec0f7a 100644 --- a/models/contact/src/plugin.ts +++ b/models/contact/src/plugin.ts @@ -15,7 +15,7 @@ import { contactId } from '@hcengineering/contact' import contact from '@hcengineering/contact-resources/src/plugin' -import type { Ref } from '@hcengineering/core' +import type { Client, Doc, Ref } from '@hcengineering/core' import {} from '@hcengineering/core' import { ObjectSearchCategory, ObjectSearchFactory } from '@hcengineering/model-presentation' import { IntlString, mergeIds, Resource } from '@hcengineering/platform' @@ -109,6 +109,7 @@ export default mergeIds(contactId, contact, { GetCurrentEmployeePosition: '' as Resource, GetContactName: '' as Resource, GetContactFirstName: '' as Resource, - GetContactLastName: '' as Resource + GetContactLastName: '' as Resource, + ContactTitleProvider: '' as Resource<(client: Client, ref: Ref) => Promise> } }) diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index 60037f6a3b..87aa719578 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -76,6 +76,7 @@ import ActivityChannelPresenter from './components/activity/ActivityChannelPrese import contact from './plugin' import { + contactTitleProvider, employeeSort, filterChannelInResult, filterChannelNinResult, @@ -314,7 +315,8 @@ export default async (): Promise => ({ GetContactName: getContactName, GetContactFirstName: getContactFirstName, GetContactLastName: getContactLastName, - GetContactLink: getContactLink + GetContactLink: getContactLink, + ContactTitleProvider: contactTitleProvider }, resolver: { Location: resolveLocation diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index 94a2b673f5..72ea6844e7 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -27,7 +27,7 @@ import { getLastName, getName } from '@hcengineering/contact' -import { Doc, getCurrentAccount, IdMap, ObjQueryType, Ref, Timestamp, toIdMap } from '@hcengineering/core' +import { Client, Doc, getCurrentAccount, IdMap, ObjQueryType, Ref, Timestamp, toIdMap } from '@hcengineering/core' import { createQuery, getClient } from '@hcengineering/presentation' import { TemplateDataProvider } from '@hcengineering/templates' import { DropdownIntlItem, getCurrentLocation, getPanelURI, Location, ResolvedLocation } from '@hcengineering/ui' @@ -300,3 +300,9 @@ export function getAvatarProviderId (avatar?: string | null): Ref): Promise { + const object = await client.findOne(contact.class.Contact, { _id: ref }) + if (object === undefined) return '' + return getName(object) +} diff --git a/plugins/recruit-resources/src/utils.ts b/plugins/recruit-resources/src/utils.ts index c84572eb0f..977546382e 100644 --- a/plugins/recruit-resources/src/utils.ts +++ b/plugins/recruit-resources/src/utils.ts @@ -3,6 +3,7 @@ import { getClient } from '@hcengineering/presentation' import { Applicant, Candidate, recruitId, Review, Vacancy, VacancyList } from '@hcengineering/recruit' import { getCurrentLocation, getPanelURI, Location, ResolvedLocation } from '@hcengineering/ui' import view from '@hcengineering/view' +import contact, { getName } from '@hcengineering/contact' import { workbenchId } from '@hcengineering/workbench' import recruit from './plugin' @@ -174,7 +175,11 @@ export async function getVacTitle (client: Client, ref: Ref): Promise): Promise { - return await getTitle(client, ref, recruit.class.Applicant) + const applicant = await client.findOne(recruit.class.Applicant, { _id: ref }) + if (applicant === undefined) return '' + const candidate = await client.findOne(contact.class.Contact, { _id: applicant.attachedTo }) + if (candidate === undefined) return '' + return getName(candidate) } export async function getRevTitle (client: Client, ref: Ref): Promise { diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index 604e77e506..0058a7f0a4 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -185,9 +185,14 @@ ) async function updateWindowTitle (loc: Location) { - const title = (await getWindowTitle(loc)) ?? getMetadata(workbench.metadata.PlatformTitle) ?? 'Platform' const ws = loc.path[1] - document.title = ws == null ? title : `${ws} - ${title}` + const docTitle = await getWindowTitle(loc) + if (docTitle !== undefined && docTitle !== '') { + document.title = ws == null ? docTitle : `${docTitle} - ${ws}` + } else { + const title = getMetadata(workbench.metadata.PlatformTitle) ?? 'Platform' + document.title = ws == null ? title : `${ws} - ${title}` + } } async function getWindowTitle (loc: Location) { if (loc.fragment == null) return @@ -195,10 +200,8 @@ const [, _id, _class] = decodeURIComponent(loc.fragment).split('|') if (_class == null) return - const clazz = hierarchy.getClass(_class as Ref>) - if (!hierarchy.hasMixin(clazz, view.mixin.ObjectTitle)) return - - const mixin = hierarchy.as(clazz, view.mixin.ObjectTitle) + const mixin = hierarchy.classHierarchyMixin(_class as Ref>, view.mixin.ObjectTitle) + if (mixin === undefined) return const titleProvider = await getResource(mixin.titleProvider) try { return await titleProvider(client, _id as Ref)