341 lines
14 KiB
JavaScript
341 lines
14 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('createTicketModule')
|
|
.service('createTicketService', ['$resource', '$http', 'systemAlertService', '$q',
|
|
function ($resource, $http, systemAlertService, $q) {
|
|
var personResource = $resource('/smartit/rest/person/search', {}, {
|
|
getListOfPersons: { method: 'GET', isArray: true },
|
|
getListOfSites: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: '/smartit/rest/foundation/search/site'
|
|
},
|
|
getListOfItems: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: '/smartit/rest/foundation/items'
|
|
},
|
|
getListOfRiskQuestions: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/change/riskquestions/get'
|
|
}
|
|
}), assetResource = $resource('/smartit/rest/asset/search', {}, {
|
|
getListOfAssets: { method: 'GET', isArray: true }
|
|
}), createTicketResource = $resource('', {}, {
|
|
createIncident: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/v2/incident'
|
|
},
|
|
createTask: {
|
|
method: 'POST',
|
|
isArray: false,
|
|
url: '/smartit/rest/task'
|
|
},
|
|
createWorkOrder: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/workorder'
|
|
},
|
|
createBroadcast: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/broadcast'
|
|
},
|
|
createOutage: {
|
|
method: 'POST',
|
|
isArray: false,
|
|
url: '/smartit/rest/outage'
|
|
},
|
|
createChangeRequest: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/v2/change',
|
|
headers: { 'Content-Type': undefined },
|
|
transformRequest: function (changeData) {
|
|
var formData = new FormData(), count, length;
|
|
formData.append('text', JSON.stringify(changeData));
|
|
if (changeData.attachments && changeData.attachments.length > 0) {
|
|
if (changeData.attachments.length === 1) {
|
|
formData.append('file', changeData.attachments[0].file);
|
|
}
|
|
else {
|
|
for (count = 0, length = changeData.attachments.length; count < length; count++) {
|
|
formData.append('file[]', changeData.attachments[count].file);
|
|
}
|
|
}
|
|
}
|
|
return formData;
|
|
}
|
|
},
|
|
createRelease: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/release'
|
|
},
|
|
createActivity: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/activity'
|
|
},
|
|
createProblem: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/problem'
|
|
},
|
|
createKnownError: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/knownerror'
|
|
},
|
|
saveRiskResponse: {
|
|
method: 'POST',
|
|
isArray: false,
|
|
url: '/smartit/rest/change/riskresponse/:id'
|
|
},
|
|
saveImpactedAreas: {
|
|
method: 'POST',
|
|
isArray: false,
|
|
url: '/smartit/rest/impactedarea/:type/:id'
|
|
},
|
|
createOutageBulk: {
|
|
method: 'POST',
|
|
isArray: false,
|
|
url: '/smartit/rest/outage/bulk'
|
|
},
|
|
createImpactAnalysis: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/asset/impactjob/:type/:id'
|
|
},
|
|
createAsset: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/asset'
|
|
}
|
|
});
|
|
this.getListOfPersons = function (term, hideBlankEmail) {
|
|
var params = { name: term, thumbnail: true };
|
|
if (hideBlankEmail) {
|
|
params.hideBlankEmail = hideBlankEmail;
|
|
}
|
|
return personResource.getListOfPersons(params).$promise;
|
|
};
|
|
this.getListOfPersonsByCompany = function (term, companyName) {
|
|
return personResource.getListOfPersons({ name: term, thumbnail: true, companyName: companyName }).$promise;
|
|
};
|
|
this.getListOfAssets = function (term, companyName, ticketType, customerId) {
|
|
var getListParams = { searchParam: term, company: { name: companyName }, thumbnail: true };
|
|
if (ticketType === EntityVO.TYPE_INCIDENT) {
|
|
getListParams.customerId = customerId;
|
|
getListParams.ticket = ticketType;
|
|
getListParams.affected = true;
|
|
}
|
|
if (ticketType === EntityVO.TYPE_PROBLEM || ticketType === EntityVO.TYPE_KNOWNERROR) {
|
|
getListParams.affected = true;
|
|
}
|
|
return assetResource.getListOfAssets(getListParams).$promise;
|
|
};
|
|
this.getListOfAssetsByType = function (term, assetType, companyName, ticketType, customerId) {
|
|
var getListParams = { searchParam: term, assetType: assetType, company: { name: companyName }, thumbnail: true };
|
|
if (ticketType === EntityVO.TYPE_INCIDENT) {
|
|
getListParams.customerId = customerId;
|
|
getListParams.ticket = ticketType;
|
|
getListParams.affected = true;
|
|
}
|
|
return assetResource.getListOfAssets(getListParams).$promise;
|
|
};
|
|
this.createIncident = function (params) {
|
|
return createTicketResource.createIncident(params).$promise.then(function (result) {
|
|
return new IncidentVO().build(result[0].items[0]);
|
|
});
|
|
};
|
|
this.createTask = function (filters, params) {
|
|
return createTicketResource.createTask(filters, params).$promise;
|
|
};
|
|
this.createWorkOrder = function (params) {
|
|
return createTicketResource.createWorkOrder(params).$promise.then(function (result) {
|
|
return new WorkOrderVO().build(result[0].items[0]);
|
|
});
|
|
};
|
|
this.createBroadcast = function (params) {
|
|
return createTicketResource.createBroadcast(params).$promise;
|
|
};
|
|
this.createChangeRequest = function (params) {
|
|
return createTicketResource.createChangeRequest(params).$promise;
|
|
};
|
|
this.createRelease = function (params) {
|
|
return createTicketResource.createRelease(params).$promise;
|
|
};
|
|
this.createActivity = function (params) {
|
|
return createTicketResource.createActivity(params).$promise;
|
|
};
|
|
this.createProblem = function (params) {
|
|
return createTicketResource.createProblem(params).$promise.then(function (result) {
|
|
return new ProblemVO().build(result[0].items[0]);
|
|
});
|
|
};
|
|
this.createKnownError = function (params) {
|
|
return createTicketResource.createKnownError(params).$promise.then(function (result) {
|
|
return new KnownErrorVO().build(result[0].items[0]);
|
|
});
|
|
};
|
|
this.createImpactAnalysis = function (id, type, params) {
|
|
return createTicketResource.createImpactAnalysis({ id: id, type: type }, params).$promise;
|
|
};
|
|
this.saveRiskResponse = function (id, params) {
|
|
return createTicketResource.saveRiskResponse({ id: id }, params).$promise;
|
|
};
|
|
this.saveImpactedAreas = function (id, type, params) {
|
|
return createTicketResource.saveImpactedAreas({ id: id, type: type }, params).$promise;
|
|
};
|
|
this.deleteImpactedAreas = function (id, params) {
|
|
return $http({
|
|
method: 'DELETE',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
url: '/smartit/rest/change/impactedAreas/' + id,
|
|
data: params
|
|
})
|
|
.catch(function (err) {
|
|
systemAlertService.error({
|
|
text: err.data.error,
|
|
clear: false
|
|
});
|
|
return $q.reject(err);
|
|
});
|
|
};
|
|
this.getListOfSites = function (term) {
|
|
return personResource.getListOfSites({ searchText: term }).$promise;
|
|
};
|
|
this.getListOfCompanies = function (term) {
|
|
var request = { type: 'company' };
|
|
if (term) {
|
|
request.term = { searchText: term };
|
|
}
|
|
return personResource.getListOfItems(request).$promise;
|
|
};
|
|
this.getListOfOrganizations = function (terms) {
|
|
var params = {
|
|
type: 'organization',
|
|
searchOptions: terms
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfDepartments = function (terms) {
|
|
var params = {
|
|
type: 'department',
|
|
searchOptions: terms
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfRegions = function (terms) {
|
|
var params = {
|
|
type: 'region',
|
|
searchOptions: terms
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfSiteGroups = function (terms) {
|
|
var params = {
|
|
type: 'siteGroup',
|
|
searchOptions: terms
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfSites = function (terms) {
|
|
var params = {
|
|
type: 'site',
|
|
searchOptions: terms
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfRegionsByName = function (terms, searchText) {
|
|
var params = {
|
|
type: 'region',
|
|
searchOptions: terms,
|
|
searchText: searchText
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfSiteGroupsByName = function (terms, searchText) {
|
|
var params = {
|
|
type: 'siteGroup',
|
|
searchOptions: terms,
|
|
searchText: searchText
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfSitesByName = function (terms, searchText) {
|
|
var params = {
|
|
type: 'site',
|
|
searchOptions: terms,
|
|
searchText: searchText
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfOrganizationsByName = function (terms, searchText) {
|
|
var params = {
|
|
type: 'organization',
|
|
searchOptions: terms,
|
|
searchText: searchText
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfDepartmentsByName = function (terms, searchText) {
|
|
var params = {
|
|
type: 'department',
|
|
searchOptions: terms,
|
|
searchText: searchText
|
|
};
|
|
if (terms.chunkInfo) {
|
|
params.chunkInfo = terms.chunkInfo;
|
|
}
|
|
return personResource.getListOfItems(params).$promise;
|
|
};
|
|
this.getListOfRiskQuestions = function (params) {
|
|
return personResource.getListOfRiskQuestions(params).$promise;
|
|
};
|
|
this.createOutage = function (params) {
|
|
return createTicketResource.createOutage(params).$promise;
|
|
};
|
|
this.createOutageBulk = function (params) {
|
|
return createTicketResource.createOutageBulk(params).$promise;
|
|
};
|
|
this.createAsset = function (params) {
|
|
return createTicketResource.createAsset(params).$promise.then(function (result) {
|
|
return result[0].items[0];
|
|
});
|
|
};
|
|
}
|
|
]);
|
|
}());
|