UNPKG

knowmax-quest-utils

Version:

Utilities for creating a Knowmax Quest client.

85 lines 3.79 kB
import { LICENSEACCESS_ENABLED, LICENSEACCESS_DISABLED } from 'knowmax-quest-types'; import { generateQuestId } from '../questid'; /** Implementation of @see ICollectionNode extended with computed properties. */ export class CollectionNode { constructor(data) { //#region ICollectionNode implementation /** Numeric identification of node. */ this.id = 0; /** Numeric identification of collection to which node belongs. */ this.collectionId = 0; this.sequence = 0; this.created = ''; this.createdBy = ''; this.modified = ''; this.modifiedBy = ''; /** Indicates if child nodes are available for this node. */ this.hasChilds = false; this.setData(data); } //#endregion //#region Extensions /** Consolidated title for this node. Prefers specified title for collection node and falls through to title of optionally referenced document. Might return "[???]" in case no title was available for this node. */ get consolidatedTitle() { return this.title ?? this.referencedTitle ?? '[???]'; } /** Referenced Quest identification including requested version. Version is omitted for references to current version. */ get questId() { return this.documentQuestId && this.referenceValid && this.referencedVersion ? generateQuestId(this.documentQuestId, this.referencedVersion, !this.documentVersion ? true : undefined) : undefined; } /** Interpreted value for license presented as boolean. True if license explicitly granted. False if license explicitly not granted or undefined in case no explicit license grant available. */ get hasLicense() { return this.license === LICENSEACCESS_ENABLED ? true : this.license === LICENSEACCESS_DISABLED ? false : undefined; } /** True in case no explicit version was referenced, so assume current version was referenced. */ get current() { return !this.documentVersion; } /** Set (partial) data from given node */ setData(node) { if (node) { if (node.id) { this.id = node.id; } if (node.collectionId !== undefined) { this.collectionId = node.collectionId; } this.parentId = node.parentId; if (node.sequence) { this.sequence = node.sequence; } this.title = node.title; this.description = node.description; this.documentQuestId = node.documentQuestId; this.documentId = node.documentId; this.documentVersion = node.documentVersion; this.customValue = node.customValue; this.customLicenseId = node.customLicenseId; if (node.created) { this.created = node.created; } if (node.createdBy) { this.createdBy = node.createdBy; } if (node.modified) { this.modified = node.modified; } if (node.modifiedBy) { this.modifiedBy = node.modifiedBy; } if (node.hasChilds) { this.hasChilds = node.hasChilds; } this.referencedTitle = node.referencedTitle; this.referencedVersion = node.referencedVersion; this.referencedDate = node.referencedDate; this.referenceValid = node.referenceValid; this.referenceExact = node.referenceExact; this.license = node.license; this.hasLicenseEnabled = node.hasLicenseEnabled; this.hasLicenseDisabled = node.hasLicenseDisabled; this.child = node.child; } } } //# sourceMappingURL=CollectionNode.js.map