198 lines
11 KiB
JavaScript
198 lines
11 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('consoleModule')
|
|
.directive('accessibleItemList', ['$rootScope', 'knowledgeConsoleModel', 'ticketConsoleModel', 'assetConsoleModel', 'events', '$filter', 'browser', function ($rootScope, knowledgeConsoleModel, ticketConsoleModel, assetConsoleModel, events, $filter, browser) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/console/accessible-item-list.html',
|
|
scope: {
|
|
consoleType: '=',
|
|
itemList: '=',
|
|
gridColumns: '=',
|
|
totalItemsFound: '=',
|
|
state: '=',
|
|
criteria: '=',
|
|
handleRowSelection: '&',
|
|
showSelection: "=",
|
|
exceedChunkSize: "="
|
|
},
|
|
link: function (scope) {
|
|
scope.isMobile = browser.isMobile;
|
|
scope.accessibilityGridColumns = angular.copy(scope.gridColumns);
|
|
scope.showNextButton = false;
|
|
scope.endTicketCount = 0;
|
|
var selectedRows = [], consoleModel;
|
|
scope.accessibleItemList = [];
|
|
scope.rtlMode = window.isRtl;
|
|
scope.quickSearchColumns = ticketConsoleModel.quickSearchHighlightedColumn || [];
|
|
switch (scope.consoleType) {
|
|
case 'ticket':
|
|
consoleModel = ticketConsoleModel;
|
|
break;
|
|
case 'knowledge':
|
|
consoleModel = knowledgeConsoleModel;
|
|
break;
|
|
case 'asset':
|
|
consoleModel = assetConsoleModel;
|
|
break;
|
|
}
|
|
var availableColConfig = (consoleModel && consoleModel.availableColConfig) ? consoleModel.availableColConfig : [];
|
|
var dateTypeColumns = _.filter(availableColConfig, function (conf) {
|
|
if (conf.cellFilter && conf.cellFilter.indexOf('datePreConfigTimezone:') !== -1) {
|
|
return true;
|
|
}
|
|
else {
|
|
return (conf.field.dataType === 'datetime' || conf.field.dataType === 'date');
|
|
}
|
|
});
|
|
function isDateType(attributeName) {
|
|
if (scope.consoleType === 'knowledge' && attributeName === 'modifiedDate') {
|
|
attributeName = 'lastModifiedDate';
|
|
}
|
|
var index = _.findIndex(dateTypeColumns, function (col) {
|
|
return col.name === attributeName;
|
|
});
|
|
return (index > -1);
|
|
}
|
|
function getActualName(attributeName) {
|
|
if (attributeName === 'incidentType') {
|
|
attributeName = 'serviceType';
|
|
}
|
|
else if (attributeName === 'changeClass') {
|
|
attributeName = 'timing';
|
|
}
|
|
else if (attributeName === 'releaseType') {
|
|
attributeName = 'type';
|
|
}
|
|
return attributeName;
|
|
}
|
|
scope.getColumnData = function (rowData, field, attributeName) {
|
|
var colData = angular.copy(rowData);
|
|
field = field.split('.');
|
|
for (var i = 0; i < field.length; i++) {
|
|
if (colData.hasOwnProperty(field[i])) {
|
|
colData = colData[field[i]];
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
}
|
|
if ([EntityVO.TYPE_STATUS, EntityVO.TYPE_STATUS_REASON, EntityVO.TYPE_PRIORITY, EntityVO.TYPE_IMPACT, EntityVO.TYPE_URGENCY,
|
|
'incidentType', 'reportedSource', 'changeClass', 'changeReason', 'riskLevel', 'investigationDriver',
|
|
'businessJustification', 'milestone', 'releaseType', 'taskType', 'workOrderType'].indexOf(attributeName) !== -1) {
|
|
colData = $filter('localizeLabel')(colData, getActualName(attributeName), scope.consoleType === EntityVO.TYPE_ASSET ? rowData.ticketType : rowData.type);
|
|
}
|
|
else if (attributeName === 'type' && scope.consoleType !== EntityVO.TYPE_ASSET) {
|
|
colData = $filter('tcCellType')(colData);
|
|
}
|
|
else if (attributeName === 'type' && scope.consoleType === EntityVO.TYPE_ASSET) {
|
|
colData = $filter('localizeLabel')(colData, 'assetType', rowData.ticketType);
|
|
}
|
|
else if (attributeName === 'isEscalated') {
|
|
colData = $filter('tcCellEscalated')(colData);
|
|
}
|
|
else if (isDateType(attributeName)) {
|
|
if (colData) {
|
|
colData = $filter('datePreConfigTimezone')(colData, 'mediumDate') + ' ' + $filter('datePreConfigTimezone')(colData, 'mediumTime');
|
|
}
|
|
}
|
|
else if (attributeName === 'slaStatus') {
|
|
colData = $filter('tcCellSlaStatus')(colData);
|
|
}
|
|
else if (attributeName === 'targetDate') {
|
|
colData = $filter('tcCellSLA')(colData);
|
|
}
|
|
else if (attributeName === 'needsAttention') {
|
|
if (colData === 'Yes') {
|
|
colData = $filter('i18n')('common.labels.yes');
|
|
}
|
|
else if (colData === 'No') {
|
|
colData = $filter('i18n')('common.labels.no');
|
|
}
|
|
}
|
|
return colData;
|
|
};
|
|
scope.selectTicket = function (ticket) {
|
|
if (ticket.selected) {
|
|
selectedRows.push(ticket);
|
|
}
|
|
else {
|
|
_.remove(selectedRows, { id: ticket.id });
|
|
}
|
|
scope.handleRowSelection({ data: selectedRows });
|
|
};
|
|
scope.selectAllTickets = function (selectAll) {
|
|
for (var i = 0; i < scope.itemList.length; i++) {
|
|
scope.itemList[i].selected = selectAll;
|
|
}
|
|
selectedRows = selectAll ? angular.copy(scope.itemList) : [];
|
|
scope.handleRowSelection({ data: selectedRows });
|
|
};
|
|
scope.$on(events.SELECT_ALL_TICKETS, function (event, selectAll) {
|
|
scope.selectAllTickets(selectAll);
|
|
});
|
|
var displayNextButton = function () {
|
|
if (scope.itemList && scope.endTicketCount === scope.itemList.length) {
|
|
scope.showNextButton = false;
|
|
}
|
|
else {
|
|
scope.showNextButton = true;
|
|
}
|
|
};
|
|
scope.fetchMoreTickets = function (direction) {
|
|
if (direction === 'next') {
|
|
scope.criteria.chunkInfo.startIndex += consoleModel.defaultChunkSize;
|
|
}
|
|
else {
|
|
scope.criteria.chunkInfo.startIndex -= consoleModel.defaultChunkSize;
|
|
}
|
|
if (scope.itemList[scope.criteria.chunkInfo.startIndex]) {
|
|
scope.endTicketCount = scope.criteria.chunkInfo.startIndex + scope.criteria.chunkInfo.chunkSize > scope.itemList.length ? scope.itemList.length :
|
|
scope.criteria.chunkInfo.startIndex + scope.criteria.chunkInfo.chunkSize;
|
|
scope.accessibleItemList = scope.itemList.slice(scope.criteria.chunkInfo.startIndex, scope.endTicketCount);
|
|
displayNextButton();
|
|
}
|
|
};
|
|
scope.sortColumn = function (columnName) {
|
|
var sortColumnIndex = _.findIndex(scope.accessibilityGridColumns, { attributeName: scope.criteria.sortInfo.sortFieldName });
|
|
if (scope.criteria.sortInfo.sortFieldName === columnName) {
|
|
scope.accessibilityGridColumns[sortColumnIndex].sortOrder =
|
|
scope.accessibilityGridColumns[sortColumnIndex].sortOrder === 'ASC' ? 'DESC' : 'ASC';
|
|
}
|
|
else {
|
|
if (sortColumnIndex !== -1) {
|
|
delete scope.accessibilityGridColumns[sortColumnIndex].sortOrder;
|
|
}
|
|
sortColumnIndex = _.findIndex(scope.accessibilityGridColumns, { attributeName: columnName });
|
|
scope.accessibilityGridColumns[sortColumnIndex].sortOrder = 'ASC';
|
|
}
|
|
scope.criteria.sortInfo = {
|
|
sortFieldName: columnName,
|
|
sortFieldOrder: scope.accessibilityGridColumns[sortColumnIndex].sortOrder
|
|
};
|
|
};
|
|
scope.$watch('itemList', function () {
|
|
if (scope.itemList && scope.itemList.length) {
|
|
scope.endTicketCount = scope.criteria.chunkInfo.startIndex + scope.criteria.chunkInfo.chunkSize > scope.itemList.length ? scope.itemList.length :
|
|
scope.criteria.chunkInfo.startIndex + scope.criteria.chunkInfo.chunkSize;
|
|
scope.accessibleItemList = scope.itemList.slice(scope.criteria.chunkInfo.startIndex, scope.endTicketCount);
|
|
}
|
|
else {
|
|
scope.accessibleItemList = [];
|
|
scope.endTicketCount = 0;
|
|
}
|
|
displayNextButton();
|
|
}, true);
|
|
scope.$watch('gridColumns', function () {
|
|
scope.accessibilityGridColumns = angular.copy(scope.gridColumns);
|
|
if (window.isRtl) {
|
|
scope.accessibilityGridColumns.reverse();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}]);
|
|
})();
|