149 lines
8.2 KiB
JavaScript
149 lines
8.2 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('consoleModule')
|
|
.directive('accessibleItemList', ['knowledgeConsoleModel', 'ticketConsoleModel', 'assetConsoleModel', 'events', '$filter', function (knowledgeConsoleModel, ticketConsoleModel, assetConsoleModel, events, $filter) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/console/accessible-item-list.html',
|
|
scope: {
|
|
consoleType: '=',
|
|
itemList: '=',
|
|
gridColumns: '=',
|
|
totalItemsFound: '=',
|
|
state: '=',
|
|
criteria: '=',
|
|
handleRowSelection: '&',
|
|
showSelection: "="
|
|
},
|
|
link: function (scope) {
|
|
var selectedRows = [], consoleModel;
|
|
scope.accessibleItemList = [];
|
|
scope.rtlMode = window.isRtl;
|
|
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) {
|
|
return (conf.field.dataType === 'datetime' || conf.field.dataType === 'date');
|
|
});
|
|
function isDateType(attributeName) {
|
|
var index = _.findIndex(dateTypeColumns, function (col) {
|
|
return col.name === attributeName;
|
|
});
|
|
return (index > -1);
|
|
}
|
|
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 (attributeName === EntityVO.TYPE_STATUS || attributeName === EntityVO.TYPE_PRIORITY
|
|
|| attributeName === EntityVO.TYPE_IMPACT || attributeName === EntityVO.TYPE_URGENCY) {
|
|
colData = $filter('localizeLabel')(colData, 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)) {
|
|
colData = $filter('date')(colData, 'mediumDate') + ' ' + $filter('date')(colData, 'mediumTime');
|
|
}
|
|
else if (attributeName === 'slaStatus') {
|
|
colData = $filter('tcCellSlaStatus')(colData);
|
|
}
|
|
else if (attributeName === 'targetDate') {
|
|
colData = $filter('tcCellSLA')(colData);
|
|
}
|
|
return colData;
|
|
};
|
|
scope.selectTicket = function (ticket) {
|
|
if (ticket.selected) {
|
|
selectedRows.push(ticket);
|
|
}
|
|
else {
|
|
selectedRows.splice(selectedRows.indexOf(ticket), 1);
|
|
}
|
|
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);
|
|
});
|
|
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);
|
|
}
|
|
};
|
|
scope.sortColumn = function (columnName) {
|
|
var sortColumnIndex = _.findIndex(scope.gridColumns, { attributeName: scope.criteria.sortInfo.sortFieldName });
|
|
if (scope.criteria.sortInfo.sortFieldName === columnName) {
|
|
scope.gridColumns[sortColumnIndex].sortOrder =
|
|
scope.gridColumns[sortColumnIndex].sortOrder === 'ASC' ? 'DESC' : 'ASC';
|
|
}
|
|
else {
|
|
if (sortColumnIndex !== -1) {
|
|
delete scope.gridColumns[sortColumnIndex].sortOrder;
|
|
}
|
|
sortColumnIndex = _.findIndex(scope.gridColumns, { attributeName: columnName });
|
|
scope.gridColumns[sortColumnIndex].sortOrder = 'ASC';
|
|
}
|
|
scope.criteria.sortInfo = {
|
|
sortFieldName: columnName,
|
|
sortFieldOrder: scope.gridColumns[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 = [];
|
|
}
|
|
}, true);
|
|
scope.$watch('gridColumns', function () {
|
|
if (window.isRtl) {
|
|
scope.gridColumns.reverse();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}]);
|
|
})();
|