"use strict"; /** * Value object for knowledge article item. * * @author Victor Shevchenko * @author Igor Samulenko * * @constructor */ function KnowledgeArticleVO() { // simple fields this.title = ''; this.isDraft = false; this.createDate = null; this.updateDate = null; this.modifiedDate = null; this.desc = ''; this.likePercentage = 0; this.rating = ''; this.useCount = 0; this.notUsefulCount = 0; this.viewCount = 0; this.type = EntityVO.TYPE_KNOWLEDGE; this.articleId = ''; this.status = ''; this.following = false; this.tags = ''; this.entityLink = ''; this.uuid = ''; this.templateId = ''; this.templateName = ''; this.version = 0; this.favorite = false; this.flagged = false; this.articleGUID = ''; this.isLastVersion = false; this.isInApproval = false; this.attachmentLimit = 0; this.internalUse = false; this.perfAssessment = false; // complex fields this.additionalCategoriesOrganization = []; this.additionalCategoriesSite = []; this.additionalCategoriesBusinessService = []; this.additionalCategoriesCompanies = []; this.additionalCategorization = []; this.articleVisibilityGroup = []; this.categorizations = []; this.content = []; this.assignee = {}; this.author = {}; this.owner = {}; this.company = {}; this.comments = []; this.hashTags = []; this.accessMappings = {}; this.assigneeGroup = {}; this.supportGroup = {}; this.language = ''; //mocked data for article metadata this.autoAssign = true; this.site = {}; this.businessService = {}; this.organization = {}; this.commentCount = 0; //for primary/additional data this.allCompanies = []; this.allSites = []; this.allServices = []; this.allOrganizations = []; this.approvalProcessName = ''; this.isPasswordEnabled = false; } // inherit BaseVO KnowledgeArticleVO.prototype = new BaseVO(); // correct the constructor pointer KnowledgeArticleVO.prototype.constructor = KnowledgeArticleVO; /** * @override * @return {Array} */ KnowledgeArticleVO.prototype.getProps = function () { var keys = Object.keys(new KnowledgeArticleVO()); return BaseVO.prototype.getProps().concat(keys); }; KnowledgeArticleVO.prototype.postBuild = function () { this.recalculateRating(); if (!_.isEmpty(this.accessMappings)) { var accessMappings = {}; for (var i = 0; i < this.accessMappings.length; i++) { var accessMappingId = this.accessMappings[i].id.indexOf('action') !== -1 ? this.accessMappings[i].id.replace(/\-/g, '').replace('action', '') + 'ActionAllowed' : this.accessMappings[i].id + 'EditAllowed'; accessMappings[accessMappingId] = (this.accessMappings[i].permission === 'write'); } this.accessMappings = accessMappings; } else { this.accessMappings = { assigneeEditAllowed: true, attachmentsEditAllowed: true, companyEditAllowed: true, detailsEditAllowed: true, relationsEditAllowed: true, statusEditAllowed: true, summaryEditAllowed: true, timelineEditAllowed: true, visibilitygroupsEditAllowed: true, helpfulEditAllowed: true, internaluseEditAllowed: true }; } this.status = { value: this.status }; this.content = _.sortBy(this.content, 'order'); this.entityLink = '#/' + this.type + '/' + this.uuid; this.tags = !this.tags ? [] : this.tags.split(','); if (this.supportGroup) { this.assigneeGroup = this.supportGroup; } if (this.assignee) { this.autoAssign = false; } if (this.templateName === 'Decision Tree' && angular.isObject(this.content[0])) { this.decisionTree = JSON.parse(this.content[0].snippet); } this.defaultCategorization = [ { name: 'operational', tiers: {} }, { name: 'product', tiers: {} } ]; this.categorizations = _.filter(this.categorizations, function (category) { return !_.isEmpty(category.tiers); }); _.forEach(this.categorizations, function (category) { category.company = { name: this.company.name }; }, this); _.forEach(this.additionalCategorization, function (category) { category.company = { name: this.company.name }; }, this); }; /** * Returns full name of knowledge article author. * * @returns {String} */ KnowledgeArticleVO.prototype.getAuthorFullName = function () { return this.author && this.author.getFullName() || ''; }; /** * Returns profile thumbnail of knowledge article author. * * @returns {String} */ KnowledgeArticleVO.prototype.getAuthorThumbnail = function () { return (this.author.thumbnailMime && this.author.thumbnail) ? ('data:' + this.author.thumbnailMime + ';base64,' + this.author.thumbnail) : ''; }; KnowledgeArticleVO.prototype.isDecisionTree = function () { if (this.templateName === 'Decision Tree') { return true; } return false; }; KnowledgeArticleVO.prototype.recalculateRating = function () { this.viewCount = (+this.useCount) + (+this.notUsefulCount); this.rating = Math.round((this.useCount / this.viewCount) * 100); };