1616 lines
81 KiB
JavaScript
1616 lines
81 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('createTicketModule')
|
|
.factory('createTicketModel', ['createTicketService', '$state', 'filterFilter', 'ticketTemplateService', 'attachmentService', '$q', 'ticketService', 'locationModel', 'searchModel', 'ticketModel', 'feedModel', 'userModel', 'systemAlertService', 'objectValueMapperService',
|
|
function (createTicketService, $state, filterFilter, ticketTemplateService, attachmentService, $q, ticketService, locationModel, searchModel, ticketModel, feedModel, userModel, systemAlertService, objectValueMapperService) {
|
|
var self = {};
|
|
self.currentTicket = {};
|
|
self.listCache = {};
|
|
// TODO: optimize this
|
|
self.getList = function (type, term, ticketType, customerId) {
|
|
var resources = [
|
|
{
|
|
run: function () {
|
|
return createTicketService.getListOfPersons(term).then(function (response) {
|
|
return response[0];
|
|
});
|
|
},
|
|
condition: type === 'person'
|
|
},
|
|
{
|
|
run: function () {
|
|
var companyName = self.currentTicket.selectedCompany ? self.currentTicket.selectedCompany.name : self.currentTicket.company.name;
|
|
return createTicketService.getListOfAssets(term, companyName, ticketType, customerId).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
},
|
|
condition: type === 'asset'
|
|
},
|
|
{
|
|
run: function () {
|
|
var assetType = 'Business Service', companyName = self.currentTicket.selectedCompany ? self.currentTicket.selectedCompany.name : self.currentTicket.company.name;
|
|
return createTicketService.getListOfAssetsByType(term, assetType, companyName, ticketType, customerId).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
},
|
|
condition: type === 'service'
|
|
},
|
|
{
|
|
run: function () {
|
|
var companyName = self.currentTicket.selectedCompany.name;
|
|
return ticketTemplateService.getIncidentTemplateList(term, companyName).then(function (response) {
|
|
return { exceedsChunkSize: response.exceedsChunkSize, list: response.objects };
|
|
});
|
|
},
|
|
condition: type === 'incidentTemplate'
|
|
},
|
|
{
|
|
run: function () {
|
|
var companyName = self.currentTicket.selectedCompany ? self.currentTicket.selectedCompany.name : self.currentTicket.company.name;
|
|
return ticketTemplateService.getTaskTemplateList(term, companyName).then(function (response) {
|
|
if (term) {
|
|
/* return single tasks only */
|
|
return { exceedsChunkSize: response[0].items[0].exceedsChunkSize, list: filterFilter(response[0].items[0].objects, { type: 'Single Tasks' }) };
|
|
}
|
|
else {
|
|
return response[0].items[0].objects;
|
|
}
|
|
});
|
|
},
|
|
condition: type === 'taskTemplate'
|
|
},
|
|
{
|
|
run: function () {
|
|
var companyName = (self.currentTicket.selectedCompany && self.currentTicket.selectedCompany.name) ? self.currentTicket.selectedCompany.name : (_.isString(self.currentTicket.selectedCompany) ? self.currentTicket.selectedCompany : '');
|
|
return ticketTemplateService.getWorkorderTemplateList(term, companyName).then(function (response) {
|
|
return { exceedsChunkSize: response.exceedsChunkSize, list: response.objects };
|
|
});
|
|
},
|
|
condition: type === 'workorderTemplate'
|
|
},
|
|
{
|
|
run: function () {
|
|
var companyPromise = searchModel.getCompaniesByText(term), sitePromise = searchModel.getFoundationSitesObjectByText(term);
|
|
return $q.all([companyPromise, sitePromise]).then(function (responses) {
|
|
return {
|
|
exceedsChunkSize: responses[0].exceedsChunkSize || responses[1].exceedsChunkSize,
|
|
list: responses[0].companies.concat(responses[1].foundationItems)
|
|
};
|
|
});
|
|
},
|
|
condition: type === 'broadcastAudience'
|
|
},
|
|
{
|
|
run: function () {
|
|
var cacheKey = 'organization:' + term.companyName;
|
|
return self.listCache[cacheKey]
|
|
? $q.when(self.listCache[cacheKey])
|
|
: createTicketService.getListOfOrganizations(term).then(function (responses) {
|
|
var result = responses[0].items[0];
|
|
self.listCache[cacheKey] = result;
|
|
return result;
|
|
});
|
|
},
|
|
condition: type === 'organization'
|
|
},
|
|
{
|
|
run: function () {
|
|
var cacheKey = 'department:' + term.companyName + ':' + term.organizationName;
|
|
return self.listCache[cacheKey]
|
|
? $q.when(self.listCache[cacheKey])
|
|
: createTicketService.getListOfDepartments(term).then(function (responses) {
|
|
var result = responses[0].items[0];
|
|
self.listCache[cacheKey] = result;
|
|
return result;
|
|
});
|
|
},
|
|
condition: type === 'department'
|
|
},
|
|
{
|
|
run: function () {
|
|
var cacheKey = 'region:' + term.companyName;
|
|
return self.listCache[cacheKey]
|
|
? $q.when(self.listCache[cacheKey])
|
|
: createTicketService.getListOfRegions(term).then(function (responses) {
|
|
var result = responses[0].items[0];
|
|
self.listCache[cacheKey] = result;
|
|
return result;
|
|
});
|
|
},
|
|
condition: type === 'region'
|
|
},
|
|
{
|
|
run: function () {
|
|
var cacheKey = 'sitegroup:' + term.companyName + ':' + term.regionName;
|
|
return self.listCache[cacheKey]
|
|
? $q.when(self.listCache[cacheKey])
|
|
: createTicketService.getListOfSiteGroups(term).then(function (responses) {
|
|
var result = responses[0].items[0];
|
|
self.listCache[cacheKey] = result;
|
|
return result;
|
|
});
|
|
},
|
|
condition: type === 'sitegroup'
|
|
},
|
|
{
|
|
run: function () {
|
|
var cacheKey = 'site:' + term.companyName + ':' + term.regionName;
|
|
if (term.siteGroupName) {
|
|
cacheKey += ':' + term.siteGroupName;
|
|
}
|
|
return self.listCache[cacheKey]
|
|
? $q.when(self.listCache[cacheKey])
|
|
: createTicketService.getListOfSites(term).then(function (responses) {
|
|
var result = responses[0].items[0];
|
|
self.listCache[cacheKey] = result;
|
|
return result;
|
|
});
|
|
},
|
|
condition: type === 'site'
|
|
},
|
|
{
|
|
run: function () {
|
|
//console.log("Search term",term);
|
|
return locationModel.filterLocations(term).then(function (locations) {
|
|
return locations;
|
|
});
|
|
},
|
|
condition: type === 'workorderLocation'
|
|
},
|
|
{
|
|
run: function () {
|
|
return locationModel.filterLocationPOI(term.location, term.searchText).then(function (poiList) {
|
|
return poiList;
|
|
});
|
|
},
|
|
condition: type === 'workorderPOI'
|
|
},
|
|
{
|
|
run: function () {
|
|
var selectedGroupId = self.currentTicket.selectedManagerGroup.id;
|
|
return ticketService.getGroupMembers(selectedGroupId, (self.currentTicket.type === EntityVO.TYPE_WORKORDER ? 'role=workordermanager' : '')).then(function (response) {
|
|
return filterFilter(response, { fullName: term });
|
|
});
|
|
},
|
|
condition: type === 'workorderManager'
|
|
},
|
|
{
|
|
run: function () {
|
|
return createTicketService.getListOfRiskQuestions(term).then(function (response) {
|
|
return response[0].items[0].objects;
|
|
});
|
|
},
|
|
condition: type === 'riskquestion'
|
|
}
|
|
];
|
|
return _.find(resources, 'condition').run();
|
|
};
|
|
self.getPersonsByCompany = function (term, companyName) {
|
|
return createTicketService.getListOfPersonsByCompany(term, companyName).then(function (response) {
|
|
return response[0];
|
|
});
|
|
};
|
|
self.getListOfRegionsByName = function (term, searchText) {
|
|
return createTicketService.getListOfRegionsByName(term, searchText).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
};
|
|
self.getListOfSiteGroupsByName = function (term, searchText) {
|
|
return createTicketService.getListOfSiteGroupsByName(term, searchText).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
};
|
|
self.getListOfSitesByName = function (term, searchText) {
|
|
return createTicketService.getListOfSitesByName(term, searchText).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
};
|
|
self.getListOfOrganizationsByName = function (term, searchText) {
|
|
return createTicketService.getListOfOrganizationsByName(term, searchText).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
};
|
|
self.getListOfDepartmentsByName = function (term, searchText) {
|
|
return createTicketService.getListOfDepartmentsByName(term, searchText).then(function (response) {
|
|
return response[0].items[0];
|
|
});
|
|
};
|
|
self.getChangeClass = function () {
|
|
var fieldValue = objectValueMapperService.getValueByFieldName('changeClass');
|
|
return fieldValue;
|
|
};
|
|
self.collectTicketChanges = function (ticketMetadata) {
|
|
var ticket = self.currentTicket, allFieldsList = objectValueMapperService.getFieldList();
|
|
var changesList = {
|
|
id: ticket.id,
|
|
customer: _.cloneDeep(ticket.customer),
|
|
displayId: ticket.displayId,
|
|
status: {},
|
|
categorizations: [],
|
|
resCategorizations: [],
|
|
customFields: {}
|
|
};
|
|
_.forEach(allFieldsList, function (field, fieldName) {
|
|
// _.isEmpty returns true for numbers, therefore need to perform type check
|
|
if (!_.isEmpty(field.value) || _.isNumber(field.value) || _.isDate(field.value)) {
|
|
if (field.type === FieldVO.prototype.PERSON_NAME) {
|
|
var name = field.name === FieldVO.prototype.WIDET_NAMES.requestedFor ? FieldVO.prototype.WIDET_NAMES.customer : field.name;
|
|
if (field.isAssigneeWidget()) {
|
|
if (field.primaryKey === 'assignee' && field.value.loginId !== null) {
|
|
changesList[field.primaryKey] = field.value;
|
|
}
|
|
else if (field.primaryKey === 'manager' && field.value.loginId !== null) {
|
|
changesList[field.primaryKey] = field.value;
|
|
}
|
|
else if (field.primaryKey === 'coordinator' && field.value.loginId !== null) {
|
|
changesList[field.primaryKey] = field.value;
|
|
}
|
|
}
|
|
else {
|
|
if (!field.value) {
|
|
changesList[name] = {};
|
|
return;
|
|
}
|
|
if (field.value.loginId) {
|
|
changesList[name] = field.value;
|
|
}
|
|
}
|
|
}
|
|
else if (field.type === FieldVO.prototype.AFFECTED_ASSET) {
|
|
if (field.value.ci && field.value.ci.reconciliationId !== null) {
|
|
changesList[fieldName] = field.value.ci;
|
|
}
|
|
}
|
|
else if (field.type === FieldVO.prototype.CATEGORY_FIELD) {
|
|
var categories = [];
|
|
var tierList = {};
|
|
_.forEach(field.value.listOfTiers, function (element) {
|
|
tierList[element.name] = element.selectedValue;
|
|
});
|
|
var category = {
|
|
name: fieldName,
|
|
tiers: tierList
|
|
};
|
|
categories.push(category);
|
|
changesList.categorizations = changesList.categorizations.concat(categories);
|
|
}
|
|
else if (field.type === FieldVO.prototype.PRIORITY) {
|
|
if (field.value.priority !== null) {
|
|
var priorityFields = {
|
|
impact: field.value.impact.name,
|
|
urgency: field.value.urgency.name,
|
|
priority: field.value.priority.name
|
|
};
|
|
angular.extend(changesList, priorityFields);
|
|
}
|
|
}
|
|
else if (field.isSupportGroupWidget() && field.value) {
|
|
if (field.primaryKey === 'supportGroup') {
|
|
changesList[field.primaryKey] = field.value;
|
|
}
|
|
else if (field.primaryKey === 'managerGroup') {
|
|
changesList[field.primaryKey] = field.value;
|
|
}
|
|
else if (field.primaryKey === 'coordinatorGroup') {
|
|
changesList[field.primaryKey] = field.value;
|
|
}
|
|
}
|
|
else if (field.type === FieldVO.prototype.TICKET_CLASS) {
|
|
if (field.value.timing) {
|
|
changesList.timing = field.value.timing.name;
|
|
}
|
|
if (field.value.timingReason) {
|
|
changesList.timingReason = field.value.timingReason.name;
|
|
}
|
|
}
|
|
else if (field.type === FieldVO.prototype.CATEGORY_COMPANY || field.name === 'locationCompany') {
|
|
changesList.locationCompany = field.value ? { name: field.value } : '';
|
|
}
|
|
else if (field.type === FieldVO.prototype.TICKET_LOCATION) {
|
|
changesList.location = field.value;
|
|
}
|
|
else if (field.type === FieldVO.prototype.POI_LOCATION) {
|
|
if (field.value && field.value.poiId) {
|
|
changesList.location = { poiId: field.value.poiId };
|
|
}
|
|
}
|
|
else {
|
|
if (_.isObject(field.value) && field.type !== FieldVO.prototype.IMPACTED_AREAS && !_.isDate(field.value)) {
|
|
if (fieldName === 'changeRisk') {
|
|
if (field.riskIsUserSpecified && field.value.mode === "manual") {
|
|
changesList.riskIsUserSpecified = field.riskIsUserSpecified;
|
|
}
|
|
else {
|
|
changesList.riskIsUserSpecified = false;
|
|
}
|
|
}
|
|
angular.extend(changesList, field.value);
|
|
}
|
|
else if (field.name === 'assignee' || field.name === 'assigneeName' || field.name === 'managerName') {
|
|
if (field.value && field.assigneeLoginId) {
|
|
if (field.name === 'assignee' || field.name === 'assigneeName') {
|
|
changesList.assignee = {
|
|
fullName: field.value,
|
|
loginId: field.assigneeLoginId
|
|
};
|
|
}
|
|
else if (field.name === 'managerName') {
|
|
changesList.manager = {
|
|
loginId: field.assigneeLoginId,
|
|
fullName: field.value
|
|
};
|
|
}
|
|
}
|
|
}
|
|
else if (field.type !== FieldVO.prototype.IMPACTED_AREAS) {
|
|
if (field.ootb) {
|
|
if (field.name === FieldVO.prototype.STATUS) {
|
|
changesList.status.value = field.value;
|
|
}
|
|
else if (field.name === FieldVO.prototype.STATUS_REASON) {
|
|
changesList.status.reason = field.value;
|
|
}
|
|
else if (field.name === 'resolution') {
|
|
changesList.resolution = field.value;
|
|
}
|
|
else if (field.name.indexOf('CategoryTier') !== -1 || field.name === 'resProductName' || field.name === 'productName') {
|
|
setCategoryFields(changesList, field, ticket);
|
|
}
|
|
else if (field.name === 'z1D_Phase') {
|
|
if (ticket.taskPhases) {
|
|
_.find(ticket.taskPhases, function (selectedPhase) {
|
|
if (selectedPhase.name === field.value) {
|
|
changesList.phaseGuid = selectedPhase.guid;
|
|
changesList.phaseName = selectedPhase.name;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
else {
|
|
if (field.dataType === FieldVO.prototype.DATA_TYPE_DATE || field.dataType === FieldVO.prototype.DATA_TYPE_TIME || field.dataType === FieldVO.prototype.DATA_TYPE_DATE_TIME) {
|
|
changesList[fieldName] = field.value.valueOf();
|
|
}
|
|
else {
|
|
var keyOOTBMapping = ticketMetadata && ticketMetadata.ootbMapping[field.name];
|
|
if (keyOOTBMapping && keyOOTBMapping.length) {
|
|
_.set(changesList, _.last(keyOOTBMapping), field.value);
|
|
}
|
|
else {
|
|
changesList[fieldName] = field.value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if (!field.ootb && field.dataType === FieldVO.prototype.DATA_TYPE_DATE_TIME) {
|
|
changesList.customFields[fieldName] = field.value.valueOf();
|
|
}
|
|
else if (!field.ootb && (field.dataType === FieldVO.prototype.DATA_TYPE_DATE
|
|
|| field.dataType === FieldVO.prototype.DATA_TYPE_TIME)) {
|
|
changesList.customFields[fieldName] = field.getValue();
|
|
}
|
|
else {
|
|
changesList.customFields[fieldName] = field.value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// below code is for optional values. change reason is optional field can have null value
|
|
if ('changeReason' === fieldName) {
|
|
keyOOTBMapping = ticketMetadata && ticketMetadata.ootbMapping[field.name];
|
|
if (keyOOTBMapping && keyOOTBMapping.length) {
|
|
_.set(changesList, _.last(keyOOTBMapping), field.value == null ? "" : field.value);
|
|
}
|
|
}
|
|
if ('reportedSource' === fieldName) {
|
|
if (!field.value) {
|
|
changesList.customFields[fieldName] = null;
|
|
}
|
|
else {
|
|
changesList.customFields[fieldName] = field.value;
|
|
}
|
|
}
|
|
//required for populate different value field
|
|
if (field.linkedFieldExist()) {
|
|
changesList.customFields[field.valueField] = field.getLinkedValue();
|
|
}
|
|
});
|
|
if (ticket.type === EntityVO.TYPE_WORKORDER) {
|
|
delete changesList.company;
|
|
}
|
|
return changesList;
|
|
};
|
|
function setCategoryFields(changesList, field, ticket) {
|
|
if (!changesList.categorizations) {
|
|
changesList.categorizations = [];
|
|
}
|
|
var category = _.find(ticket.allCategories, function (categoryTiers) {
|
|
return _.findIndex(categoryTiers.listOfTiers, function (tier) {
|
|
return tier.name === field.name;
|
|
}) > -1;
|
|
});
|
|
var newCategory = _.find(changesList.categorizations, { name: category.name });
|
|
if (!newCategory) {
|
|
newCategory = {
|
|
name: category.name,
|
|
tiers: {}
|
|
};
|
|
if (category && category.listOfTiers) {
|
|
_.forEach(category.listOfTiers, function (tier) {
|
|
newCategory.tiers[tier.name] = null;
|
|
});
|
|
}
|
|
changesList.categorizations.push(newCategory);
|
|
}
|
|
newCategory.tiers[field.name] = field.value;
|
|
}
|
|
self.createIncidentV2 = function (ticket) {
|
|
return createTicketService.createIncident(ticket).then(function (incident) {
|
|
var id = incident.id;
|
|
var promiseArray = [];
|
|
if (id) {
|
|
ticketModel.cache[id] = incident;
|
|
var descAttachments = objectValueMapperService.getFieldByName('desc');
|
|
if (descAttachments) {
|
|
var attachmentsToSave = descAttachments.getValue();
|
|
if (!_.isEmpty(attachmentsToSave.attachmentToUpload)) {
|
|
_.each(attachmentsToSave.attachmentToUpload, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_INCIDENT, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
return $q.all(promiseArray).then(function () {
|
|
$state.go(EntityVO.TYPE_INCIDENT, { id: id });
|
|
}).catch(function (error) {
|
|
//check if attachment call failed but incident created
|
|
if (id) {
|
|
$state.go(EntityVO.TYPE_INCIDENT, { id: id });
|
|
}
|
|
else {
|
|
delete ticketModel.cache[id];
|
|
return error;
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_INCIDENT, { id: id });
|
|
}
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_INCIDENT, { id: id });
|
|
}
|
|
}
|
|
}).catch(function (error) {
|
|
return (error.data && (error.data.detailMessage || error.data.error)) || error;
|
|
});
|
|
};
|
|
self.createWorkOrderV2 = function (ticket) {
|
|
var currentTicket = self.currentTicket;
|
|
if (currentTicket.dynamicFields && currentTicket.dynamicFields.length) {
|
|
ticket.dynamicFields = [];
|
|
_.forEach(currentTicket.dynamicFields, function (field) {
|
|
ticket.dynamicFields.push({
|
|
name: field.name,
|
|
value: field.value,
|
|
dataType: field.dataType,
|
|
label: field.label
|
|
});
|
|
});
|
|
}
|
|
if (ticket.scheduledStartDate) {
|
|
ticket.scheduledStartDate = getTimestamp(ticket.scheduledStartDate);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
ticket.scheduledEndDate = getTimestamp(ticket.scheduledEndDate);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
ticket.actualStartDate = getTimestamp(ticket.actualStartDate);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
ticket.actualEndDate = getTimestamp(ticket.actualEndDate);
|
|
}
|
|
return createTicketService.createWorkOrder(ticket).then(function (workOrder) {
|
|
var id = workOrder.id;
|
|
var promiseArray = [];
|
|
if (id) {
|
|
ticketModel.cache[id] = workOrder;
|
|
var descAttachments = objectValueMapperService.getFieldByName('desc');
|
|
if (descAttachments) {
|
|
var attachmentsToSave = descAttachments.getValue();
|
|
if (!_.isEmpty(attachmentsToSave.attachmentToUpload)) {
|
|
_.each(attachmentsToSave.attachmentToUpload, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_WORKORDER, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
return $q.all(promiseArray).then(function () {
|
|
$state.go(EntityVO.TYPE_WORKORDER, { id: id });
|
|
}).catch(function (error) {
|
|
//check if attachment call failed but workOrder created
|
|
if (id) {
|
|
$state.go(EntityVO.TYPE_WORKORDER, { id: id });
|
|
}
|
|
else {
|
|
delete ticketModel.cache[id];
|
|
return error;
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_WORKORDER, { id: id });
|
|
}
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_WORKORDER, { id: id });
|
|
}
|
|
}
|
|
}).catch(function (error) {
|
|
return (error.data && (error.data.detailMessage || error.data.error)) || error;
|
|
});
|
|
};
|
|
/**
|
|
* Create change request
|
|
*
|
|
* @param source
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createChangeRequestV2 = function (params) {
|
|
var ticket = self.currentTicket;
|
|
if (ticket.company) {
|
|
params.company = ticket.company;
|
|
}
|
|
if (!ticket.questionResponses && ticket.riskLevel) {
|
|
params.riskIsUserSpecified = ticket.riskIsUserSpecified;
|
|
}
|
|
return createTicketService.createChangeRequest(params)
|
|
.then(function (changeResponse) {
|
|
return changeResponse[0].items[0];
|
|
});
|
|
};
|
|
self.createTaskV2 = function (params, template) {
|
|
var source, ticket = self.currentTicket;
|
|
if (angular.isDefined(template)) {
|
|
var filters = {
|
|
templateId: template.id,
|
|
templateType: template.type
|
|
};
|
|
source = 'template';
|
|
}
|
|
params.company = {
|
|
name: ticket.company.name
|
|
};
|
|
params.parentName = ticket.parentName;
|
|
params.parentDisplayId = ticket.parentDisplayId;
|
|
params.parentId = ticket.parentId;
|
|
if (params.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(params.scheduledStartDate);
|
|
}
|
|
if (params.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(params.scheduledEndDate);
|
|
}
|
|
if (params.actualStartDate) {
|
|
params.actualStartDate = getTimestamp(params.actualStartDate);
|
|
}
|
|
if (params.actualEndDate) {
|
|
params.actualEndDate = getTimestamp(params.actualEndDate);
|
|
}
|
|
return createTicketService.createTask(filters, params).then(function (task) {
|
|
if (source !== 'template') {
|
|
var id = params.id;
|
|
var promiseArray = [];
|
|
if (id) {
|
|
var descAttachments = objectValueMapperService.getFieldByName('desc');
|
|
if (descAttachments) {
|
|
var attachmentsToSave = descAttachments.getValue();
|
|
if (!_.isEmpty(attachmentsToSave.attachmentToUpload)) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_TASK, id, attachmentsToSave.attachmentToUpload);
|
|
promiseArray.push(promise);
|
|
return $q.all(promiseArray);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}).catch(function (error) {
|
|
throw error;
|
|
});
|
|
};
|
|
// TODO: get rid of copy-paste
|
|
/**
|
|
* Create incident, data is taken from model
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createIncident = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
customer: ticket.customer,
|
|
summary: ticket.summary,
|
|
desc: ticket.desc,
|
|
impact: ticket.selectedImpact.name,
|
|
urgency: ticket.selectedUrgency.name,
|
|
templateId: ticket.templateId,
|
|
status: {
|
|
value: ticket.selectedStatus.name
|
|
},
|
|
categorizations: ticket.categorizations,
|
|
resCategorizations: ticket.resCategorizations
|
|
};
|
|
if (ticket.locationCompany && ticket.locationCompany.name && ticket.locationCompany.name !== ticket.customer.company.name) {
|
|
params.locationCompany = ticket.locationCompany;
|
|
}
|
|
if (ticket.selectedStatusReason) {
|
|
params.status.reason = ticket.selectedStatusReason.name;
|
|
}
|
|
if (ticket.selectedServiceType && ticket.selectedServiceType.name) {
|
|
params.serviceType = ticket.selectedServiceType.name;
|
|
}
|
|
if (ticket.resolution) {
|
|
params.resolution = ticket.resolution;
|
|
}
|
|
if (ticket.selectedService) {
|
|
params.impactedService = _.isObject(ticket.selectedService) ? ticket.selectedService : {};
|
|
}
|
|
if (ticket.selectedAsset) {
|
|
params.causalCI = _.isObject(ticket.selectedAsset) ? ticket.selectedAsset : {};
|
|
}
|
|
if (ticket.contact) {
|
|
params.contact = _.isObject(ticket.contact) ? ticket.contact : {};
|
|
}
|
|
if (!ticket.autoAssign) {
|
|
if (ticket.selectedGroup) {
|
|
params.supportGroup = _.isObject(ticket.selectedGroup) ? ticket.selectedGroup : {};
|
|
}
|
|
if (ticket.selectedAssignee) {
|
|
params.assignee = _.isObject(ticket.selectedAssignee) ? ticket.selectedAssignee : {};
|
|
}
|
|
}
|
|
// prepare custom field values
|
|
if (_.size(ticket.customFields)) {
|
|
params.customFields = ticket.customFields;
|
|
}
|
|
return createTicketService.createIncident(params).then(function (incident) {
|
|
var id = incident.id;
|
|
var promiseArray = [];
|
|
if (id) {
|
|
ticketModel.cache[id] = incident;
|
|
if (!_.isEmpty(ticket.attachments)) {
|
|
_.each(ticket.attachments, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_INCIDENT, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
return $q.all(promiseArray).then(function () {
|
|
$state.go(EntityVO.TYPE_INCIDENT, { id: id });
|
|
}).catch(function (error) {
|
|
delete ticketModel.cache[id];
|
|
return error;
|
|
});
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_INCIDENT, { id: id });
|
|
}
|
|
}
|
|
}).catch(function (error) {
|
|
return error.data.detailMessage || error.data.error || error;
|
|
});
|
|
};
|
|
/**
|
|
* Create workorder
|
|
*
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createWorkOrder = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
summary: ticket.summary,
|
|
customer: ticket.customer,
|
|
desc: ticket.desc,
|
|
priority: ticket.selectedPriority.name,
|
|
status: {
|
|
value: ticket.selectedStatus.name
|
|
},
|
|
categorizations: ticket.categorizations,
|
|
dynamicFields: []
|
|
};
|
|
if (ticket.poi) {
|
|
params.location = { poiId: ticket.poi.id };
|
|
}
|
|
if (ticket.locationCompany && ticket.locationCompany.name && ticket.locationCompany.name !== ticket.customer.company.name) {
|
|
params.locationCompany = ticket.locationCompany;
|
|
}
|
|
if (ticket.selectedService) {
|
|
params.impactedService = _.isObject(ticket.selectedService) ? ticket.selectedService : {};
|
|
}
|
|
if (ticket.selectedStatusReason) {
|
|
params.status.reason = ticket.selectedStatusReason.name;
|
|
}
|
|
if (ticket.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(ticket.scheduledStartDate, ticket.scheduledStartTime);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(ticket.scheduledEndDate, ticket.scheduledEndTime);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
params.actualStartDate = getTimestamp(ticket.actualStartDate, ticket.actualStartTime);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
params.actualEndDate = getTimestamp(ticket.actualEndDate, ticket.actualEndTime);
|
|
}
|
|
if (!ticket.autoAssignAssignee) {
|
|
if (ticket.selectedGroup) {
|
|
params.supportGroup = _.isObject(ticket.selectedGroup) ? ticket.selectedGroup : {};
|
|
}
|
|
if (ticket.selectedAssignee) {
|
|
params.assignee = _.isObject(ticket.selectedAssignee) ? ticket.selectedAssignee : {};
|
|
}
|
|
}
|
|
if (!ticket.autoAssignManager) {
|
|
if (ticket.selectedManagerGroup) {
|
|
params.managerGroup = _.isObject(ticket.selectedManagerGroup) ? ticket.selectedManagerGroup : {};
|
|
}
|
|
if (ticket.selectedManager) {
|
|
params.manager = _.isObject(ticket.selectedManager) ? ticket.selectedManager : {};
|
|
}
|
|
}
|
|
if (ticket.templateId) {
|
|
params.templateId = ticket.templateId;
|
|
}
|
|
if (ticket.templateName) {
|
|
params.templateName = ticket.templateName;
|
|
}
|
|
if (ticket.contact) {
|
|
params.contact = _.isObject(ticket.contact) ? ticket.contact : {};
|
|
}
|
|
// prepare custom field values
|
|
if (_.size(ticket.customFields)) {
|
|
params.customFields = ticket.customFields;
|
|
}
|
|
if (ticket.dynamicFields.length) {
|
|
_.forEach(ticket.dynamicFields, function (field) {
|
|
params.dynamicFields.push({
|
|
name: field.name,
|
|
value: field.value,
|
|
dataType: field.dataType
|
|
});
|
|
});
|
|
}
|
|
return createTicketService.createWorkOrder(params).then(function (workOrder) {
|
|
var id = workOrder.id, promiseArray = [];
|
|
if (id) {
|
|
ticketModel.cache[id] = workOrder;
|
|
if (!_.isEmpty(ticket.attachments)) {
|
|
_.each(ticket.attachments, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_WORKORDER, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
return $q.all(promiseArray).then(function () {
|
|
$state.go(EntityVO.TYPE_WORKORDER, { id: id });
|
|
}).catch(function (error) {
|
|
delete ticketModel.cache[id];
|
|
return error;
|
|
});
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_WORKORDER, { id: id });
|
|
}
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
return error.data.detailMessage || error.data.error || error;
|
|
});
|
|
};
|
|
/**
|
|
* Create task
|
|
*
|
|
* @param source
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createTask = function (source, template) {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
summary: ticket.summary,
|
|
desc: ticket.desc,
|
|
type: ticket.type,
|
|
priority: ticket.selectedPriority.name,
|
|
company: {
|
|
name: ticket.company.name
|
|
},
|
|
categorizations: ticket.categorizations,
|
|
parentName: ticket.parentName,
|
|
parentDisplayId: ticket.parentDisplayId,
|
|
parentId: ticket.parentId
|
|
}, filters = {};
|
|
if (ticket.name) {
|
|
params.name = ticket.name;
|
|
}
|
|
if (ticket.selectedPhase) {
|
|
params.phaseGuid = ticket.selectedPhase.guid;
|
|
params.phaseName = ticket.selectedPhase.name;
|
|
}
|
|
if (ticket.customer) {
|
|
params.customer = _.cloneDeep(ticket.customer);
|
|
if (params.customer.accessMappings) {
|
|
delete params.customer.accessMappings;
|
|
}
|
|
}
|
|
if (!ticket.autoAssign) {
|
|
if (ticket.selectedGroup) {
|
|
params.supportGroup = _.isObject(ticket.selectedGroup) ? ticket.selectedGroup : {};
|
|
}
|
|
if (ticket.selectedAssignee) {
|
|
params.assignee = _.isObject(ticket.selectedAssignee) ? ticket.selectedAssignee : {};
|
|
}
|
|
}
|
|
if (ticket.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(ticket.scheduledStartDate, ticket.scheduledStartTime);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(ticket.scheduledEndDate, ticket.scheduledEndTime);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
params.actualStartDate = getTimestamp(ticket.actualStartDate, ticket.actualStartTime);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
params.actualEndDate = getTimestamp(ticket.actualEndDate, ticket.actualEndTime);
|
|
}
|
|
// prepare custom field values
|
|
if (_.size(ticket.customFields)) {
|
|
params.customFields = ticket.customFields;
|
|
}
|
|
if (angular.isDefined(template)) {
|
|
filters = {
|
|
templateId: template.id,
|
|
templateType: template.type
|
|
};
|
|
}
|
|
return createTicketService.createTask(filters, params).then(function () {
|
|
if (source === 'detail' || source === 'draft') {
|
|
var id = params.id, promiseArray = [];
|
|
if (!_.isEmpty(ticket.attachments)) {
|
|
promiseArray.push(attachmentService.uploadAttachment(EntityVO.TYPE_TASK, id, ticket.attachments)
|
|
.then(function () { }));
|
|
return $q.all(promiseArray);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
* Create broadcast
|
|
*
|
|
* @param source
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createBroadcast = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
title: ticket.title,
|
|
message: ticket.desc,
|
|
targets: [
|
|
{
|
|
company: ticket.companyName,
|
|
site: ticket.siteName
|
|
}
|
|
],
|
|
type: ticket.broadcastType.name,
|
|
priority: ticket.priority.name,
|
|
visibility: ticket.visibility.name,
|
|
originatedFrom: 'GALILEO'
|
|
};
|
|
if (ticket.broadcastStartDate) {
|
|
params.broadcastStartDate = getTimestamp(ticket.broadcastStartDate, ticket.broadcastStartTime);
|
|
}
|
|
if (ticket.broadcastEndDate) {
|
|
params.broadcastEndDate = getTimestamp(ticket.broadcastEndDate, ticket.broadcastEndTime);
|
|
}
|
|
return createTicketService.createBroadcast(params).then(function (response) {
|
|
var id = response[0].id, promiseArray = [];
|
|
if (!_.isEmpty(ticket.attachments)) {
|
|
_.each(ticket.attachments, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_BROADCAST, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
return $q.all(promiseArray);
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
* Create outage
|
|
*
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createOutage = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
type: ticket.outageType.name,
|
|
status: {
|
|
value: ticket.status.name
|
|
},
|
|
desc: ticket.desc,
|
|
company: ticket.parent.company,
|
|
affectedAsset: {
|
|
name: ticket.parent.name,
|
|
classId: ticket.parent.classId,
|
|
reconciliationId: ticket.parent.reconciliationId,
|
|
instanceId: ticket.parent.instanceId
|
|
}
|
|
};
|
|
if (ticket.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(ticket.scheduledStartDate, ticket.scheduledStartTime);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(ticket.scheduledEndDate, ticket.scheduledEndTime);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
params.actualStartDate = getTimestamp(ticket.actualStartDate, ticket.actualStartTime);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
params.actualEndDate = getTimestamp(ticket.actualEndDate, ticket.actualEndTime);
|
|
}
|
|
return createTicketService.createOutage(params).then(function () {
|
|
})
|
|
.catch(function (error) {
|
|
return error.data.detailMessage || error.data.error || error;
|
|
});
|
|
};
|
|
self.createOutagesBulk = function (assets, createRelation) {
|
|
var ticket = self.currentTicket, outage = {
|
|
type: ticket.outageType.name,
|
|
status: {
|
|
value: ticket.status.name
|
|
},
|
|
desc: ticket.desc,
|
|
company: ticket.parent.company
|
|
};
|
|
if (ticket.scheduledStartDate) {
|
|
outage.scheduledStartDate = getTimestamp(ticket.scheduledStartDate, ticket.scheduledStartTime);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
outage.scheduledEndDate = getTimestamp(ticket.scheduledEndDate, ticket.scheduledEndTime);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
outage.actualStartDate = getTimestamp(ticket.actualStartDate, ticket.actualStartTime);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
outage.actualEndDate = getTimestamp(ticket.actualEndDate, ticket.actualEndTime);
|
|
}
|
|
var parentAssets = _.map(assets, function (asset) {
|
|
return {
|
|
name: asset.name,
|
|
classId: asset.classId,
|
|
reconciliationId: asset.reconciliationId,
|
|
instanceId: asset.instanceId
|
|
};
|
|
});
|
|
var params = { outage: outage, assets: parentAssets };
|
|
if (createRelation) {
|
|
params.createRelation = true;
|
|
params.attributeMap = { id: ticket.parent.id, ticketType: ticket.parent.type };
|
|
}
|
|
return createTicketService.createOutageBulk(params)
|
|
.then(function () { })
|
|
.catch(function (error) {
|
|
return error.data.detailMessage || error.data.error || error;
|
|
});
|
|
};
|
|
/**
|
|
* Create change request
|
|
*
|
|
* @param source
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createChangeRequest = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
company: ticket.company,
|
|
summary: ticket.summary,
|
|
desc: ticket.desc,
|
|
assignee: ticket.assignee,
|
|
supportGroup: ticket.supportGroup,
|
|
impact: ticket.impact.name,
|
|
urgency: ticket.urgency.name,
|
|
priority: ticket.priority.name,
|
|
timing: ticket.timing.name,
|
|
categorizations: ticket.categorizations,
|
|
customer: ticket.customer,
|
|
location: ticket.location,
|
|
templateId: ticket.templateId
|
|
};
|
|
if (!ticket.questionResponses && ticket.riskLevel) {
|
|
params.riskLevel = ticket.riskLevel.name;
|
|
params.riskIsUserSpecified = ticket.riskIsUserSpecified;
|
|
}
|
|
if (!ticket.autoAssignManager) {
|
|
if (ticket.manager) {
|
|
params.manager = ticket.manager;
|
|
}
|
|
if (ticket.managerGroup) {
|
|
params.managerGroup = {
|
|
company: ticket.managerGroup.company,
|
|
name: ticket.managerGroup.name,
|
|
organization: ticket.managerGroup.organization
|
|
};
|
|
}
|
|
}
|
|
if (ticket.impactedService) {
|
|
params.impactedService = _.isObject(ticket.impactedService) ? ticket.impactedService : {};
|
|
}
|
|
if (ticket.changeReason) {
|
|
params.changeReason = ticket.changeReason.name;
|
|
}
|
|
if (ticket.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(ticket.scheduledStartDate);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(ticket.scheduledEndDate);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
params.actualStartDate = getTimestamp(ticket.actualStartDate);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
params.actualEndDate = getTimestamp(ticket.actualEndDate);
|
|
}
|
|
if (ticket.targetDate) {
|
|
params.targetDate = getTimestamp(ticket.targetDate);
|
|
}
|
|
if (ticket.timingReason) {
|
|
params.timingReason = ticket.timingReason.name;
|
|
}
|
|
// prepare custom field values
|
|
if (_.size(ticket.customFields)) {
|
|
params.customFields = ticket.customFields;
|
|
}
|
|
return createTicketService.createChangeRequest(params)
|
|
.then(function (changeResponse) {
|
|
return changeResponse[0].items[0];
|
|
});
|
|
};
|
|
/**
|
|
* Create release
|
|
*
|
|
* @param source
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createRelease = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
company: ticket.company,
|
|
summary: ticket.summary,
|
|
desc: ticket.desc,
|
|
coordinator: ticket.coordinator,
|
|
coordinatorGroup: ticket.coordinatorGroup,
|
|
impact: ticket.impact.name,
|
|
urgency: ticket.urgency.name,
|
|
priority: ticket.priority.name,
|
|
categorizations: ticket.categorizations,
|
|
location: ticket.location,
|
|
templateId: ticket.templateId,
|
|
templateGuid: ticket.templateGuid,
|
|
riskLevel: ticket.riskLevel.name
|
|
};
|
|
if (ticket.impactedService) {
|
|
params.impactedService = _.isObject(ticket.impactedService) ? ticket.impactedService : {};
|
|
}
|
|
if (ticket.businessJustification) {
|
|
params.businessJustification = _.isObject(ticket.businessJustification) ? ticket.businessJustification.name : "";
|
|
}
|
|
if (ticket.releaseType) {
|
|
params.releaseType = _.isObject(ticket.releaseType) ? ticket.releaseType.name : "";
|
|
}
|
|
if (ticket.riskLevelSelectionMode === 'auto') {
|
|
params.isAutoCalcualteRisk = true;
|
|
}
|
|
if (ticket.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(ticket.scheduledStartDate);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(ticket.scheduledEndDate);
|
|
}
|
|
if (ticket.deploymentStartDate) {
|
|
params.deploymentStartDate = getTimestamp(ticket.deploymentStartDate);
|
|
}
|
|
if (ticket.deploymentEndDate) {
|
|
params.deploymentEndDate = getTimestamp(ticket.deploymentEndDate);
|
|
}
|
|
return createTicketService.createRelease(params)
|
|
.then(function (releaseResponse) {
|
|
return releaseResponse[0].items[0];
|
|
});
|
|
};
|
|
/**
|
|
* Create Activity
|
|
*
|
|
* @param source
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createActivity = function (isCreateFromTemplate, ticketData) {
|
|
var params;
|
|
if (isCreateFromTemplate) {
|
|
params = {
|
|
templateGuid: ticketData.id,
|
|
parentId: ticketData.parentId,
|
|
parentGuid: ticketData.parentGuid,
|
|
sequence: ticketData.sequence
|
|
};
|
|
if (ticketData.milestone) {
|
|
params.milestone = _.isObject(ticketData.milestone) ? ticketData.milestone.name : ticketData.milestone;
|
|
}
|
|
return createTicketService.createActivity(params)
|
|
.then(function (activityResponse) {
|
|
return activityResponse[0].items[0];
|
|
});
|
|
}
|
|
var ticket = self.currentTicket;
|
|
params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
summary: ticket.summary,
|
|
desc: ticket.desc,
|
|
parentId: ticket.parentId,
|
|
parentGuid: ticket.parentGuid,
|
|
sequence: ticket.sequence,
|
|
company: ticket.company,
|
|
location: ticket.location,
|
|
assignee: ticket.assignee,
|
|
supportGroup: ticket.supportGroup
|
|
};
|
|
if (ticket.milestone) {
|
|
params.milestone = _.isObject(ticket.milestone) ? ticket.milestone.name : '';
|
|
}
|
|
if (ticket.priority) {
|
|
params.priority = _.isObject(ticket.priority) ? ticket.priority.name : '';
|
|
}
|
|
if (ticket.scheduledStartDate) {
|
|
params.scheduledStartDate = getTimestamp(ticket.scheduledStartDate);
|
|
}
|
|
if (ticket.scheduledEndDate) {
|
|
params.scheduledEndDate = getTimestamp(ticket.scheduledEndDate);
|
|
}
|
|
if (ticket.actualStartDate) {
|
|
params.actualStartDate = getTimestamp(ticket.actualStartDate);
|
|
}
|
|
if (ticket.actualEndDate) {
|
|
params.actualEndDate = getTimestamp(ticket.actualEndDate);
|
|
}
|
|
return createTicketService.createActivity(params)
|
|
.then(function (activityResponse) {
|
|
return activityResponse[0].items[0];
|
|
});
|
|
};
|
|
/**
|
|
* Create problem, data is taken from model
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createProblem = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
summary: ticket.summary,
|
|
desc: ticket.desc,
|
|
impact: ticket.selectedImpact.name,
|
|
urgency: ticket.selectedUrgency.name,
|
|
templateId: ticket.templateId,
|
|
status: {
|
|
value: ticket.selectedStatus.name
|
|
},
|
|
categorizations: ticket.categorizations,
|
|
investigationDriver: ticket.investigationDriver.name,
|
|
targetDate: ticket.targetDate ? getTimestamp(ticket.targetDate) : null,
|
|
workaround: ticket.workaround,
|
|
resolution: ticket.resolution,
|
|
rootCause: ticket.rootCause ? ticket.rootCause.name : undefined
|
|
};
|
|
if (ticket.company) {
|
|
params.company = ticket.company;
|
|
}
|
|
if (ticket.location) {
|
|
params.location = ticket.location;
|
|
}
|
|
if (ticket.selectedStatusReason) {
|
|
params.status.reason = ticket.selectedStatusReason.name;
|
|
}
|
|
if (ticket.selectedService) {
|
|
params.impactedService = _.isObject(ticket.selectedService) ? ticket.selectedService : {};
|
|
}
|
|
if (ticket.selectedAsset) {
|
|
params.causalCI = _.isObject(ticket.selectedAsset) ? ticket.selectedAsset : {};
|
|
}
|
|
if (ticket.contact) {
|
|
params.contact = _.isObject(ticket.contact) ? ticket.contact : {};
|
|
}
|
|
if (!ticket.autoAssign) {
|
|
if (ticket.assignee) {
|
|
params.assignee = ticket.assignee;
|
|
}
|
|
if (ticket.supportGroup) {
|
|
params.supportGroup = ticket.supportGroup;
|
|
}
|
|
}
|
|
if (!ticket.coordinatorAutoAssign) {
|
|
if (ticket.coordinator) {
|
|
params.coordinator = ticket.coordinator;
|
|
}
|
|
if (ticket.coordinatorGroup) {
|
|
params.coordinatorGroup = ticket.coordinatorGroup;
|
|
}
|
|
}
|
|
// prepare custom field values
|
|
if (_.size(ticket.customFields)) {
|
|
params.customFields = ticket.customFields;
|
|
}
|
|
return createTicketService.createProblem(params).then(function (problem) {
|
|
var id = problem.id;
|
|
var promiseArray = [];
|
|
if (id) {
|
|
ticketModel.cache[id] = problem;
|
|
if (ticket.impactedAreas) {
|
|
var impactedAreasPromise = self.saveImpactedAreas(id, EntityVO.TYPE_PROBLEM, ticket.impactedAreas);
|
|
promiseArray.push(impactedAreasPromise);
|
|
}
|
|
if (!_.isEmpty(ticket.attachments)) {
|
|
_.each(ticket.attachments, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_PROBLEM, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
}
|
|
if (promiseArray.length) {
|
|
return $q.all(promiseArray).then(function () {
|
|
$state.go(EntityVO.TYPE_PROBLEM, { id: id });
|
|
}).catch(function (error) {
|
|
delete ticketModel.cache[id];
|
|
return error;
|
|
});
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_PROBLEM, { id: id });
|
|
}
|
|
}
|
|
}).catch(function (error) {
|
|
return error.data.detailMessage || error.data.error || error;
|
|
});
|
|
};
|
|
self.createKE = function () {
|
|
var ticket = self.currentTicket, params = {
|
|
id: ticket.id,
|
|
displayId: ticket.displayId,
|
|
summary: ticket.summary,
|
|
impact: ticket.selectedImpact.name,
|
|
urgency: ticket.selectedUrgency.name,
|
|
desc: ticket.desc,
|
|
targetDate: getTimestamp(ticket.targetDate),
|
|
status: {
|
|
value: ticket.selectedStatus.name
|
|
},
|
|
categorizations: ticket.categorizations,
|
|
workaround: ticket.workaround,
|
|
resolution: ticket.resolution,
|
|
rootCause: ticket.rootCause ? ticket.rootCause.name : undefined
|
|
};
|
|
if (ticket.company) {
|
|
params.company = ticket.company;
|
|
}
|
|
if (ticket.selectedService) {
|
|
params.impactedService = _.isObject(ticket.selectedService) ? ticket.selectedService : {};
|
|
}
|
|
if (ticket.selectedAsset) {
|
|
params.causalCI = _.isObject(ticket.selectedAsset) ? ticket.selectedAsset : {};
|
|
}
|
|
if (ticket.selectedStatusReason) {
|
|
params.status.reason = ticket.selectedStatusReason.name;
|
|
}
|
|
if (!ticket.autoAssign) {
|
|
if (ticket.assignee) {
|
|
params.assignee = _.isObject(ticket.assignee) ? ticket.assignee : {};
|
|
}
|
|
if (ticket.supportGroup) {
|
|
params.supportGroup = _.isObject(ticket.supportGroup) ? ticket.supportGroup : {};
|
|
}
|
|
}
|
|
if (!ticket.coordinatorAutoAssign) {
|
|
if (ticket.coordinator) {
|
|
params.coordinator = _.isObject(ticket.coordinator) ? ticket.coordinator : {};
|
|
}
|
|
if (ticket.coordinatorGroup) {
|
|
params.coordinatorGroup = _.isObject(ticket.coordinatorGroup) ? ticket.coordinatorGroup : {};
|
|
}
|
|
}
|
|
if (ticket.selectedViewAccess) {
|
|
params.viewAccess = ticket.selectedViewAccess.name;
|
|
}
|
|
// prepare custom field values
|
|
if (_.size(ticket.customFields)) {
|
|
params.customFields = ticket.customFields;
|
|
}
|
|
return createTicketService.createKnownError(params).then(function (ke) {
|
|
var id = ke.id;
|
|
var promiseArray = [];
|
|
if (id) {
|
|
ticketModel.cache[id] = ke;
|
|
if (!_.isEmpty(ticket.attachments)) {
|
|
_.each(ticket.attachments, function (attachment) {
|
|
var promise = attachmentService.uploadAttachment(EntityVO.TYPE_KNOWNERROR, id, attachment);
|
|
promiseArray.push(promise);
|
|
});
|
|
}
|
|
if (promiseArray.length) {
|
|
return $q.all(promiseArray).then(function () {
|
|
$state.go(EntityVO.TYPE_KNOWNERROR, { id: id });
|
|
}).catch(function (error) {
|
|
delete ticketModel.cache[id];
|
|
return error;
|
|
});
|
|
}
|
|
else {
|
|
$state.go(EntityVO.TYPE_KNOWNERROR, { id: id });
|
|
}
|
|
}
|
|
}).catch(function (error) {
|
|
return error.data.detailMessage || error.data.error || error;
|
|
});
|
|
};
|
|
self.createImpactAnalysis = function (id, type, params) {
|
|
if (id && type) {
|
|
return createTicketService.createImpactAnalysis(id, type, params)
|
|
.catch(function (error) {
|
|
if (error) {
|
|
systemAlertService.error({
|
|
text: (error.data && error.data.error) || error,
|
|
clear: true
|
|
});
|
|
}
|
|
});
|
|
}
|
|
};
|
|
self.saveImpactedAreas = function (id, type, impactedAreas) {
|
|
if (impactedAreas && impactedAreas.length > 0) {
|
|
return createTicketService.saveImpactedAreas(id, type, impactedAreas);
|
|
}
|
|
return $q.when();
|
|
};
|
|
self.deleteImpactedAreas = function (id, impactedAreas) {
|
|
if (impactedAreas && impactedAreas.length > 0) {
|
|
return createTicketService.deleteImpactedAreas(id, impactedAreas);
|
|
}
|
|
return $q.when();
|
|
};
|
|
self.saveRiskResponse = function (ticket) {
|
|
var params = [];
|
|
if (!ticket.questionResponses) {
|
|
return $q.when();
|
|
}
|
|
_.forOwn(ticket.questionResponses, function (option) {
|
|
var questionResponse = {
|
|
weight: option.parentQuestion.weight,
|
|
company: ticket.company.name,
|
|
questionnaireId: option.parentQuestion.questionnaireId,
|
|
parentId: ticket.id,
|
|
questionId: option.parentQuestion.id,
|
|
questionText: option.parentQuestion.label,
|
|
value: option.riskValue,
|
|
order: option.parentQuestion.sortOrder,
|
|
displayValue: option.label,
|
|
format: option.parentQuestion.format
|
|
};
|
|
if (option.parentQuestion.responseId) {
|
|
questionResponse.id = option.parentQuestion.responseId;
|
|
}
|
|
params.push(questionResponse);
|
|
});
|
|
ticket.questionResponses = params;
|
|
return createTicketService.saveRiskResponse(ticket.id, params).catch(function (error) {
|
|
if (error) {
|
|
systemAlertService.error({
|
|
text: (error.data && error.data.error) || error,
|
|
clear: true
|
|
});
|
|
}
|
|
});
|
|
};
|
|
self.saveDocuments = function (ticket) {
|
|
var promiseArray = [];
|
|
if (!_.isEmpty(ticket.documents)) {
|
|
_.each(ticket.documents, function (doc) {
|
|
_.each(doc.plans, function (plan) {
|
|
if (!plan.desc && plan.attachments.length < 1) {
|
|
return;
|
|
}
|
|
var request = {
|
|
text: plan.desc,
|
|
type: doc.index,
|
|
locked: false,
|
|
access: true,
|
|
attachments: [],
|
|
attachmentInfos: []
|
|
};
|
|
_.each(plan.attachments, function (attach) {
|
|
if (!attach.id) {
|
|
request.attachments.push(attach);
|
|
request.attachmentInfos.push({ name: attach.name, action: 'add' });
|
|
}
|
|
});
|
|
//promise = feedModel.saveNote(param, note);
|
|
var promise = attachmentService.createChangePlan(ticket.id, ticket.type, request);
|
|
promiseArray.push(promise);
|
|
});
|
|
});
|
|
}
|
|
return promiseArray;
|
|
};
|
|
self.onChangeCreateSuccess = function (change, runImpactAnalysis) {
|
|
if (!change.type) {
|
|
change.type = EntityVO.TYPE_CHANGE;
|
|
}
|
|
//initiate backend call to start impact analysis
|
|
if (runImpactAnalysis) {
|
|
var command = { "command": "start" }; //start will start the impact analysis
|
|
self.createImpactAnalysis(change.id, EntityVO.TYPE_CHANGE, command);
|
|
}
|
|
feedModel.pendingWorkNote = null;
|
|
self.currentTicket = null;
|
|
};
|
|
/**
|
|
* Create asset, data is taken from model
|
|
* @returns {ng.IPromise<TResult>}
|
|
*/
|
|
self.createAsset = function () {
|
|
var asset = self.currentTicket, params = {
|
|
classId: asset.selectedSubtype.name,
|
|
name: asset.name,
|
|
description: asset.desc
|
|
};
|
|
if (asset.company && asset.company.name) {
|
|
params.companyName = asset.company.name;
|
|
}
|
|
_.forEach(asset.allCategories[0].listOfTiers, function (tier) {
|
|
if (tier.selectedValue) {
|
|
params[tier.name] = tier.selectedValue;
|
|
}
|
|
});
|
|
if (!_.isEmpty(asset.selectedStatus)) {
|
|
params.status = asset.selectedStatus.name;
|
|
}
|
|
if (!_.isEmpty(asset.selectedStatusReason)) {
|
|
params.statusReason = asset.selectedStatusReason.name;
|
|
}
|
|
if (!_.isEmpty(asset.tagNumber)) {
|
|
params.tag = asset.tagNumber;
|
|
}
|
|
if (!_.isEmpty(asset.manufacturer)) {
|
|
params.manufacturer = asset.manufacturer.name;
|
|
}
|
|
if (!_.isEmpty(asset.supplier)) {
|
|
params.supplier = asset.supplier.name;
|
|
}
|
|
if (!_.isEmpty(asset.impact)) {
|
|
params.impact = asset.impact;
|
|
}
|
|
if (!_.isEmpty(asset.urgency)) {
|
|
params.urgency = asset.urgency;
|
|
}
|
|
if (!_.isEmpty(asset.priority)) {
|
|
params.priority = asset.priority;
|
|
}
|
|
if (!_.isEmpty(asset.systemRole)) {
|
|
params.systemRole = asset.systemRole;
|
|
}
|
|
if (!_.isEmpty(asset.serialNumber)) {
|
|
params.serialNumber = asset.serialNumber;
|
|
}
|
|
if (!_.isEmpty(asset.assetId)) {
|
|
params.assetId = asset.assetId;
|
|
}
|
|
if (!_.isEmpty(asset.partNumber)) {
|
|
params.partNumber = asset.partNumber;
|
|
}
|
|
if (asset.receivedDate.value) {
|
|
params.receivedDate = asset.receivedDate.value;
|
|
}
|
|
if (asset.availableDate.value) {
|
|
params.availableDate = asset.availableDate.value;
|
|
}
|
|
if (asset.returnDate.value) {
|
|
params.returnDate = asset.returnDate.value;
|
|
}
|
|
if (asset.installationDate.value) {
|
|
params.installationDate = asset.installationDate.value;
|
|
}
|
|
if (asset.disposalDate.value) {
|
|
params.disposalDate = asset.disposalDate.value;
|
|
}
|
|
if (asset.purchaseDate.value) {
|
|
params.purchaseDate = asset.purchaseDate.value;
|
|
}
|
|
if (asset.lastScanDate.value) {
|
|
params.lastScanDate = asset.lastScanDate.value;
|
|
}
|
|
/*SW00503167 - hiding currency fields for the time being till this issue is resolved*/
|
|
/*if(asset.unitPrice.value) {
|
|
params.unitPrice = asset.unitPrice;
|
|
}
|
|
if(asset.salesTax.value) {
|
|
params.salesTax = asset.salesTax;
|
|
}
|
|
if(asset.marketValue.value) {
|
|
params.marketValue = asset.marketValue;
|
|
}*/
|
|
if (!_.isEmpty(asset.invoiceNumber)) {
|
|
params.invoiceNumber = asset.invoiceNumber;
|
|
}
|
|
if (!_.isEmpty(asset.costCenter)) {
|
|
params.costCenter = asset.costCenter.value;
|
|
}
|
|
if (!_.isEmpty(asset.budgetCode)) {
|
|
params.budgetCode = asset.budgetCode;
|
|
}
|
|
if (!_.isEmpty(asset.projectNumber)) {
|
|
params.projectNumber = asset.projectNumber;
|
|
}
|
|
if (!_.isEmpty(asset.floor)) {
|
|
params.floor = asset.floor;
|
|
}
|
|
if (!_.isEmpty(asset.room)) {
|
|
params.room = asset.room;
|
|
}
|
|
/* type specific */
|
|
if (asset.selectedType.name === asset.advancedType) {
|
|
if (!_.isEmpty(asset.hostName)) {
|
|
params.hostName = asset.hostName;
|
|
}
|
|
if (!_.isEmpty(asset.primaryCapability)) {
|
|
params.primaryCapability = asset.primaryCapability.name;
|
|
}
|
|
if (!_.isEmpty(asset.capabilityList)) {
|
|
params.capabilityList = asset.capabilityList;
|
|
}
|
|
if (!_.isEmpty(asset.selectedSystemType)) {
|
|
params.systemType = asset.selectedSystemType.name;
|
|
}
|
|
if (!_.isEmpty(asset.selectedVirtualSystemType)) {
|
|
params.virtualSystemType = asset.selectedVirtualSystemType.name;
|
|
}
|
|
}
|
|
if (!_.isEmpty(asset.siteName)) {
|
|
params.siteName = asset.siteName;
|
|
}
|
|
if (!_.isEmpty(asset.siteGroup)) {
|
|
params.siteGroup = asset.siteGroup;
|
|
}
|
|
if (!_.isEmpty(asset.siteRegion)) {
|
|
params.siteRegion = asset.siteRegion;
|
|
}
|
|
// prepare custom field values
|
|
_.forOwn(asset.customFields, function (value, key) {
|
|
if (value === '' || value === null || !angular.isDefined(value)) {
|
|
delete asset.customFields[key];
|
|
}
|
|
});
|
|
if (_.size(asset.customFields)) {
|
|
params.customFields = asset.customFields;
|
|
}
|
|
return createTicketService.createAsset(params).then(function (data) {
|
|
var assetObj = data.responseObject;
|
|
if (!assetObj.needsReconciliation) {
|
|
$state.go(EntityVO.TYPE_ASSET, {
|
|
assetId: assetObj.reconciliationId,
|
|
assetClassId: assetObj.classId
|
|
});
|
|
}
|
|
else {
|
|
return { assetName: asset.name };
|
|
}
|
|
}).catch(function (error) {
|
|
return { error: error.data.detailMessage || error.data.error || error };
|
|
});
|
|
};
|
|
self.formContainsInvalidFields = function (form) {
|
|
var formErrorsWithoutRequired = _.omit(form.$error, 'required');
|
|
return !_.isEmpty(formErrorsWithoutRequired);
|
|
};
|
|
function getTimestamp(date, time) {
|
|
time = time ? moment(time) : moment(date);
|
|
return moment(date).set('hours', time.get('hours')).set('minutes', time.get('minutes')).format('X') * 1000;
|
|
}
|
|
return self;
|
|
}
|
|
]);
|
|
}());
|