"use strict"; function RelationItemVO() { // simple fields this.desc = ''; this.displayId = ''; this.parentId = ''; this.relationshipType = ''; this.tag = ''; this.type = ''; this.templateName = ''; this.relationshipClassId; // complex fields this.realObject = {}; this.visited = false; this.subType = ""; } RelationItemVO.prototype = new BaseVO(); RelationItemVO.prototype.constructor = RelationItemVO; RelationItemVO.TAG_RESOURCE = 'resource'; RelationItemVO.TAG_LINKEDITEM = 'linkeditem'; RelationItemVO.TAG_RELEASEPLAN = 'releaseplan'; RelationItemVO.TYPE_RELATEDTO = 'relatedto'; RelationItemVO.TYPE_DUPLICATEOF = 'duplicateof'; RelationItemVO.TYPE_ORIGINALOF = 'originalof'; RelationItemVO.TYPE_REFERENCES = 'references'; RelationItemVO.TYPE_CAUSED = 'caused'; RelationItemVO.TYPE_CAUSEDBY = 'causedby'; RelationItemVO.TYPE_RESOLVED = 'resolved'; RelationItemVO.TYPE_RESOLVEDBY = 'resolvedby'; RelationItemVO.TYPE_IMPACTS = 'impacts'; RelationItemVO.TYPE_IMPACTEDBY = 'impactedby'; RelationItemVO.TYPE_RESTORES = 'restores'; RelationItemVO.TYPE_RESTOREDBY = 'restoredby'; RelationItemVO.TYPE_REOPENEDFROM = 'reopenedfrom'; RelationItemVO.TYPE_REOPENEDBY = 'reopenedby'; RelationItemVO.TYPE_USEDBY = 'usedby'; RelationItemVO.TYPE_POI = 'POI'; RelationItemVO.TYPE_CREATED = 'created'; RelationItemVO.TYPE_CREATEDBY = 'createdby'; RelationItemVO.TYPE_INITIATES = 'initiates'; RelationItemVO.TYPE_INITIATEDBY = 'initiatedby'; RelationItemVO.TYPE_CONSISTSOF = 'consistsof'; RelationItemVO.TYPE_MEMBEROF = 'memberof'; /** * @override * @return {Array} properties */ RelationItemVO.prototype.getProps = function () { return BaseVO.prototype.getProps().concat('desc', 'displayId', 'parentId', 'relationshipType', 'tag', 'type', 'templateName', 'realObject', 'relationshipClassId'); }; /** * @override */ RelationItemVO.prototype.postBuild = function () { // todo Sun: remove this once backend fix the type value for crowdsourced asset if (this.type === 'Crowdsourced Asset') { this.type = 'asset'; } this.isPoi = this.relationshipType === RelationItemVO.TYPE_POI; if (this.isAsset()) { if (this.isPoi && !this.realObject.reconciliationId && this.realObject.poiId) { this.realObject.reconciliationId = this.realObject.poiId; } this.entityLink = '#/' + this.type + '/' + this.realObject.reconciliationId + '/' + this.realObject.classId; } this.subType = this.realObject.isAutomatic ? "-auto" : ""; if (this.type === EntityVO.TYPE_CONTRACT) { this.expirationDateHumanized = this.realObject.expirationDate ? moment(this.realObject.expirationDate).format('lll') : null; } }; RelationItemVO.prototype.getRating = function () { return Math.round((this.realObject.useCount / ((+this.realObject.useCount) + (+this.realObject.notUsefulCount))) * 100) || 0; }; RelationItemVO.prototype.getNumberOfViews = function () { if (!_.isUndefined(this.realObject.viewCount) && (this.realObject.viewCount !== null)) { return this.realObject.viewCount; } else { return -1; } }; RelationItemVO.prototype.getNumberOfLinkedItems = function () { if (!_.isUndefined(this.realObject.linkedItems) && (this.realObject.linkedItems !== null)) { return this.realObject.linkedItems; } else { return -1; } }; RelationItemVO.prototype.getLastModifyDate = function () { return this.realObject.modifiedDate; }; RelationItemVO.prototype.getStatus = function () { return this.realObject.status.value; }; RelationItemVO.prototype.getAssigneeFullName = function () { return this.realObject.assignee.fullName; }; RelationItemVO.prototype.isAsset = function () { return this.type === EntityVO.TYPE_ASSET; }; RelationItemVO.prototype.isDecisionTree = function () { return this.templateName === 'Decision Tree'; }; RelationItemVO.prototype.isArticleActive = function () { var fieldObj = this.realObject || this.additionalInformation; return this.type === EntityVO.TYPE_KNOWLEDGE ? ["Cancelled", "Retire Approval", "Retired", "Closed Version"].indexOf(fieldObj && fieldObj.status && fieldObj.status.value) === -1 : true; };