knowmax-quest-utils
Version:
Utilities for creating a Knowmax Quest client.
89 lines • 3.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollectionNode = void 0;
const knowmax_quest_types_1 = require("knowmax-quest-types");
const questid_1 = require("../questid");
/** Implementation of @see ICollectionNode extended with computed properties. */
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 ? (0, questid_1.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 === knowmax_quest_types_1.LICENSEACCESS_ENABLED ? true : this.license === knowmax_quest_types_1.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;
}
}
}
exports.CollectionNode = CollectionNode;
//# sourceMappingURL=CollectionNode.js.map