135 lines
7.3 KiB
JavaScript
135 lines
7.3 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.service('relationService', ['$resource', '$http', 'systemAlertService', '$q',
|
|
function ($resource, $http, systemAlertService, $q) {
|
|
var resource = $resource('/smartit/rest/relations/:type/:id', {}, {
|
|
getRelations: {
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
bulkAddRelation: {
|
|
url: '/smartit/rest/bulkupdate/relations/bulk',
|
|
method: 'POST',
|
|
transformResponse: function (data) {
|
|
return { results: angular.fromJson(data) };
|
|
}
|
|
},
|
|
bulkAddRelationHKM: {
|
|
url: '/smartit/rest/knowledge/pin',
|
|
method: 'POST',
|
|
transformResponse: function (data) {
|
|
return { results: angular.fromJson(data) };
|
|
}
|
|
},
|
|
deleteActivity: {
|
|
url: '/smartit/rest/activity/:id',
|
|
method: 'DELETE',
|
|
isArray: false
|
|
},
|
|
relateBulkCI: {
|
|
url: '/smartit/rest/:type/relateBulkCI/:id',
|
|
method: 'POST',
|
|
isArray: false
|
|
},
|
|
updateTaskSequence: {
|
|
url: '/smartit/rest/task/updatesequence',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
updateReleasePlanItemsSequence: {
|
|
url: '/smartit/rest/release/updatesequence',
|
|
method: 'POST',
|
|
isArray: true
|
|
}
|
|
});
|
|
this.getRelations = function (id, type, params) {
|
|
params = params || {};
|
|
params.id = id;
|
|
params.type = type;
|
|
return resource.getRelations(params).$promise.then(function (result) {
|
|
var relatedItems = result[0].items[0] && result[0].items[0].objects;
|
|
if (relatedItems) {
|
|
return _.map(relatedItems, function (item) {
|
|
return new RelationItemVO().build(item);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
this.bulkAddRelation = function (params) {
|
|
return resource.bulkAddRelation(params).$promise.then(function (responce) {
|
|
return _.forEach(responce.results, function (responseElement, key) {
|
|
responce.results[key] = {
|
|
relations: _.map(responseElement.objects, function (relation) {
|
|
return new RelationItemVO().build(relation);
|
|
}),
|
|
status: responseElement.statusInfoList[0]
|
|
};
|
|
});
|
|
});
|
|
};
|
|
this.bulkAddRelationHKM = function (params) {
|
|
return resource.bulkAddRelationHKM(params).$promise.then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
this.relateBulkCI = function (ticket, relation, searchCriteria) {
|
|
var params = { id: ticket.id, type: ticket.type }, relationsInfoDefault = { relationshipType: '', tag: '', type: '' }, request = { relationship: {}, searchCriteria: searchCriteria };
|
|
if (params.type === EntityVO.TYPE_CHANGE) {
|
|
params.source = "cisearchv2";
|
|
}
|
|
_.forEach(relationsInfoDefault, function (item, key) {
|
|
request.relationship[key] = relation[key];
|
|
});
|
|
return resource.relateBulkCI(params, request).$promise;
|
|
};
|
|
this.removeRelation = function (parent, relation) {
|
|
return $http({
|
|
method: 'DELETE',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
url: '/smartit/rest/relations/' + parent.parentType + '/' + parent.parentId,
|
|
data: relation
|
|
})
|
|
.catch(function (error) {
|
|
systemAlertService.error({
|
|
text: error.data.errorCode ? $filter('i18n')('error.unknown') : (error.data.error || error.data.results.error),
|
|
clear: false
|
|
});
|
|
return $q.reject(err);
|
|
});
|
|
};
|
|
this.deleteActivity = function (ticket) {
|
|
var params = { id: ticket.id };
|
|
return resource.deleteActivity(params).$promise;
|
|
};
|
|
this.getRelatedTasks = function (relations) {
|
|
return _.filter(relations, { type: EntityVO.TYPE_TASK });
|
|
};
|
|
this.getRelatedLinkedItems = function (relations, context, showAffectedServiceRelation) {
|
|
// showAffectedServiceRelation :: Configuration parameter to show or hide business service related item
|
|
//SW00554046 - for CRQ show/hide service relations only in CI tab and always hide in relation tab.
|
|
showAffectedServiceRelation = (context && EntityVO.TYPE_CHANGE === context.type) ? false : showAffectedServiceRelation;
|
|
return _.chain(relations)
|
|
.filter({ tag: RelationItemVO.TAG_LINKEDITEM })
|
|
.reject(function (linkedItem) {
|
|
var affectedAssetServiceConditions = !showAffectedServiceRelation && context && context.type && _.includes([context.causalCI && context.causalCI.reconciliationId, context.impactedService && context.impactedService.reconciliationId], linkedItem.id), incidentConditions = affectedAssetServiceConditions && context.type === EntityVO.TYPE_INCIDENT, changeConditions = !showAffectedServiceRelation && context && context.type && EntityVO.TYPE_CHANGE === context.type && linkedItem.type === EntityVO.TYPE_ASSET, workOrderConditions = !showAffectedServiceRelation && context && context.type && context.type === EntityVO.TYPE_WORKORDER && _.includes([context.impactedService && context.impactedService.reconciliationId], linkedItem.id), problemKnownErrorConditions = affectedAssetServiceConditions && (context.type === EntityVO.TYPE_PROBLEM || context.type === EntityVO.TYPE_KNOWNERROR), releaseConditions = affectedAssetServiceConditions && context.type === EntityVO.TYPE_RELEASE;
|
|
return incidentConditions || changeConditions || workOrderConditions || problemKnownErrorConditions || releaseConditions;
|
|
}).value();
|
|
};
|
|
this.getRelatedCIs = function (relations) {
|
|
return _.filter(relations, { type: EntityVO.TYPE_ASSET });
|
|
};
|
|
this.updateTaskSequence = function (params) {
|
|
return resource.updateTaskSequence(params).$promise.then(function (response) {
|
|
return response[0].items;
|
|
});
|
|
};
|
|
this.updateReleasePlanItemsSequence = function (params) {
|
|
return resource.updateReleasePlanItemsSequence(params).$promise.then(function (response) {
|
|
return response[0].items;
|
|
});
|
|
};
|
|
}]);
|
|
}());
|