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

158 lines
9.2 KiB
JavaScript
Raw Permalink 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', function (l10nModel, i18nService, metadataModel, $compile, $filter, approvalService, approvalModel, $sce) {
var profileLinkTemplate = '<a href="{entityLink}">{displayValue}</a>';
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-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) {
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:
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:
return '"' + $filter('localizeLabel')(entity.displayValue, entity.type, relatedObject.type) + '"';
case EntityVO.TYPE_TEXT:
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();
default:
return entity.displayValue;
}
};
return {
restrict: 'E',
replace: true,
scope: {
event: '=',
relatedObject: '=',
parentContext: '=',
isUpdateFeed: '='
},
template: '<div><div loading-spinner if="loadingApprovalDialog" overlay="true" inline="true"></div></div>',
link: function (scope, iElement) {
var event = scope.event, relatedObject = scope.relatedObject;
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) {
var entityTemplate = entityTemplateFunction(entity, event, relatedObject);
entityProps.forEach(function (property) {
entityTemplate = entityTemplate.toString().replace(new RegExp('{' + property + '}', 'g'), entity[property]);
});
if (entity.type == "person") {
return $sce.getTrustedHtml(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;
// 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 = '<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) {
metadataModel.getMetadataByType(relatedObject.type).then(function () {
init();
});
}
else {
init();
}
}
}
};
}]);
}());