98 lines
6.7 KiB
JavaScript
98 lines
6.7 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('changeModule')
|
|
.factory('ciRelationsModel', ['consoleService', 'configurationModel', 'metadataModel', 'userModel', '$rootScope', '$q', '$window',
|
|
function (consoleService, configurationModel, metadataModel, userModel, $rootScope, $q, $window) {
|
|
var ciRelationsModel = {},
|
|
//column header cell template for server side sorting, sorting works on all columns except for
|
|
// Asset Type column (backend does not support this, Reason - Asset Type is a Logical representation of CI,
|
|
// its not really a parameter in back-end form) and Related column (this is just a UI column)
|
|
//colHeaderCellTemplate is with sorting
|
|
colHeaderCellTemplate = '<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{cursor: col.cursor}" ng-class="{ ngSorted: !noSortVisible }">' +
|
|
'<div ux-id="header-col_{{::col.displayName}}" ng-click="sortColumn(search, col ); col.sort($event)" ng-class="\'colt\' + col.index" class="ngHeaderText" title="{{\'asset.attributes.\' + col.displayName | i18n | uppercase}}">{{\'asset.attributes.\' + col.displayName | i18n | uppercase}}</div>' +
|
|
'<div class="ngSortButtonUp" ng-show="col.showSortButtonDown()"></div>' +
|
|
'<div class="ngSortButtonDown" ng-show="col.showSortButtonUp()"></div>' +
|
|
'<div class="ngSortPriority">{{col.sortPriority}}</div>' +
|
|
'</div>' +
|
|
'<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event, search); columnResizeonMouseDown($event, search, col)"></div>',
|
|
//linkedColHeaderCellTemplate is without sorting
|
|
linkedColHeaderCellTemplate = '<div class="ngHeaderSortColumn {{col.headerClass}}" ng-class="{ ngSorted: !noSortVisible }">' +
|
|
'<div ux-id="header-col_{{::col.displayName}}" ng-class="\'colt\' + col.index" class="ngHeaderText" title="{{\'asset.attributes.\' + col.displayName | i18n | uppercase}}">{{\'asset.attributes.\' + col.displayName | i18n | uppercase}}</div>' +
|
|
'</div>' +
|
|
'<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event); columnResizeonMouseDown($event, search, col)"></div>',
|
|
//nameCellTemplate
|
|
nameCellTemplate = '<div class=\"ngCellText ci-search-section__results_name_col\" ng-class=\"col.colIndex()\">' +
|
|
'<a href="" ng-click= "showPreview(row.entity);" class=\"ci-search-section__results_name_col\"><span class=\"ngCellText ci-search-section__results_name_col\">{{row.getProperty(col.field)}}</span></a></div>',
|
|
//linkedCellTemplate is for related columns rows
|
|
linkedCellTemplate = '<div class=\"ngCellText ci-search-section_linked_column\" ng-class=\"col.colIndex()\">' +
|
|
'<div class="tag_removable ci-search-section__related" ng-repeat="tag in row.entity.relations track by $index">{{\'common.relationship.type.\' + tag | i18n}}' +
|
|
'<i class="icon-cross tag__remove" ng-click="removeLink(search, row.entity, tag)" ng-enter="removeLink(search, row.entity, tag)"' +
|
|
'title="{{\'common.button.remove\' | i18n}}" ' +
|
|
'aria-label="{{\'common.button.remove\' | i18n}} {{\'common.relationship.type.\' + tag | i18n}} {{\'resourceSlice.linkedItem.label\' | i18n}}" role=\"link\" tabindex=\"0\"></i>' +
|
|
'</div></div>', columnPreferenceGroup = 'CISearchColumns', columnPreferenceDetailsId = '', extendColumnConfig = function () {
|
|
_.forEach(ciRelationsModel.columnsConfig, function (column) {
|
|
var headerCellTemplate, cellTemplate;
|
|
//set header cell template
|
|
if (column.name === 'name' || column.name === 'classId' || column.name === 'status'
|
|
|| column.name === 'serialNumber' || column.name === 'site' || column.name === 'productName') {
|
|
headerCellTemplate = colHeaderCellTemplate;
|
|
}
|
|
else if (column.name === 'type' || column.name === 'related') {
|
|
headerCellTemplate = linkedColHeaderCellTemplate;
|
|
}
|
|
//set cell template
|
|
if (column.name === 'name') {
|
|
cellTemplate = nameCellTemplate;
|
|
}
|
|
if (column.name === 'related') {
|
|
var minWidth = 270; //min width is needed only for Related column
|
|
cellTemplate = linkedCellTemplate;
|
|
var maxWidth = 300;
|
|
}
|
|
//set initial width for columns
|
|
var gridWidth = $window.innerWidth - 640;
|
|
column.width = column.width ? column.width : gridWidth / 7;
|
|
angular.extend(column, {
|
|
headerCellTemplate: headerCellTemplate,
|
|
cellTemplate: cellTemplate,
|
|
minWidth: minWidth,
|
|
maxWidth: maxWidth,
|
|
width: minWidth ? minWidth : column.width
|
|
});
|
|
});
|
|
};
|
|
ciRelationsModel.finalLinkedCount = 0;
|
|
ciRelationsModel.populateConfiguration = function () {
|
|
if (!_.isEmpty(ciRelationsModel.columnsConfig)) {
|
|
return $q.when(1);
|
|
}
|
|
return $q.all([userModel.getUserPreferences(columnPreferenceGroup)]).then(function (config) {
|
|
if (config[0]) {
|
|
var columnConfig = config[0], columns = columnConfig.length ? columnConfig[0].value : {};
|
|
}
|
|
else {
|
|
columnConfig = [];
|
|
}
|
|
columnPreferenceDetailsId = columnConfig.length ? columnConfig[0].id : null;
|
|
ciRelationsModel.columnsConfig = _.merge(configurationModel.get('ciSearch.columns'), columns);
|
|
extendColumnConfig();
|
|
return ciRelationsModel.columnsConfig;
|
|
});
|
|
};
|
|
ciRelationsModel.updateColumnConfig = function (columnsConfig) {
|
|
userModel.updateUserPreferences(columnPreferenceGroup, {
|
|
id: columnPreferenceDetailsId,
|
|
name: 'columns',
|
|
value: columnsConfig
|
|
}).then(function (props) {
|
|
if (!columnPreferenceDetailsId) {
|
|
columnPreferenceDetailsId = props[0].id;
|
|
}
|
|
});
|
|
};
|
|
return ciRelationsModel;
|
|
}
|
|
]);
|
|
}());
|