diff --git a/models/lead/src/index.ts b/models/lead/src/index.ts index 956bde8421..4208af945d 100644 --- a/models/lead/src/index.ts +++ b/models/lead/src/index.ts @@ -221,6 +221,10 @@ export function createModel (builder: Builder): void { editor: lead.component.Leads }) + builder.mixin(lead.class.Lead, core.class.Class, view.mixin.ObjectTitle, { + titleProvider: lead.function.LeadTitleProvider + }) + builder.mixin(lead.class.Lead, core.class.Class, view.mixin.ClassFilters, { filters: ['attachedTo', 'title', 'assignee', 'state', 'doneState', 'modifiedOn'] }) diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index ed6c1ff935..2e9c61448f 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -383,6 +383,10 @@ export function createModel (builder: Builder): void { validator: recruit.validator.ApplicantValidator }) + builder.mixin(recruit.class.Applicant, core.class.Class, view.mixin.ObjectTitle, { + titleProvider: recruit.function.ApplicationTitleProvider + }) + builder.createDoc( view.class.ActionCategory, core.space.Model, diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 745261738e..90368b56db 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -411,7 +411,7 @@ export function createModel (builder: Builder): void { }) builder.mixin(tracker.class.Issue, core.class.Class, view.mixin.ObjectTitle, { - titleProvider: tracker.function.getIssueTitle + titleProvider: tracker.function.IssueTitleProvider }) builder.mixin(tracker.class.TypeIssuePriority, core.class.Class, view.mixin.AttributePresenter, { diff --git a/plugins/lead-resources/src/index.ts b/plugins/lead-resources/src/index.ts index 67e3f37bf4..da14882062 100644 --- a/plugins/lead-resources/src/index.ts +++ b/plugins/lead-resources/src/index.ts @@ -25,6 +25,7 @@ import LeadsPresenter from './components/LeadsPresenter.svelte' import TemplatesIcon from './components/TemplatesIcon.svelte' import CreateCustomer from './components/CreateCustomer.svelte' import NewItemsHeader from './components/NewItemsHeader.svelte' +import { getLeadTitle } from './utils' export default async (): Promise => ({ component: { @@ -38,5 +39,8 @@ export default async (): Promise => ({ Leads, CreateCustomer, NewItemsHeader + }, + function: { + LeadTitleProvider: getLeadTitle } }) diff --git a/plugins/lead-resources/src/plugin.ts b/plugins/lead-resources/src/plugin.ts index 6b38ecd588..0d11554298 100644 --- a/plugins/lead-resources/src/plugin.ts +++ b/plugins/lead-resources/src/plugin.ts @@ -14,7 +14,8 @@ // import lead, { leadId } from '@anticrm/lead' -import { IntlString, mergeIds } from '@anticrm/platform' +import { IntlString, mergeIds, Resource } from '@anticrm/platform' +import { Client, Doc, Ref } from '@anticrm/core' import { AnyComponent } from '@anticrm/ui' export default mergeIds(leadId, lead, { @@ -42,5 +43,8 @@ export default mergeIds(leadId, lead, { CreateCustomer: '' as AnyComponent, LeadsPresenter: '' as AnyComponent, CreateFunnel: '' as AnyComponent + }, + function: { + LeadTitleProvider: '' as Resource<(client: Client, ref: Ref) => Promise> } }) diff --git a/plugins/lead-resources/src/utils.ts b/plugins/lead-resources/src/utils.ts new file mode 100644 index 0000000000..0d0f2adf7f --- /dev/null +++ b/plugins/lead-resources/src/utils.ts @@ -0,0 +1,9 @@ +import { Doc, Ref, TxOperations } from '@anticrm/core' +import { Lead } from '@anticrm/lead' +import lead from './plugin' + +export async function getLeadTitle (client: TxOperations, ref: Ref): Promise { + const object = await client.findOne(lead.class.Lead, { _id: ref as Ref }) + if (object === undefined) throw new Error(`Lead not found, _id: ${ref}`) + return `LEAD-${object.number}` +} diff --git a/plugins/recruit-resources/src/index.ts b/plugins/recruit-resources/src/index.ts index 53e5084a92..12447c3a16 100644 --- a/plugins/recruit-resources/src/index.ts +++ b/plugins/recruit-resources/src/index.ts @@ -45,6 +45,7 @@ import VacancyCountPresenter from './components/VacancyCountPresenter.svelte' import VacancyItemPresenter from './components/VacancyItemPresenter.svelte' import VacancyModifiedPresenter from './components/VacancyModifiedPresenter.svelte' import VacancyPresenter from './components/VacancyPresenter.svelte' +import { getApplicationTitle } from './utils' import recruit from './plugin' async function createOpinion (object: Doc): Promise { @@ -147,5 +148,8 @@ export default async (): Promise => ({ }, completion: { ApplicationQuery: async (client: Client, query: string) => await queryApplication(client, query) + }, + function: { + ApplicationTitleProvider: getApplicationTitle } }) diff --git a/plugins/recruit-resources/src/plugin.ts b/plugins/recruit-resources/src/plugin.ts index f42da84a9d..67178581c5 100644 --- a/plugins/recruit-resources/src/plugin.ts +++ b/plugins/recruit-resources/src/plugin.ts @@ -13,8 +13,8 @@ // limitations under the License. // -import { Ref, Space } from '@anticrm/core' -import type { IntlString, StatusCode } from '@anticrm/platform' +import { Client, Doc, Ref, Space } from '@anticrm/core' +import type { IntlString, Resource, StatusCode } from '@anticrm/platform' import { mergeIds } from '@anticrm/platform' import recruit, { recruitId } from '@anticrm/recruit' import { TagCategory } from '@anticrm/tags' @@ -113,5 +113,8 @@ export default mergeIds(recruitId, recruit, { VacancyModifiedPresenter: '' as AnyComponent, CreateVacancy: '' as AnyComponent, CreateCandidate: '' as AnyComponent + }, + function: { + ApplicationTitleProvider: '' as Resource<(client: Client, ref: Ref) => Promise> } }) diff --git a/plugins/recruit-resources/src/utils.ts b/plugins/recruit-resources/src/utils.ts new file mode 100644 index 0000000000..98402cdadf --- /dev/null +++ b/plugins/recruit-resources/src/utils.ts @@ -0,0 +1,17 @@ +import core, { Doc, Ref, TxOperations } from '@anticrm/core' +import { translate } from '@anticrm/platform' +import { Applicant } from '@anticrm/recruit' +import recruit from './plugin' + +export async function getApplicationTitle (client: TxOperations, ref: Ref): Promise { + const object = await client.findOne( + recruit.class.Applicant, + { _id: ref as Ref }, + { lookup: { _class: core.class.Class } } + ) + if (object?.$lookup?._class?.shortLabel === undefined) { + throw new Error(`Application shortLabel not found, _id: ${ref}`) + } + const label = await translate(object.$lookup._class.shortLabel, {}) + return `${label}-${object.number}` +} diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index 0a2d84f47e..58948eea6d 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -152,6 +152,6 @@ export default async (): Promise => ({ IssueQuery: async (client: Client, query: string) => await queryIssue(tracker.class.Issue, client, query) }, function: { - getIssueTitle + IssueTitleProvider: getIssueTitle } }) diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index ae5ee2703e..837e1bb5cb 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -214,6 +214,6 @@ export default mergeIds(trackerId, tracker, { CreateIssue: '' as AnyComponent }, function: { - getIssueTitle: '' as Resource<(client: Client, ref: Ref) => Promise> + IssueTitleProvider: '' as Resource<(client: Client, ref: Ref) => Promise> } }) diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index 4bcbda02d5..11d0a75f4c 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -453,11 +453,11 @@ export async function getKanbanStatuses ( } export async function getIssueTitle (client: TxOperations, ref: Ref): Promise { - const issue = await client.findOne( + const object = 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) + if (object?.$lookup?.space === undefined) throw new Error(`Issue Team not found, _id: ${ref}`) + return getIssueId(object.$lookup.space, object) }