2021-08-07 14:49:14 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
2021-12-03 10:16:16 +00:00
|
|
|
//
|
2021-08-07 14:49:14 +00:00
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
2021-12-03 10:16:16 +00:00
|
|
|
//
|
2021-08-07 14:49:14 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
2021-12-03 10:16:16 +00:00
|
|
|
//
|
2021-08-07 14:49:14 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2022-01-18 10:21:32 +00:00
|
|
|
import core, {
|
|
|
|
AttachedDoc,
|
|
|
|
Class,
|
2022-03-04 09:02:13 +00:00
|
|
|
ClassifierKind,
|
2022-01-18 10:21:32 +00:00
|
|
|
Client,
|
|
|
|
Collection,
|
|
|
|
Doc,
|
2022-01-31 09:06:30 +00:00
|
|
|
FindResult,
|
|
|
|
Hierarchy,
|
|
|
|
Lookup,
|
|
|
|
matchQuery,
|
2022-03-04 09:02:13 +00:00
|
|
|
Mixin,
|
2022-01-31 09:06:30 +00:00
|
|
|
Obj,
|
2022-01-18 10:21:32 +00:00
|
|
|
Ref,
|
2022-01-19 09:04:30 +00:00
|
|
|
TxOperations
|
2022-01-18 10:21:32 +00:00
|
|
|
} from '@anticrm/core'
|
2021-08-07 14:49:14 +00:00
|
|
|
import type { IntlString } from '@anticrm/platform'
|
|
|
|
import { getResource } from '@anticrm/platform'
|
2022-02-16 09:02:31 +00:00
|
|
|
import { getAttributePresenterClass, KeyedAttribute } from '@anticrm/presentation'
|
2022-01-18 10:21:32 +00:00
|
|
|
import { ErrorPresenter, getPlatformColorForText } from '@anticrm/ui'
|
2022-01-19 09:04:30 +00:00
|
|
|
import type { Action, ActionTarget, BuildModelOptions, ObjectDDParticipant } from '@anticrm/view'
|
|
|
|
import view, { AttributeModel, BuildModelKey } from '@anticrm/view'
|
2022-02-10 09:04:18 +00:00
|
|
|
import plugin from './plugin'
|
2021-08-07 14:49:14 +00:00
|
|
|
|
2022-01-11 09:07:29 +00:00
|
|
|
/**
|
|
|
|
* Define some properties to be used to show component until data is properly loaded.
|
|
|
|
*/
|
|
|
|
export interface LoadingProps {
|
|
|
|
length: number
|
|
|
|
}
|
|
|
|
|
2021-11-23 18:46:34 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2022-01-18 10:21:32 +00:00
|
|
|
export async function getObjectPresenter (
|
|
|
|
client: Client,
|
|
|
|
_class: Ref<Class<Obj>>,
|
|
|
|
preserveKey: BuildModelKey
|
|
|
|
): Promise<AttributeModel> {
|
2021-12-03 10:16:16 +00:00
|
|
|
const clazz = client.getHierarchy().getClass(_class)
|
2021-08-07 14:49:14 +00:00
|
|
|
const presenterMixin = client.getHierarchy().as(clazz, view.mixin.AttributePresenter)
|
|
|
|
if (presenterMixin.presenter === undefined) {
|
|
|
|
if (clazz.extends !== undefined) {
|
2021-12-03 10:16:16 +00:00
|
|
|
return await getObjectPresenter(client, clazz.extends, preserveKey)
|
2021-08-07 14:49:14 +00:00
|
|
|
} else {
|
2021-12-08 09:09:51 +00:00
|
|
|
throw new Error('object presenter not found for ' + JSON.stringify(preserveKey))
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const presenter = await getResource(presenterMixin.presenter)
|
2021-12-23 13:59:09 +00:00
|
|
|
const key = preserveKey.sortingKey ?? preserveKey.key
|
2022-01-18 10:21:32 +00:00
|
|
|
const sortingKey =
|
|
|
|
clazz.sortingKey !== undefined ? (key.length > 0 ? key + '.' + clazz.sortingKey : clazz.sortingKey) : key
|
2021-08-07 14:49:14 +00:00
|
|
|
return {
|
2021-12-20 10:18:29 +00:00
|
|
|
key: preserveKey.key,
|
2021-12-03 10:16:16 +00:00
|
|
|
_class,
|
2021-12-20 10:18:29 +00:00
|
|
|
label: preserveKey.label ?? clazz.label,
|
2021-12-20 09:06:31 +00:00
|
|
|
presenter,
|
|
|
|
sortingKey
|
2021-12-03 10:16:16 +00:00
|
|
|
}
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:21:32 +00:00
|
|
|
async function getAttributePresenter (
|
|
|
|
client: Client,
|
|
|
|
_class: Ref<Class<Obj>>,
|
|
|
|
key: string,
|
|
|
|
preserveKey: BuildModelKey
|
|
|
|
): Promise<AttributeModel> {
|
2021-08-07 14:49:14 +00:00
|
|
|
const attribute = client.getHierarchy().getAttribute(_class, key)
|
2021-12-06 15:15:53 +00:00
|
|
|
let attrClass = getAttributePresenterClass(attribute)
|
2021-12-03 10:16:16 +00:00
|
|
|
const clazz = client.getHierarchy().getClass(attrClass)
|
|
|
|
let presenterMixin = client.getHierarchy().as(clazz, view.mixin.AttributePresenter)
|
|
|
|
let parent = clazz.extends
|
|
|
|
while (presenterMixin.presenter === undefined && parent !== undefined) {
|
|
|
|
const pclazz = client.getHierarchy().getClass(parent)
|
|
|
|
attrClass = parent
|
|
|
|
presenterMixin = client.getHierarchy().as(pclazz, view.mixin.AttributePresenter)
|
|
|
|
parent = pclazz.extends
|
|
|
|
}
|
2021-08-07 14:49:14 +00:00
|
|
|
if (presenterMixin.presenter === undefined) {
|
2021-12-08 09:09:51 +00:00
|
|
|
throw new Error('attribute presenter not found for ' + JSON.stringify(preserveKey))
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
2021-12-23 13:59:09 +00:00
|
|
|
const resultKey = preserveKey.sortingKey ?? preserveKey.key
|
2021-12-20 09:06:31 +00:00
|
|
|
const sortingKey = attribute.type._class === core.class.ArrOf ? resultKey + '.length' : resultKey
|
2021-08-07 14:49:14 +00:00
|
|
|
const presenter = await getResource(presenterMixin.presenter)
|
|
|
|
return {
|
2021-12-20 10:18:29 +00:00
|
|
|
key: preserveKey.key,
|
2021-12-20 09:06:31 +00:00
|
|
|
sortingKey,
|
2021-12-03 10:16:16 +00:00
|
|
|
_class: attrClass,
|
2021-12-20 10:18:29 +00:00
|
|
|
label: preserveKey.label ?? attribute.label,
|
2022-01-11 09:09:52 +00:00
|
|
|
presenter,
|
2022-02-07 09:21:32 +00:00
|
|
|
icon: presenterMixin.icon,
|
|
|
|
attribute
|
2021-12-03 10:16:16 +00:00
|
|
|
}
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 09:06:30 +00:00
|
|
|
async function getPresenter<T extends Doc> (
|
2022-01-18 10:21:32 +00:00
|
|
|
client: Client,
|
2022-01-31 09:06:30 +00:00
|
|
|
_class: Ref<Class<T>>,
|
2022-01-18 10:21:32 +00:00
|
|
|
key: BuildModelKey,
|
|
|
|
preserveKey: BuildModelKey,
|
2022-01-31 09:06:30 +00:00
|
|
|
lookup?: Lookup<T>
|
2022-01-18 10:21:32 +00:00
|
|
|
): Promise<AttributeModel> {
|
2021-12-20 10:18:29 +00:00
|
|
|
if (key.presenter !== undefined) {
|
2021-12-20 09:06:31 +00:00
|
|
|
const { presenter, label, sortingKey } = key
|
2021-09-26 11:05:17 +00:00
|
|
|
return {
|
2022-02-16 09:02:31 +00:00
|
|
|
key: key.key ?? '',
|
2021-12-20 09:06:31 +00:00
|
|
|
sortingKey: sortingKey ?? '',
|
2021-12-03 10:16:16 +00:00
|
|
|
_class,
|
2021-09-26 11:05:17 +00:00
|
|
|
label: label as IntlString,
|
2022-02-16 09:02:31 +00:00
|
|
|
presenter: await getResource(presenter),
|
|
|
|
props: key.props
|
2021-09-26 11:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-20 10:18:29 +00:00
|
|
|
if (key.key.length === 0) {
|
2021-12-03 10:16:16 +00:00
|
|
|
return await getObjectPresenter(client, _class, preserveKey)
|
2021-08-07 14:49:14 +00:00
|
|
|
} else {
|
2022-01-31 09:06:30 +00:00
|
|
|
if (key.key.startsWith('$lookup')) {
|
|
|
|
if (lookup === undefined) {
|
2022-02-10 09:04:18 +00:00
|
|
|
throw new Error(`lookup class does not provided for ${key.key}`)
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
2022-01-31 09:06:30 +00:00
|
|
|
return await getLookupPresenter(client, _class, key, preserveKey, lookup)
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
2021-12-20 10:18:29 +00:00
|
|
|
return await getAttributePresenter(client, _class, key.key, preserveKey)
|
2021-08-07 14:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 10:16:16 +00:00
|
|
|
export async function buildModel (options: BuildModelOptions): Promise<AttributeModel[]> {
|
2021-12-08 09:09:51 +00:00
|
|
|
console.log('building table model for', options)
|
2021-12-03 10:16:16 +00:00
|
|
|
// eslint-disable-next-line array-callback-return
|
2022-01-18 10:21:32 +00:00
|
|
|
const model = options.keys
|
|
|
|
.map((key) => (typeof key === 'string' ? { key: key } : key))
|
|
|
|
.map(async (key) => {
|
|
|
|
try {
|
2022-01-31 09:06:30 +00:00
|
|
|
return await getPresenter(options.client, options._class, key, key, options.options?.lookup)
|
2022-01-18 10:21:32 +00:00
|
|
|
} catch (err: any) {
|
|
|
|
if (options.ignoreMissing ?? false) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
const stringKey = key.label ?? key.key
|
|
|
|
console.error('Failed to find presenter for', key, err)
|
|
|
|
const errorPresenter: AttributeModel = {
|
|
|
|
key: '',
|
|
|
|
sortingKey: '',
|
|
|
|
presenter: ErrorPresenter,
|
|
|
|
label: stringKey as IntlString,
|
|
|
|
_class: core.class.TypeString,
|
|
|
|
props: { error: err }
|
|
|
|
}
|
|
|
|
return errorPresenter
|
2021-11-18 12:48:05 +00:00
|
|
|
}
|
2022-01-18 10:21:32 +00:00
|
|
|
})
|
|
|
|
return (await Promise.all(model)).filter((a) => a !== undefined) as AttributeModel[]
|
2021-09-25 16:48:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:21:32 +00:00
|
|
|
function filterActions (
|
|
|
|
client: Client,
|
|
|
|
doc: Doc,
|
|
|
|
targets: ActionTarget[],
|
|
|
|
derived: Ref<Class<Doc>> = core.class.Doc
|
|
|
|
): Array<Ref<Action>> {
|
2021-12-03 10:16:16 +00:00
|
|
|
const result: Array<Ref<Action>> = []
|
2021-12-15 09:04:43 +00:00
|
|
|
const hierarchy = client.getHierarchy()
|
2022-02-25 15:32:23 +00:00
|
|
|
const clazz = hierarchy.getClass(doc._class)
|
|
|
|
const ignoreActions = hierarchy.as(clazz, view.mixin.IgnoreActions)
|
|
|
|
const ignore = ignoreActions?.actions ?? []
|
2021-12-03 10:16:16 +00:00
|
|
|
for (const target of targets) {
|
2022-02-25 15:32:23 +00:00
|
|
|
if (ignore.includes(target.action)) {
|
|
|
|
continue
|
|
|
|
}
|
2021-12-20 10:18:29 +00:00
|
|
|
if (target.query !== undefined) {
|
|
|
|
const r = matchQuery([doc], target.query)
|
|
|
|
if (r.length === 0) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hierarchy.isDerived(doc._class, target.target) && client.getHierarchy().isDerived(target.target, derived)) {
|
2021-09-25 16:48:22 +00:00
|
|
|
result.push(target.action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-12-15 09:04:43 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*
|
|
|
|
* Find all action contributions applicable for specified _class.
|
|
|
|
* If derivedFrom is specifie, only actions applicable to derivedFrom class will be used.
|
|
|
|
* So if we have contribution for Doc, Space and we ask for SpaceWithStates and derivedFrom=Space,
|
|
|
|
* we won't recieve Doc contribution but recieve Space ones.
|
|
|
|
*/
|
2022-01-18 10:21:32 +00:00
|
|
|
export async function getActions (
|
|
|
|
client: Client,
|
|
|
|
doc: Doc,
|
|
|
|
derived: Ref<Class<Doc>> = core.class.Doc
|
|
|
|
): Promise<FindResult<Action>> {
|
2021-09-25 16:48:22 +00:00
|
|
|
const targets = await client.findAll(view.class.ActionTarget, {})
|
2021-12-20 10:18:29 +00:00
|
|
|
return await client.findAll(view.class.Action, { _id: { $in: filterActions(client, doc, targets, derived) } })
|
2021-09-25 16:48:22 +00:00
|
|
|
}
|
2021-12-06 09:16:04 +00:00
|
|
|
|
2022-01-13 09:06:50 +00:00
|
|
|
export async function deleteObject (client: TxOperations, object: Doc): Promise<void> {
|
2021-12-06 09:16:04 +00:00
|
|
|
const hierarchy = client.getHierarchy()
|
2022-03-04 09:02:13 +00:00
|
|
|
const promises: Promise<any>[] = []
|
|
|
|
if (client.getHierarchy().isDerived(object._class, core.class.AttachedDoc)) {
|
|
|
|
const adoc = object as AttachedDoc
|
|
|
|
promises.push(client.removeCollection(object._class, object.space, adoc._id, adoc.attachedTo, adoc.attachedToClass, adoc.collection).catch(err => console.error(err)))
|
|
|
|
} else {
|
|
|
|
promises.push(client.removeDoc(object._class, object.space, object._id).catch(err => console.error(err)))
|
|
|
|
}
|
|
|
|
promises.push(deleteClassCollections(client, object._class, object))
|
|
|
|
const mixins = getMixins(hierarchy, object._class, object)
|
|
|
|
for (const mixin of mixins) {
|
|
|
|
promises.push(deleteClassCollections(client, mixin, object))
|
|
|
|
}
|
|
|
|
|
|
|
|
promises.push(deleteRelatedDocuments(hierarchy, object, client))
|
|
|
|
await Promise.all(promises)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteClassCollections (client: TxOperations, _class: Ref<Class<Doc>>, object: Doc): Promise<void> {
|
|
|
|
const hierarchy = client.getHierarchy()
|
|
|
|
const attributes = hierarchy.getAllAttributes(_class)
|
2021-12-06 09:16:04 +00:00
|
|
|
for (const [name, attribute] of attributes) {
|
|
|
|
if (hierarchy.isDerived(attribute.type._class, core.class.Collection)) {
|
|
|
|
const collection = attribute.type as Collection<AttachedDoc>
|
|
|
|
const allAttached = await client.findAll(collection.of, { attachedTo: object._id })
|
|
|
|
for (const attached of allAttached) {
|
2022-01-19 09:04:30 +00:00
|
|
|
await deleteObject(client, attached).catch(err => console.log('failed to delete', name, err))
|
2021-12-06 09:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-04 09:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getParentClass (hierarchy: Hierarchy, _class: Ref<Class<Doc>>): Ref<Class<Doc>> {
|
|
|
|
const baseDomain = hierarchy.getDomain(_class)
|
|
|
|
const ancestors = hierarchy.getAncestors(_class)
|
|
|
|
let result: Ref<Class<Doc>> = _class
|
|
|
|
for (const ancestor of ancestors) {
|
|
|
|
try {
|
|
|
|
const domain = hierarchy.getClass(ancestor).domain
|
|
|
|
if (domain === baseDomain) {
|
|
|
|
result = ancestor
|
|
|
|
}
|
|
|
|
} catch {}
|
2022-01-19 09:04:30 +00:00
|
|
|
}
|
2022-03-04 09:02:13 +00:00
|
|
|
return result
|
|
|
|
}
|
2022-01-19 09:04:30 +00:00
|
|
|
|
2022-03-04 09:02:13 +00:00
|
|
|
function getMixins (hierarchy: Hierarchy, _class: Ref<Class<Doc>>, object: Doc): Ref<Mixin<Doc>>[] {
|
|
|
|
const parentClass = getParentClass(hierarchy, _class)
|
|
|
|
const descendants = hierarchy.getDescendants(parentClass)
|
|
|
|
return descendants.filter(
|
|
|
|
(m) => hierarchy.getClass(m).kind === ClassifierKind.MIXIN && hierarchy.hasMixin(object, m)
|
|
|
|
)
|
2022-01-19 09:04:30 +00:00
|
|
|
}
|
2022-03-04 09:02:13 +00:00
|
|
|
|
2022-01-19 09:04:30 +00:00
|
|
|
async function deleteRelatedDocuments (hierarchy: Hierarchy, object: Doc, client: TxOperations): Promise<void> {
|
|
|
|
const objectClass = hierarchy.getClass(object._class)
|
|
|
|
if (hierarchy.hasMixin(objectClass, view.mixin.ObjectDDParticipant)) {
|
|
|
|
const removeParticipand: ObjectDDParticipant = hierarchy.as(objectClass, view.mixin.ObjectDDParticipant)
|
|
|
|
const collector = await getResource(removeParticipand.collectDocs)
|
|
|
|
const docs = await collector(object, client)
|
|
|
|
for (const d of docs) {
|
|
|
|
await deleteObject(client, d)
|
|
|
|
}
|
2021-12-06 09:16:04 +00:00
|
|
|
}
|
2021-12-06 15:15:53 +00:00
|
|
|
}
|
2022-01-18 10:21:32 +00:00
|
|
|
|
|
|
|
export function getMixinStyle (id: Ref<Class<Doc>>, selected: boolean): string {
|
|
|
|
const color = getPlatformColorForText(id as string)
|
|
|
|
return `
|
|
|
|
background: ${color + (selected ? 'ff' : '33')};
|
|
|
|
border: 1px solid ${color + (selected ? '0f' : '66')};
|
|
|
|
`
|
|
|
|
}
|
2022-01-31 09:06:30 +00:00
|
|
|
|
|
|
|
async function getLookupPresenter<T extends Doc> (client: Client, _class: Ref<Class<T>>, key: BuildModelKey, preserveKey: BuildModelKey, lookup: Lookup<T>): Promise<AttributeModel> {
|
|
|
|
const lookupClass = getLookupClass(key.key, lookup, _class)
|
|
|
|
const lookupProperty = getLookupProperty(key.key)
|
|
|
|
const lookupKey = { ...key, key: lookupProperty[0] }
|
|
|
|
const model = await getPresenter(client, lookupClass[0], lookupKey, preserveKey)
|
|
|
|
model.label = getLookupLabel(client, lookupClass[1], lookupClass[0], lookupKey, lookupProperty[1])
|
|
|
|
return model
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLookupLabel<T extends Doc> (client: Client, _class: Ref<Class<T>>, lookupClass: Ref<Class<Doc>>, key: BuildModelKey, attrib: string): IntlString {
|
|
|
|
if (key.label !== undefined) return key.label
|
|
|
|
if (key.key === '') {
|
|
|
|
try {
|
|
|
|
const attribute = client.getHierarchy().getAttribute(_class, attrib)
|
|
|
|
return attribute.label
|
|
|
|
} catch {}
|
|
|
|
const clazz = client.getHierarchy().getClass(lookupClass)
|
|
|
|
return clazz.label
|
|
|
|
} else {
|
|
|
|
const attribute = client.getHierarchy().getAttribute(lookupClass, key.key)
|
|
|
|
return attribute.label
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLookupClass<T extends Doc> (key: string, lookup: Lookup<T>, parent: Ref<Class<T>>): [Ref<Class<Doc>>, Ref<Class<Doc>>] {
|
|
|
|
const _class = getLookup(key, lookup, parent)
|
|
|
|
if (_class === undefined) {
|
|
|
|
throw new Error('lookup class does not provided for ' + key)
|
|
|
|
}
|
|
|
|
return _class
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLookupProperty (key: string): [string, string] {
|
|
|
|
const parts = key.split('$lookup')
|
|
|
|
const lastPart = parts[parts.length - 1]
|
|
|
|
const split = lastPart.split('.').filter((p) => p.length > 0)
|
|
|
|
const prev = split.shift() ?? ''
|
|
|
|
const result = split.join('.')
|
|
|
|
return [result, prev]
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLookup (key: string, lookup: Lookup<any>, parent: Ref<Class<Doc>>): [Ref<Class<Doc>>, Ref<Class<Doc>>] | undefined {
|
|
|
|
const parts = key.split('$lookup.').filter((p) => p.length > 0)
|
|
|
|
const currentKey = parts[0].split('.').filter((p) => p.length > 0)[0]
|
|
|
|
const current = (lookup as any)[currentKey]
|
|
|
|
const nestedKey = parts.slice(1).join('$lookup.')
|
2022-02-10 09:04:18 +00:00
|
|
|
if (nestedKey.length > 0) {
|
2022-01-31 09:06:30 +00:00
|
|
|
if (!Array.isArray(current)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return getLookup(nestedKey, current[1], current[0])
|
|
|
|
}
|
|
|
|
if (Array.isArray(current)) {
|
|
|
|
return [current[0], parent]
|
|
|
|
}
|
|
|
|
if (current === undefined && lookup._id !== undefined) {
|
|
|
|
const reverse = (lookup._id as any)[currentKey]
|
|
|
|
return reverse !== undefined ? [reverse, parent] : undefined
|
|
|
|
}
|
|
|
|
return current !== undefined ? [current, parent] : undefined
|
|
|
|
}
|
2022-02-10 09:04:18 +00:00
|
|
|
|
|
|
|
export function getBooleanLabel (value: boolean | undefined): IntlString {
|
|
|
|
if (value === true) return plugin.string.LabelYes
|
|
|
|
if (value === false) return plugin.string.LabelNo
|
|
|
|
return plugin.string.LabelNA
|
|
|
|
}
|
2022-02-16 09:02:31 +00:00
|
|
|
export function getCollectionCounter (hierarchy: Hierarchy, object: Doc, key: KeyedAttribute): number {
|
|
|
|
if (hierarchy.isMixin(key.attr.attributeOf)) {
|
|
|
|
return (hierarchy.as(object, key.attr.attributeOf) as any)[key.key]
|
|
|
|
}
|
|
|
|
return (object as any)[key.key] ?? 0
|
|
|
|
}
|