145 lines
6.5 KiB
JavaScript
145 lines
6.5 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by ygowtham on 6/16/2015.
|
|
* Added all necessary code for Collision Banner (I1 - G1.3)
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('changeModule')
|
|
.service('collisionService', ['$resource', '$q',
|
|
function ($resource, $q) {
|
|
var resource = $resource('', {}, {
|
|
getCollision: {
|
|
url: '/smartit/rest/change/collisions/get',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
getListOfCollisionsAndCiByDate: {
|
|
url: '/smartit/rest/change/collisions/get',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
getListOfCalendarItems: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/calendar/get'
|
|
},
|
|
addCollisionStatuses: {
|
|
method: 'PUT',
|
|
isArray: true,
|
|
url: '/smartit/rest/change/:id/collisions'
|
|
}
|
|
});
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionService#getListOfCollisionsById
|
|
* @methodOf myitsmApp.ticketService
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the context
|
|
* @param {Object} param - Object that has information about the ticket required in the request API.
|
|
* @param {String} param.id|parentId - UUID of the ticket
|
|
* @param {String} param.type|parentType - Ticket type value
|
|
* @param {boolean} param.includeCIDetails|includeCIDetails - Flag to include CI Details in response or not.
|
|
*/
|
|
this.getListOfCollisionsById = function (params) {
|
|
var reqParams;
|
|
if (params.id) {
|
|
reqParams = { id: params.id, includeCIDetails: params.includeCIDetails };
|
|
}
|
|
else if (!params.parentId) {
|
|
return $q.when({ error: 'Missing required parameter. Request cancelled' });
|
|
}
|
|
else {
|
|
reqParams = params;
|
|
}
|
|
return resource.getCollision(reqParams).$promise
|
|
.then(function (response) {
|
|
return handleCollisionData(response[0], params.includeCIDetails);
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionService#getListOfCollisionsAndCiByDate
|
|
* @methodOf myitsmApp.ticketService
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the context
|
|
* @param {Object} params - Object that has information about the ticket required in the request API.
|
|
*/
|
|
this.getListOfCollisionsAndCiByDate = function (params) {
|
|
return resource.getListOfCollisionsAndCiByDate(params).$promise
|
|
.then(function (response) {
|
|
return handleCollisionData(response[0], true);
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionService#getListOfCollisionsByDate
|
|
* @methodOf myitsmApp.ticketService
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the context
|
|
* @param {Object} params - Object that has information about the ticket required in the request API.
|
|
*/
|
|
this.getListOfCollisionsByDate = function (params) {
|
|
return resource.getListOfCalendarItems(params).$promise;
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionService#getListOfCollisionsByDate
|
|
* @methodOf myitsmApp.ticketService
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the context
|
|
* @param {Object} params - Object that has information about the ticket required in the request API.
|
|
*/
|
|
this.addCollisionStatuses = function (params, id) {
|
|
return resource.addCollisionStatuses({ id: id }, params).$promise.then(function (response) {
|
|
return handleCollisionData(response[0], true);
|
|
});
|
|
};
|
|
function handleCollisionData(data, includeCIDetails) {
|
|
var collisionData = {
|
|
count: data.items[0].totalMatches,
|
|
changeList: [],
|
|
totalUnaddressedCount: 0
|
|
};
|
|
collisionData.changeList = data.items[0].objects;
|
|
collisionData.changeList.forEach(function (object) {
|
|
if (object.additionalInformation) {
|
|
if (new Date(object.additionalInformation.scheduledStartDate).getDay() === 0 ||
|
|
new Date(object.additionalInformation.scheduledEndDate).getDay() === 6) {
|
|
object.fallsOnWeekend = true;
|
|
}
|
|
}
|
|
else {
|
|
object.fallsOnWeekend = false;
|
|
}
|
|
if (includeCIDetails) {
|
|
object.ciCount = 0;
|
|
for (var i = 0; i < object.configurationItems.length; i++) {
|
|
if (object.configurationItems[i].collisionStatus) {
|
|
object.configurationItems[i].status = {
|
|
name: object.configurationItems[i].collisionStatus.value
|
|
};
|
|
object.configurationItems[i].rationale = object.configurationItems[i].collisionStatus.reason;
|
|
if (object.configurationItems[i].collisionStatus.value !== 'Resolved' && object.configurationItems[i].collisionStatus.value !== 'Ignored') {
|
|
object.ciCount = object.ciCount + 1;
|
|
}
|
|
}
|
|
else {
|
|
object.ciCount += 1;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
object.ciCount = object.hasActiveCollisions ? 1 : 0;
|
|
}
|
|
collisionData.totalUnaddressedCount += object.ciCount;
|
|
});
|
|
return collisionData;
|
|
}
|
|
}]);
|
|
}());
|