560 lines
23 KiB
JavaScript
560 lines
23 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by igor.samulenko on 4/29/2014.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('adminModule').service('screenConfigurationService', ['$resource', '$q', '$http', function ($resource, $q, $http) {
|
|
var resource = $resource('/smartit/rest/customization', {}, {
|
|
loadConfiguration: {
|
|
url: '/smartit/rest/v2/customization/application/search?name=Galileo&phase=2',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
refreshMetadata: {
|
|
url: '/smartit/rest/customization/metadata/field/available/refresh',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
refreshMetadataV2: {
|
|
url: '/smartit/rest/v2/customization/metadata/field/available/refresh',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
loadAvailableFieldList: {
|
|
url: '/smartit/rest/customization/field/available/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadAvailableFieldListV2: {
|
|
url: '/smartit/rest/v2/customization/field/available/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadSelectedFieldList: {
|
|
url: '/smartit/rest/customization/field/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadActions: {
|
|
url: '/smartit/rest/action/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadActionsNew: {
|
|
url: '/smartit/rest/v3/action/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadActionUrlParams: {
|
|
url: '/smartit/rest/customization/action/search/urlparams',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadMockConfiguration: {
|
|
url: 'mocks/application-custom-field-configuration.json',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
loadMockAvailableFieldList: {
|
|
url: 'mocks/available-field-list.json',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadMockFieldList: {
|
|
url: 'mocks/custom-field-list.json',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
saveFieldConfiguration: {
|
|
url: '/smartit/rest/customization/cell/update',
|
|
method: 'POST'
|
|
},
|
|
saveFieldConfigurationV2: {
|
|
url: '/smartit/rest/v2/customization/cell/update',
|
|
method: 'POST'
|
|
},
|
|
saveActionConfiguration: {
|
|
url: '/smartit/rest/action',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
saveActionConfigurationV2: {
|
|
url: '/smartit/rest/action',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
loadFieldsLabels: {
|
|
url: '/smartit/rest/customization/field/summary/search',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
getAcceleratorsByType: {
|
|
url: '/smartit/rest/customization/available/accelerators',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
getNewAcceleratorsByType: {
|
|
url: '/smartit/rest/v2/customization/available/accelerators',
|
|
method: 'GET',
|
|
isArray: false
|
|
},
|
|
loadMockFieldLabels: {
|
|
url: 'mocks/custom-field-labels.json',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadMockActions: {
|
|
url: 'mocks/configuration-actions.json',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadMockActionUrlParams: {
|
|
url: 'mocks/configuration-action-url-params.json',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
loadMockDependantFieldMappings: {
|
|
url: 'mocks/custom-field-dependency-mappings.json',
|
|
method: 'GET'
|
|
},
|
|
loadDynamicSelectionFieldLabels: {
|
|
url: '/smartit/rest/v2/customization/menu/expand',
|
|
method: 'POST',
|
|
transformResponse: function (data) {
|
|
return { items: angular.fromJson(data) };
|
|
},
|
|
isArray: false
|
|
},
|
|
executeProviderAction: {
|
|
url: '/smartit/rest/action/execute',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
executeProviderActionV3: {
|
|
url: '/smartit/rest/v3/action/execute',
|
|
method: 'POST',
|
|
isArray: false
|
|
},
|
|
getSmartReporterUrl: {
|
|
url: '/smartit/rest/reporting/url',
|
|
//url: 'mocks/smart-reporter-url.json',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getExternalUrl: {
|
|
url: '/smartit/rest/external/url',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getTemplateList: {
|
|
url: '/smartit/rest/v3/action/templates',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getTemplateById: {
|
|
url: '/smartit/rest/v3/action/templates',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
createUrlAction: {
|
|
url: '/smartit/rest/v3/action',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
refreshServerCache: {
|
|
url: '/smartit/rest/system/provider/management/all/cache/reset',
|
|
method: 'DELETE',
|
|
isArray: false
|
|
}
|
|
});
|
|
/**
|
|
* Public functions
|
|
*/
|
|
/**
|
|
* Loads screen configuration
|
|
*
|
|
* @returns {*}
|
|
*/
|
|
this.loadConfiguration = function (params) {
|
|
return resource.loadConfiguration(params).$promise.then(function (result) {
|
|
return processAppConfiguration(result);
|
|
});
|
|
};
|
|
this.loadScreenConfigurationByName = function (screenName, options) {
|
|
var defaultParams = { screen: screenName };
|
|
return this.loadConfiguration(_.merge(defaultParams, options));
|
|
};
|
|
/**
|
|
* Refresh metadata
|
|
* @param {Object} params
|
|
* @returns {ng.IPromise<T>|ng.IPromise<ng.resource.IResourceArray<T>>|ng.IPromise<Array<T>>|$promise|*}
|
|
*/
|
|
this.refreshMetadata = function (params) {
|
|
return resource.refreshMetadata(params).$promise;
|
|
};
|
|
/**
|
|
* Refresh metadata V2 compatible screen
|
|
* @param {Object} params
|
|
* @returns {ng.IPromise<T>|ng.IPromise<ng.resource.IResourceArray<T>>|ng.IPromise<Array<T>>|$promise|*}
|
|
*/
|
|
this.refreshMetadataV2 = function (params) {
|
|
return resource.refreshMetadataV2(params).$promise;
|
|
};
|
|
/**
|
|
* Loads available field list
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadAvailableFieldList = function (params) {
|
|
return resource.loadAvailableFieldList(params).$promise.then(processFieldList);
|
|
};
|
|
/**
|
|
* Loads available field list with widgets and custom fields
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadAvailableFieldListV2 = function (params) {
|
|
return resource.loadAvailableFieldListV2(params).$promise.then(processFieldList);
|
|
};
|
|
/**
|
|
* Loads selected field list
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadSelectedFieldList = function (params) {
|
|
return resource.loadSelectedFieldList(params).$promise.then(processFieldList);
|
|
};
|
|
/**
|
|
* Loads Actions
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadActions = function (params) {
|
|
//return resource.loadMockActions(params).$promise.then(processActions);
|
|
return resource.loadActions(params).$promise.then(processActions);
|
|
};
|
|
/**
|
|
* Loads Actions for Runtime
|
|
* @returns {*}
|
|
*/
|
|
this.loadActionsForRuntime = function () {
|
|
return resource.loadActions().$promise.then(function (data) {
|
|
return data[0].items;
|
|
});
|
|
};
|
|
/**
|
|
* Loads Actions for Runtime
|
|
* @returns {*}
|
|
*/
|
|
this.loadActionsForRuntimeV2 = function () {
|
|
return resource.loadActionsNew().$promise.then(function (data) {
|
|
return data[0].items;
|
|
});
|
|
};
|
|
/**
|
|
* Loads Actions V2
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadActionsNew = function (params) {
|
|
//return resource.loadMockActions(params).$promise.then(processActions);
|
|
return resource.loadActionsNew(params).$promise.then(processActions);
|
|
};
|
|
/**
|
|
* Loads Accelerators
|
|
*
|
|
* @param {Object} params map
|
|
* @returns {*}
|
|
*/
|
|
this.getAcceleratorsByType = function (params) {
|
|
return resource.getAcceleratorsByType(params).$promise.then(function (data) {
|
|
return data.items;
|
|
});
|
|
};
|
|
/**
|
|
* Loads Accelerators V2
|
|
*
|
|
* @param {Object} params map
|
|
* @returns {*}
|
|
*/
|
|
this.getNewAcceleratorsByType = function (params) {
|
|
return resource.getNewAcceleratorsByType(params).$promise.then(function (data) {
|
|
return data.items;
|
|
});
|
|
};
|
|
/**
|
|
* Loads Actions
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadActionUrlParams = function (params) {
|
|
//return resource.loadMockActionUrlParams(params).$promise.then(processActionUrlParams);
|
|
return resource.loadActionUrlParams(params).$promise.then(processActionUrlParams);
|
|
};
|
|
/**
|
|
* Loads labels for custom fields
|
|
*
|
|
* @param {Object} params
|
|
* @returns {*}
|
|
*/
|
|
this.loadFieldsLabels = function (params) {
|
|
return resource.loadFieldsLabels(params).$promise;
|
|
};
|
|
/**
|
|
* Saves custom fields configuration
|
|
*
|
|
* @param {Array} fieldList - array of fields with information on their state
|
|
* @returns {*}
|
|
*/
|
|
this.saveFieldConfiguration = function (fieldList, shortId) {
|
|
var params = {};
|
|
if (shortId === 'typeSpecific') {
|
|
params.assetType = shortId;
|
|
}
|
|
return resource.saveFieldConfiguration(params, fieldList).$promise;
|
|
};
|
|
/**
|
|
* Saves custom fields configuration using v2 request
|
|
*
|
|
* @param {Array} fieldList - array of fields with information on their state
|
|
* @returns {*}
|
|
*/
|
|
this.saveFieldConfigurationV2 = function (fieldList, shortId) {
|
|
var params = {};
|
|
if (shortId === 'typeSpecific') {
|
|
params.assetType = shortId;
|
|
}
|
|
return resource.saveFieldConfigurationV2(params, fieldList).$promise;
|
|
};
|
|
/**
|
|
* Saves action configuration
|
|
*
|
|
* @param {object} with actionList array and actionOrder
|
|
* @returns {*}
|
|
*/
|
|
this.saveActionConfiguration = function (actionObj) {
|
|
return resource.saveActionConfiguration({}, actionObj).$promise.then(processActions);
|
|
};
|
|
/**
|
|
* Saves action configuration V2
|
|
*
|
|
* @param {object} with actionList array and actionOrder
|
|
* @returns {*}
|
|
*/
|
|
this.saveActionConfigurationV2 = function (actionObj) {
|
|
return resource.saveActionConfigurationV2({}, actionObj).$promise.then(processActions);
|
|
};
|
|
this.loadMockDependantFieldMappings = function () {
|
|
return resource.loadMockDependantFieldMappings().$promise;
|
|
};
|
|
/**
|
|
* Loads labels for dynamic selection custom field
|
|
*
|
|
* @param {Object} params
|
|
* @param {Object} data
|
|
* @returns {*}
|
|
*/
|
|
this.loadDynamicSelectionFieldLabels = function (params, data) {
|
|
return resource.loadDynamicSelectionFieldLabels(params, data).$promise.then(function (result) {
|
|
var items = _.isArray(result.items) && result.items[0].items ? result.items[0].items : result.items;
|
|
var menuOptions = prepareHierarchicalMenuOptions(items);
|
|
return { items: menuOptions, exceedsChunkSize: result.items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
function prepareHierarchicalMenuOptions(hierarchicalMenu) {
|
|
var resultFlattedQMO = [];
|
|
function flatQMO(menu, prevParent) {
|
|
_.forEach(menu, function (option) {
|
|
if (option.subMenu && option.subMenu.length) {
|
|
option.parent = prevParent && prevParent.length ? prevParent.concat([option.label]) : [option.label];
|
|
flatQMO(option.subMenu, option.parent);
|
|
}
|
|
else {
|
|
if (prevParent) {
|
|
option.parent = prevParent.slice(0);
|
|
}
|
|
resultFlattedQMO.push(option);
|
|
}
|
|
});
|
|
}
|
|
flatQMO(hierarchicalMenu);
|
|
return _.forEach(resultFlattedQMO, function (QMO) {
|
|
QMO.displayLabel = (QMO.parent && QMO.parent.length) ? (QMO.parent.join(' > ') + ' > ' + QMO.label) : QMO.label;
|
|
});
|
|
}
|
|
this.executeProviderAction = function (actionId, resourceId) {
|
|
var params = {
|
|
actionId: actionId,
|
|
resourceId: resourceId
|
|
};
|
|
return resource.executeProviderAction(params).$promise;
|
|
};
|
|
this.executeProviderActionV3 = function (actionId, resourceId, parameters) {
|
|
var params = {
|
|
actionId: actionId,
|
|
resourceId: resourceId,
|
|
parameters: parameters
|
|
};
|
|
return resource.executeProviderActionV3(params).$promise.then(function (data) {
|
|
delete data.actionId; // Fix for no response appends params data SW00536634
|
|
delete data.resourceId;
|
|
delete data.parameters;
|
|
return JSON.parse(angular.toJson(data));
|
|
});
|
|
};
|
|
/**
|
|
* Get absolute path of fieldName from metadata and use it to get field value from context
|
|
*
|
|
* @param {Object} context
|
|
* @param {Object} metadata
|
|
* @param fieldName
|
|
* @returns {String} value
|
|
*/
|
|
this.getContextPropertyByMetadataMapping = function (context, metadata, fieldName, isCreate) {
|
|
var value, mappings = metadata.ootbMapping[fieldName];
|
|
if (mappings && mappings.length) {
|
|
for (var i = 0, l = mappings.length; i < l; i++) {
|
|
var pathList = mappings[i].split('.');
|
|
if (pathList[0] === 'resCategorizations' || pathList[0] === 'categorizations') {
|
|
for (var index in context.allCategories) {
|
|
if (context.allCategories.hasOwnProperty(index)) {
|
|
var valueObject = _.find(context.allCategories[index].listOfTiers, { name: pathList[pathList.length - 1] });
|
|
if (valueObject) {
|
|
value = valueObject.selectedValue;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (isCreate && (context.type === EntityVO.TYPE_PROBLEM || context.type === EntityVO.TYPE_KNOWNERROR)
|
|
&& _.includes([EntityVO.TYPE_PRIORITY, EntityVO.TYPE_URGENCY, EntityVO.TYPE_IMPACT, EntityVO.TYPE_STATUS], mappings[i])) {
|
|
switch (mappings[i]) {
|
|
case EntityVO.TYPE_PRIORITY:
|
|
value = _.get(context, EntityVO.TYPE_CALCULATED_PRIORITY, '');
|
|
break;
|
|
case EntityVO.TYPE_URGENCY:
|
|
value = _.get(context, EntityVO.TYPE_SELECTED_URGENCY, '');
|
|
break;
|
|
case EntityVO.TYPE_IMPACT:
|
|
value = _.get(context, EntityVO.TYPE_SELECTED_IMPACT, '');
|
|
break;
|
|
case EntityVO.TYPE_STATUS:
|
|
value = _.get(context, EntityVO.TYPE_SELECTED_STATUS, '');
|
|
break;
|
|
default:
|
|
value = _.get(context, mappings[i], '');
|
|
break;
|
|
}
|
|
if (_.isObject(value)) {
|
|
value = value.name;
|
|
}
|
|
}
|
|
else {
|
|
value = _.get(context, mappings[i], '');
|
|
}
|
|
if (angular.isDefined(value) && !(_.isObject(value))) {
|
|
break;
|
|
}
|
|
else {
|
|
value = '';
|
|
}
|
|
}
|
|
}
|
|
return value;
|
|
};
|
|
this.getSmartReporterUrl = function () {
|
|
return resource.getSmartReporterUrl().$promise.then(function (data) {
|
|
return data[0].items[0].reportingServerURL;
|
|
});
|
|
};
|
|
this.getExternalUrl = function () {
|
|
return resource.getExternalUrl().$promise.then(function (data) {
|
|
return data[0].items[0];
|
|
});
|
|
};
|
|
this.getTemplateList = function (params) {
|
|
return resource.getTemplateList(params).$promise.then(function (data) {
|
|
return data;
|
|
});
|
|
};
|
|
this.getTemplateById = function (params) {
|
|
return resource.getTemplateById(params).$promise.then(function (data) {
|
|
return data[0];
|
|
});
|
|
};
|
|
/**
|
|
* Create URL Action
|
|
*
|
|
* @param {object} with actionList array and actionOrder
|
|
* @returns {*}
|
|
*/
|
|
this.createUrlAction = function (actionObj) {
|
|
return resource.createUrlAction({}, actionObj).$promise.then(processActions);
|
|
};
|
|
this.refreshServerCache = function () {
|
|
return resource.refreshServerCache().$promise;
|
|
};
|
|
/**
|
|
* Private functions
|
|
*/
|
|
/**
|
|
* Process app config data from server
|
|
*
|
|
* @param {Object} data
|
|
* @returns {ApplicationConfigurationVO} app config
|
|
*/
|
|
function processAppConfiguration(data) {
|
|
return new ApplicationConfigurationVO().build(data);
|
|
}
|
|
/**
|
|
* Process field list data from server
|
|
*
|
|
* @param {Array} data
|
|
* @returns {Array} field list
|
|
*/
|
|
function processFieldList(data) {
|
|
return data.map(function (item) {
|
|
return new FieldVO().build(item);
|
|
});
|
|
}
|
|
/**
|
|
* Process Action list data from server
|
|
*
|
|
* @param {Array} Object
|
|
* @returns {Object} Object with action vo
|
|
*/
|
|
function processActions(data) {
|
|
var actionListObj = [];
|
|
if (data[0].items[0].actionList) {
|
|
actionListObj = data[0].items[0].actionList.map(function (item) {
|
|
return new ActionVO().build(item);
|
|
});
|
|
}
|
|
var newData = {
|
|
actionList: actionListObj,
|
|
actionOrder: data[0].items[0].actionOrder || 'alphabetical'
|
|
};
|
|
return newData;
|
|
}
|
|
/**
|
|
* Process Action url params data from server
|
|
*
|
|
* @param {Array} url params
|
|
* @returns {Array} url params
|
|
*/
|
|
function processActionUrlParams(data) {
|
|
data.forEach(function (item) {
|
|
item.name = '[' + item.name + ']';
|
|
});
|
|
return data;
|
|
}
|
|
}]);
|
|
})();
|