SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/feed/feed-item-event-message-ren...

216 lines
13 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

"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 = '<a ux-id href="{entityLink}">{displayValue}</a>';
var profileUnLinkTemplate = '<span>{displayValue}</span>';
var urlLinkTemplate = '<a aria-haspopup="true" target="_blank" href="{entityLink}">{displayValue}</a>';
// 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 = '<a href="{entityLink}" tooltip-trigger="\'outsideClick\'" tooltip-placement="bottom" tooltip-append-to-body="true" tooltip-popup-delay="1" uib-tooltip-html=\"tooltipHtml\">{displayValue}</a>';
/**
* 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: '<div><div loading-spinner if="loadingApprovalDialog" overlay="true" inline="true"></div></div>',
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('<a', 'g'), '<a ux-id="event-msg-profile-link_' + entity.type + '"');
}
else if (event.eventType === EventVO.prototype.VENDOR_NOTE_V2) {
if (entity.type === 'url') {
return $sce.getTrustedHtml(entityTemplate);
}
else if (index === 2) {
// index 2 is the MCSM vendor name, in this case, we do not want to encode it
return encodeURI(entityTemplate).replace(/%20/g, ' ');
}
else {
return entityTemplate;
}
}
else {
return entityTemplate;
}
});
if (event.recipients.length > 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 = '<div>' + i18nService.getLocalizedString('email.tooltip.headerText') + ':</div><div>';
_.forEach(recipients, function (recipient, key) {
scope.tooltipHtml += recipient + (key === recipients.length - 1 ? '' : ', ');
});
scope.tooltipHtml += '</div>';
}
// 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, '<span class="system-event-message__' + event.eventType + '">' + stringToPaint + '</span>');
}
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 = '<div class="feed__item-format">' + messageTemplate + '</div>';
}
else {
contents = '<div>' + messageTemplate + '</div>';
}
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 += ("<button class='btn_link' ng-click='showApprovers(true)'>");
}
else {
contents += ("<button class='btn_link' ng-click='showApprovers(false)'>");
}
contents += (i18nService.getLocalizedString('approval.approversList.labels.showList') + '</div>');
}
iElement.append($compile(contents)(scope));
}
if (!event) {
console.log('No information about system event.');
}
else {
var entityIndex = _.findIndex(event.entities, function (entity) {
return entity.type === EntityVO.TYPE_PRIORITY || entity.type === EntityVO.TYPE_STATUS;
});
if (entityIndex !== -1) {
var types = [relatedObject.type];
if (relatedObject.type !== EntityVO.TYPE_TASK) {
types.push(EntityVO.TYPE_TASK);
}
metadataModel.getMetadataByTypes(types).then(function () {
init();
});
}
else {
init();
}
}
}
};
}]);
}());