"use strict";
(function () {
'use strict';
angular.module('feedModule')
.directive('feedItemEventMessageRenderer', ['l10nModel', 'i18nService', 'metadataModel', '$compile', '$filter', 'approvalService', 'approvalModel', '$sce', 'utilityFunctions', 'pwaModel', 'configurationModel',
function (l10nModel, i18nService, metadataModel, $compile, $filter, approvalService, approvalModel, $sce, utilityFunctions, pwaModel, configurationModel) {
var profileLinkTemplate = '{displayValue}';
var profileUnLinkTemplate = '{displayValue}';
var urlLinkTemplate = '{displayValue}';
// tooltip-popup-delay="1" is a rquirement, as tooltip needs to be launche async. When launching sync on click - may cause delay in appearence
var tooltipTemplate = '{displayValue}';
/**
* Returns html template for entity.
*
* @param {EntityVO} entity
* @returns {String} html string
*/
var entityTemplateFunction = function (entity, event, relatedObject, isUnlinkEntityValue) {
switch (entity.type) {
case EntityVO.TYPE_PERSON:
case EntityVO.TYPE_INCIDENT:
case EntityVO.TYPE_CHANGE:
case EntityVO.TYPE_WORKORDER:
case EntityVO.TYPE_SERVICEREQUEST:
case EntityVO.TYPE_PROBLEM:
case EntityVO.TYPE_KNOWNERROR:
case EntityVO.TYPE_KNOWLEDGE:
case EntityVO.TYPE_RELEASE:
case EntityVO.TYPE_ACTIVITY:
case EntityVO.TYPE_TASK:
case EntityVO.TYPE_EMAIL_LINK:
if (isUnlinkEntityValue) {
return profileUnLinkTemplate;
}
else {
return profileLinkTemplate;
}
case EntityVO.TYPE_ASSET:
return profileLinkTemplate;
case EntityVO.TYPE_URL:
return urlLinkTemplate;
case EntityVO.TYPE_INTEGER:
if (event.eventType === "change-collision") {
entity.entityLink = '#/' + relatedObject.type + '/' + relatedObject.id + '/collisions';
return profileLinkTemplate;
}
else {
return tooltipTemplate;
}
break;
case EntityVO.TYPE_PRIORITY:
case EntityVO.TYPE_STATUS:
case EntityVO.TYPE_MILESTONE:
case EntityVO.TYPE_STATUS_REASON:
if (entity.type === EntityVO.TYPE_STATUS && event.messageId <= 51350 && event.messageId >= 51300) {
return '"' + (entity.displayValue ? entity.displayValue.trim() : '') + '"';
}
else {
return '"' + $filter('localizeLabel')(entity.displayValue, entity.type, relatedObject.type) + '"';
}
case EntityVO.TYPE_OUTAGE_TYPE:
return i18nService.getLocalizedString("create.outage.type." + entity.displayValue.replace(/\s+/g, '.').toLowerCase());
case EntityVO.TYPE_TEXT:
if (entity.displayValue) {
entity.displayValue = utilityFunctions.escapeHTML(entity.displayValue);
}
return entity.displayValue;
case EntityVO.TYPE_TIME:
// returns humanized duration string
return moment.duration(+entity.displayValue * 1000 - event.createDate.getTime()).humanize();
case EntityVO.TYPE_TIMESTAMP:
// returns humanized date string
return moment(+entity.displayValue).calendar({ sameElse: 'lll' });
default:
return entity.displayValue;
}
};
return {
restrict: 'E',
replace: true,
scope: {
event: '=',
relatedObject: '=',
parentContext: '=',
isUpdateFeed: '=',
isAppEnabled: '=?'
},
template: '
',
link: function (scope, iElement) {
var event = scope.event, relatedObject = scope.relatedObject, isAppEnabled = scope.isAppEnabled;
scope.tooltipHtml = '';
scope.loadingApprovalDialog = false;
scope.showApprovers = function (showClosedTabDefault) {
scope.loadingApprovalDialog = true;
approvalModel.getListOfApprovers(relatedObject).then(function (data) {
approvalService.showApproversDialog(data.approvalList, scope.parentContext, showClosedTabDefault);
}).finally(function () {
scope.loadingApprovalDialog = false;
});
};
function init() {
var entityProps = EntityVO.prototype.getProps().concat('entityLink');
var entities = event.entities.map(function (entity, index) {
var isUnlinkEntityValue = _.includes(event.eventType, 'create') && !isAppEnabled && entity.type !== 'person';
var entityTemplate = entityTemplateFunction(entity, event, relatedObject, isUnlinkEntityValue);
if (entity.type == "person" && entity.displayValue) {
entity.displayValue = utilityFunctions.escapeHTML(entity.displayValue);
}
entityProps.forEach(function (property) {
if (pwaModel.isPwaEnabled() && (configurationModel.get('pwaEnabledTickets.tickets').indexOf(entity.type) >= 0) && property === "entityLink") {
entity[property] = entity[property] && entity[property].replace(entity.type, entity.type + "PV");
entityTemplate = entityTemplate.toString().replace(new RegExp('{' + property + '}', 'g'), entity[property]);
}
else {
entityTemplate = entityTemplate.toString().replace(new RegExp('{' + property + '}', 'g'), entity[property]);
}
});
entityTemplate = entityTemplate.toString().replace(new RegExp('ux-id', 'g'), 'ux-id="event-msg-profile-link_' + entity.type + '"');
if (entity.type == "person") {
return $sce.getTrustedHtml(entityTemplate).replace(new RegExp(' 0) {
var recipients = event.recipients.map(function (entity) {
var entityTemplate = entityTemplateFunction(entity, event, relatedObject);
entityProps.forEach(function (property) {
entityTemplate = entityTemplate.toString().replace(new RegExp('{' + property + '}', 'g'), entity[property]);
if (property == "displayValue") {
$sce.getTrustedHtml(entityTemplate);
}
});
return entityTemplate;
});
scope.tooltipHtml = '' + i18nService.getLocalizedString('email.tooltip.headerText') + ':
';
_.forEach(recipients, function (recipient, key) {
scope.tooltipHtml += recipient + (key === recipients.length - 1 ? '' : ', ');
});
scope.tooltipHtml += '
';
}
// check if localized label template is available
var localizedTemplate = l10nModel.getLocalizedMessage(event.messageId) ? l10nModel.getLocalizedMessage(event.messageId).value : event.labelTemplate;
if (event.messageId <= 51350 && event.messageId >= 51300) {
localizedTemplate = localizedTemplate.replaceAll("#newline#", "\n");
entities = entities.map(Function.prototype.call, String.prototype.trim); //To trim whitespaces in an array.
}
// fill in the placeholders
var messageTemplate = $filter('i18n')(localizedTemplate, entities);
// apply final styling
if (event.isSlaChange() || event.isSlaMet()) {
// find message to colorize ("SLA Alert:")
var endIndex = messageTemplate.indexOf(':') + 1;
var stringToPaint = messageTemplate.substr(0, endIndex);
// apply specific styles
messageTemplate = messageTemplate.replace(stringToPaint, '' + stringToPaint + '');
}
var contents;
if ((event.messageId <= 65007 && event.messageId >= 65002)
|| (event.messageId >= 61002 && event.messageId <= 61004)
|| (event.messageId >= 66018 && event.messageId <= 66020)
|| (event.messageId <= 51350 && event.messageId >= 51300)) {
contents = '' + messageTemplate + '
';
}
else {
contents = '' + messageTemplate + '
';
}
if (((event.messageId <= 65007 && event.messageId >= 65002) || (event.messageId >= 61002 && event.messageId <= 61004)) && !scope.isUpdateFeed && !(scope.parentContext && scope.parentContext instanceof PersonProfileVO)) {
if (event.messageId == 65002) {
contents += ("