Template first name (#2887)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-05 13:15:19 +06:00 committed by GitHub
parent 17c9846720
commit eb25bd2d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 3 deletions

View File

@ -689,6 +689,28 @@ export function createModel (builder: Builder): void {
}, },
contact.templateField.ContactName 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' export { contactOperation } from './migration'

View File

@ -103,6 +103,8 @@ export default mergeIds(contactId, contact, {
function: { function: {
GetCurrentEmployeeName: '' as Resource<TemplateFieldFunc>, GetCurrentEmployeeName: '' as Resource<TemplateFieldFunc>,
GetCurrentEmployeeEmail: '' as Resource<TemplateFieldFunc>, GetCurrentEmployeeEmail: '' as Resource<TemplateFieldFunc>,
GetContactName: '' as Resource<TemplateFieldFunc> GetContactName: '' as Resource<TemplateFieldFunc>,
GetContactFirstName: '' as Resource<TemplateFieldFunc>,
GetContactLastName: '' as Resource<TemplateFieldFunc>
} }
}) })

View File

@ -12,7 +12,7 @@
"PersonLastNamePlaceholder": "Фамилия", "PersonLastNamePlaceholder": "Фамилия",
"PersonLocationPlaceholder": "Местоположение", "PersonLocationPlaceholder": "Местоположение",
"PersonsNamePlaceholder": "Папка", "PersonsNamePlaceholder": "Папка",
"Name": "Имя", "Name": "Полное имя",
"SelectFolder": "Выбрать папку", "SelectFolder": "Выбрать папку",
"OrganizationsFolder": "Папка с организациями", "OrganizationsFolder": "Папка с организациями",
"PersonsFolder": "Папка с людьми", "PersonsFolder": "Папка с людьми",

View File

@ -75,6 +75,8 @@ import {
employeeSort, employeeSort,
filterChannelInResult, filterChannelInResult,
filterChannelNinResult, filterChannelNinResult,
getContactFirstName,
getContactLastName,
getContactLink, getContactLink,
getContactName, getContactName,
getCurrentEmployeeEmail, getCurrentEmployeeEmail,
@ -281,6 +283,8 @@ export default async (): Promise<Resources> => ({
GetCurrentEmployeeName: getCurrentEmployeeName, GetCurrentEmployeeName: getCurrentEmployeeName,
GetCurrentEmployeeEmail: getCurrentEmployeeEmail, GetCurrentEmployeeEmail: getCurrentEmployeeEmail,
GetContactName: getContactName, GetContactName: getContactName,
GetContactFirstName: getContactFirstName,
GetContactLastName: getContactLastName,
GetContactLink: getContactLink GetContactLink: getContactLink
}, },
resolver: { resolver: {

View File

@ -23,6 +23,8 @@ import {
Employee, Employee,
EmployeeAccount, EmployeeAccount,
formatName, formatName,
getFirstName,
getLastName,
getName getName
} from '@hcengineering/contact' } from '@hcengineering/contact'
import { Doc, getCurrentAccount, IdMap, ObjQueryType, Ref, Timestamp, toIdMap } from '@hcengineering/core' import { Doc, getCurrentAccount, IdMap, ObjQueryType, Ref, Timestamp, toIdMap } from '@hcengineering/core'
@ -135,6 +137,30 @@ export async function getContactName (provider: TemplateDataProvider): Promise<s
} }
} }
export async function getContactLastName (provider: TemplateDataProvider): Promise<string | undefined> {
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<string | undefined> {
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<Location> { export async function getContactLink (doc: Doc): Promise<Location> {
const loc = getCurrentLocation() const loc = getCurrentLocation()
loc.path.length = 2 loc.path.length = 2

View File

@ -266,7 +266,9 @@ export const contactPlugin = plugin(contactId, {
templateField: { templateField: {
CurrentEmployeeName: '' as Ref<TemplateField>, CurrentEmployeeName: '' as Ref<TemplateField>,
CurrentEmployeeEmail: '' as Ref<TemplateField>, CurrentEmployeeEmail: '' as Ref<TemplateField>,
ContactName: '' as Ref<TemplateField> ContactName: '' as Ref<TemplateField>,
ContactFirstName: '' as Ref<TemplateField>,
ContactLastName: '' as Ref<TemplateField>
} }
}) })