Add objectTitle mixin (#2144)

Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
Alex 2022-06-26 00:32:31 +07:00 committed by GitHub
parent 7499ec85d2
commit 4f8b4706e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 9 deletions

View File

@ -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']
})

View File

@ -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,

View File

@ -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, {

View File

@ -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
}
})

View File

@ -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>>
}
})

View 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}`
}

View File

@ -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
}
})

View File

@ -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>>
}
})

View 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}`
}

View File

@ -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
}
})

View File

@ -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>>
}
})

View File

@ -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)
}