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
)
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'

View File

@ -103,6 +103,8 @@ export default mergeIds(contactId, contact, {
function: {
GetCurrentEmployeeName: '' 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": "Фамилия",
"PersonLocationPlaceholder": "Местоположение",
"PersonsNamePlaceholder": "Папка",
"Name": "Имя",
"Name": "Полное имя",
"SelectFolder": "Выбрать папку",
"OrganizationsFolder": "Папка с организациями",
"PersonsFolder": "Папка с людьми",

View File

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

View File

@ -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<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> {
const loc = getCurrentLocation()
loc.path.length = 2

View File

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