mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
Add objectTitle mixin (#2144)
Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
parent
7499ec85d2
commit
4f8b4706e9
@ -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']
|
||||
})
|
||||
|
@ -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,
|
||||
|
@ -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, {
|
||||
|
@ -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<Resources> => ({
|
||||
component: {
|
||||
@ -38,5 +39,8 @@ export default async (): Promise<Resources> => ({
|
||||
Leads,
|
||||
CreateCustomer,
|
||||
NewItemsHeader
|
||||
},
|
||||
function: {
|
||||
LeadTitleProvider: getLeadTitle
|
||||
}
|
||||
})
|
||||
|
@ -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<Doc>) => Promise<string>>
|
||||
}
|
||||
})
|
||||
|
9
plugins/lead-resources/src/utils.ts
Normal file
9
plugins/lead-resources/src/utils.ts
Normal file
@ -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<Doc>): Promise<string> {
|
||||
const object = await client.findOne(lead.class.Lead, { _id: ref as Ref<Lead> })
|
||||
if (object === undefined) throw new Error(`Lead not found, _id: ${ref}`)
|
||||
return `LEAD-${object.number}`
|
||||
}
|
@ -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<void> {
|
||||
@ -147,5 +148,8 @@ export default async (): Promise<Resources> => ({
|
||||
},
|
||||
completion: {
|
||||
ApplicationQuery: async (client: Client, query: string) => await queryApplication(client, query)
|
||||
},
|
||||
function: {
|
||||
ApplicationTitleProvider: getApplicationTitle
|
||||
}
|
||||
})
|
||||
|
@ -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<Doc>) => Promise<string>>
|
||||
}
|
||||
})
|
||||
|
17
plugins/recruit-resources/src/utils.ts
Normal file
17
plugins/recruit-resources/src/utils.ts
Normal file
@ -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<Doc>): Promise<string> {
|
||||
const object = await client.findOne(
|
||||
recruit.class.Applicant,
|
||||
{ _id: ref as Ref<Applicant> },
|
||||
{ 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}`
|
||||
}
|
@ -152,6 +152,6 @@ export default async (): Promise<Resources> => ({
|
||||
IssueQuery: async (client: Client, query: string) => await queryIssue(tracker.class.Issue, client, query)
|
||||
},
|
||||
function: {
|
||||
getIssueTitle
|
||||
IssueTitleProvider: getIssueTitle
|
||||
}
|
||||
})
|
||||
|
@ -214,6 +214,6 @@ export default mergeIds(trackerId, tracker, {
|
||||
CreateIssue: '' as AnyComponent
|
||||
},
|
||||
function: {
|
||||
getIssueTitle: '' as Resource<(client: Client, ref: Ref<Doc>) => Promise<string>>
|
||||
IssueTitleProvider: '' as Resource<(client: Client, ref: Ref<Doc>) => Promise<string>>
|
||||
}
|
||||
})
|
||||
|
@ -453,11 +453,11 @@ export async function getKanbanStatuses (
|
||||
}
|
||||
|
||||
export async function getIssueTitle (client: TxOperations, ref: Ref<Doc>): Promise<string> {
|
||||
const issue = await client.findOne(
|
||||
const object = await client.findOne(
|
||||
tracker.class.Issue,
|
||||
{ _id: ref as Ref<Issue> },
|
||||
{ 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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user