diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index 8a40413842..67f7645d35 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -689,6 +689,28 @@ export function createModel (builder: Builder): void { }, contact.templateField.ContactName ) + + builder.createDoc( + templates.class.TemplateField, + core.space.Model, + { + label: contact.string.PersonFirstNamePlaceholder, + category: contact.templateFieldCategory.Contact, + func: contact.function.GetContactFirstName + }, + contact.templateField.ContactFirstName + ) + + builder.createDoc( + templates.class.TemplateField, + core.space.Model, + { + label: contact.string.PersonLastNamePlaceholder, + category: contact.templateFieldCategory.Contact, + func: contact.function.GetContactLastName + }, + contact.templateField.ContactLastName + ) } export { contactOperation } from './migration' diff --git a/models/contact/src/plugin.ts b/models/contact/src/plugin.ts index e9a74f3f89..af074472b5 100644 --- a/models/contact/src/plugin.ts +++ b/models/contact/src/plugin.ts @@ -103,6 +103,8 @@ export default mergeIds(contactId, contact, { function: { GetCurrentEmployeeName: '' as Resource, GetCurrentEmployeeEmail: '' as Resource, - GetContactName: '' as Resource + GetContactName: '' as Resource, + GetContactFirstName: '' as Resource, + GetContactLastName: '' as Resource } }) diff --git a/plugins/contact-assets/lang/ru.json b/plugins/contact-assets/lang/ru.json index cb203c43ed..d34325ff50 100644 --- a/plugins/contact-assets/lang/ru.json +++ b/plugins/contact-assets/lang/ru.json @@ -12,7 +12,7 @@ "PersonLastNamePlaceholder": "Фамилия", "PersonLocationPlaceholder": "Местоположение", "PersonsNamePlaceholder": "Папка", - "Name": "Имя", + "Name": "Полное имя", "SelectFolder": "Выбрать папку", "OrganizationsFolder": "Папка с организациями", "PersonsFolder": "Папка с людьми", diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index bd5ac116bc..320d3a2d72 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -75,6 +75,8 @@ import { employeeSort, filterChannelInResult, filterChannelNinResult, + getContactFirstName, + getContactLastName, getContactLink, getContactName, getCurrentEmployeeEmail, @@ -281,6 +283,8 @@ export default async (): Promise => ({ GetCurrentEmployeeName: getCurrentEmployeeName, GetCurrentEmployeeEmail: getCurrentEmployeeEmail, GetContactName: getContactName, + GetContactFirstName: getContactFirstName, + GetContactLastName: getContactLastName, GetContactLink: getContactLink }, resolver: { diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index a8d73bcbde..8d915fc02f 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -23,6 +23,8 @@ import { Employee, EmployeeAccount, formatName, + getFirstName, + getLastName, getName } from '@hcengineering/contact' import { Doc, getCurrentAccount, IdMap, ObjQueryType, Ref, Timestamp, toIdMap } from '@hcengineering/core' @@ -135,6 +137,30 @@ export async function getContactName (provider: TemplateDataProvider): Promise { + const value = provider.get(contact.class.Contact) as Contact + if (value === undefined) return + const client = getClient() + const hierarchy = client.getHierarchy() + if (hierarchy.isDerived(value._class, contact.class.Person)) { + return getLastName(value.name) + } else { + return '' + } +} + +export async function getContactFirstName (provider: TemplateDataProvider): Promise { + const value = provider.get(contact.class.Contact) as Contact + if (value === undefined) return + const client = getClient() + const hierarchy = client.getHierarchy() + if (hierarchy.isDerived(value._class, contact.class.Person)) { + return getFirstName(value.name) + } else { + return value.name + } +} + export async function getContactLink (doc: Doc): Promise { const loc = getCurrentLocation() loc.path.length = 2 diff --git a/plugins/contact/src/index.ts b/plugins/contact/src/index.ts index 024734edba..2a6546bc1d 100644 --- a/plugins/contact/src/index.ts +++ b/plugins/contact/src/index.ts @@ -266,7 +266,9 @@ export const contactPlugin = plugin(contactId, { templateField: { CurrentEmployeeName: '' as Ref, CurrentEmployeeEmail: '' as Ref, - ContactName: '' as Ref + ContactName: '' as Ref, + ContactFirstName: '' as Ref, + ContactLastName: '' as Ref } })