SmartIT_Extensions/BMC/smart-it-full-helix/components/chat/chat-message.js

107 lines
5.1 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('myitsmApp')
.directive('chatMessage', ['$timeout', 'chatModel', 'chatSwarm', '$filter', '$state', function ($timeout, chatModel, chatSwarm, $filter, $state) {
return {
restrict: 'AE',
templateUrl: 'components/chat/chat-message.html',
replace: true,
scope: {
message: "=context",
type: '@'
},
link: function (scope, $element, attr) {
if (scope.message.author && (chatModel.currentUser.jid == scope.message.author.jid)) {
scope.selfMessage = true;
}
;
scope.getMessageAge = function () {
return moment(scope.message.created).fromNow();
};
scope.redirectTo = function (type, data) {
switch (type) {
case "person":
$state.go('person', { id: data.loginId || data.elementId });
break;
case 'ticket':
$state.go(data.type, { id: data.id });
break;
case 'asset':
$state.go('asset', { assetId: data.reconciliationId, assetClassId: data.classId });
break;
}
};
scope.inviteUser = function (user, chatWindow) {
chatModel.inviteUserToChat(user, chatWindow);
};
scope.tools = function (messageText, chatWindowId, chatWindow) {
if (!chatWindow) {
chatWindow = _.find(chatModel.activeChatRooms, { id: chatWindowId });
}
if (chatWindow) {
chatModel.processChatMessage(messageText, chatWindow);
}
};
scope.linkKnowledgeArticle = function (uuid, type, chatWindowParentId) {
chatSwarm.linkKnowledgeArticles(uuid, type, chatWindowParentId);
};
scope.unlinkKnowledgeArticle = function (uuid, type, chatWindowParentId) {
chatSwarm.unlinkKnowledgeArticles(uuid, type, chatWindowParentId);
};
scope.inviteUser = function (user, chatWindow) {
chatModel.inviteUserToChat(user, chatWindow);
};
scope.formatMessage = function (message, chatWindow) {
if (message.startsWith(EntityVO.CHATOPS_DETAILS)) {
if (chatSwarm.checkIfJson(message.substring(8)))
return EntityVO.CHATOPS_DETAILS;
else
return message;
}
if (message.startsWith(EntityVO.CHATOPS_SWARM)) {
if (chatSwarm.checkIfJson(message.substring(6)))
return EntityVO.CHATOPS_SWARM;
else
return message;
}
else if (message.startsWith(EntityVO.CHATOPS_INCIDENT)) {
if (chatSwarm.checkIfJson(message.substring(9)))
return EntityVO.CHATOPS_SIMILARINCIDENTS;
else
return message;
}
else if (message.startsWith(EntityVO.CHATOPS_KNOWLEDGE)) {
if (chatSwarm.checkIfJson(message.substring(10)))
return EntityVO.CHATOPS_KNOWLEDGE;
else
return message;
}
else if (message.startsWith(EntityVO.CHATOPS_SIMILARINCIDENTS)) {
if (chatSwarm.checkIfJson(message.substring(17)))
return EntityVO.CHATOPS_SIMILARINCIDENTS;
else
return message;
}
else {
return message;
}
};
}
};
}])
.directive('scrollToLastItem', ['$timeout', function ($timeout) {
return {
restrict: 'A',
link: function (scope, $element) {
if (scope.$last === true) {
$timeout(function () {
var $parent = $element.parent();
$parent[0].scrollTop = $parent[0].scrollHeight;
});
}
}
};
}]);
}());