368 lines
18 KiB
JavaScript
368 lines
18 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('personModule')
|
|
.factory('personModel', ['personService', '$q', 'configurationModel', 'systemAlertService', 'userModel',
|
|
function (personService, $q, configurationModel, systemAlertService, userModel) {
|
|
var personModel = {
|
|
personDetails: {},
|
|
personAssets: [],
|
|
personOpenTickets: {
|
|
ticketList: [],
|
|
totalMatches: 0
|
|
},
|
|
personClosedTickets: {
|
|
ticketList: [],
|
|
totalMatches: 0
|
|
},
|
|
personOpenServiceBrokerTickets: {
|
|
ticketList: [],
|
|
totalMatches: 0
|
|
},
|
|
personClosedServiceBrokerTickets: {
|
|
ticketList: [],
|
|
totalMatches: 0
|
|
},
|
|
personAllTickets: {
|
|
ticketList: [],
|
|
totalMatches: 0
|
|
},
|
|
personAssignedTickets: {
|
|
ticketList: [],
|
|
totalMatches: 0
|
|
},
|
|
personKnowledgeArticles: [],
|
|
filterConfig: _.cloneDeep(configurationModel.get('ticketConsole.filter')),
|
|
defaultChunkSize: 20
|
|
};
|
|
personModel.criteria = {
|
|
filterCriteria: {},
|
|
chunkInfo: { startIndex: 0, chunkSize: personModel.defaultChunkSize }
|
|
};
|
|
personModel.filterDict = _.indexBy(personModel.filterConfig, 'name');
|
|
/**
|
|
*
|
|
* Fetch person details.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getPersonDetailsByID = function (personId) {
|
|
if (userModel.userId !== personId) {
|
|
personId = encodeURIComponent(personId);
|
|
}
|
|
return personService.getPersonDetailsByID(personId).then(function (data) {
|
|
personModel.personDetails = data;
|
|
return data;
|
|
});
|
|
};
|
|
personModel.getListOfPersonByName = function (firstName, lastName) {
|
|
var searchText = '' + firstName, skipResultProcessing = true;
|
|
if (firstName && lastName) {
|
|
searchText = firstName + ' ' + lastName;
|
|
skipResultProcessing = false;
|
|
}
|
|
return personService.getListOfPersonByName(searchText, skipResultProcessing);
|
|
};
|
|
personModel.getListOfPersonsByText = function (searchText) {
|
|
return personService.getListOfPersonByName(searchText);
|
|
};
|
|
personModel.getListOfChangeManagerByText = function (searchText) {
|
|
return personService.getListOfPersonByName(searchText, false, 'changemanager');
|
|
};
|
|
personModel.getListOfChangeCoordinatorByText = function (searchText) {
|
|
return personService.getListOfPersonByName(searchText, false, 'changecoordinator');
|
|
};
|
|
personModel.getListOfProblemCoordinatorByText = function (searchText) {
|
|
return personService.getListOfPersonByName(searchText, false, 'problemcoordinator');
|
|
};
|
|
personModel.getListOfReleaseCoordinatorByText = function (searchText) {
|
|
return personService.getListOfPersonByName(searchText, false, 'releasecoordinator');
|
|
};
|
|
personModel.getListOfPersonNamesByText = function (searchText) {
|
|
return personService.getListOfPersonNamesByName(searchText);
|
|
};
|
|
personModel.getServiceSummaryStats = function (personId) {
|
|
return personService.getServiceSummaryStats(personId).then(function (data) {
|
|
personModel.serviceSummaryRaw = data[0].statsMetrics;
|
|
personModel.serviceSummary = {
|
|
ratingCount: 0,
|
|
ratingScore: 0,
|
|
escalation: 0,
|
|
ratingMarkers: []
|
|
};
|
|
var i;
|
|
for (i = 0; i < personModel.serviceSummaryRaw.length; i++) {
|
|
if (personModel.serviceSummaryRaw[i].name === 'Number of Ratings') {
|
|
personModel.serviceSummary.ratingCount = personModel.serviceSummaryRaw[i].value;
|
|
}
|
|
else if (personModel.serviceSummaryRaw[i].name === 'Average Rating') {
|
|
personModel.serviceSummary.ratingScore = personModel.serviceSummaryRaw[i].value;
|
|
}
|
|
else if (personModel.serviceSummaryRaw[i].name === 'Number of Escalations') {
|
|
personModel.serviceSummary.escalation = personModel.serviceSummaryRaw[i].value;
|
|
}
|
|
}
|
|
for (i = 0; i < 5; i++) {
|
|
if (personModel.serviceSummary.ratingScore >= i + 0.75) {
|
|
personModel.serviceSummary.ratingMarkers.push({ value: 100 });
|
|
}
|
|
else if (personModel.serviceSummary.ratingScore >= i + 0.25) {
|
|
personModel.serviceSummary.ratingMarkers.push({ value: 50 });
|
|
}
|
|
else {
|
|
personModel.serviceSummary.ratingMarkers.push({ value: 0 });
|
|
}
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
* Fetch person asset list.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getPersonAssets = function (personId, showAllAssets) {
|
|
return personService.getPersonAssets(personId, showAllAssets).then(function (data) {
|
|
personModel.personAssets = data;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch person open tickets list.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getOpenTickets = function (personId, startIndex) {
|
|
var params = {};
|
|
params.chunkInfo = {
|
|
startIndex: startIndex || 0,
|
|
chunkSize: personModel.defaultChunkSize
|
|
};
|
|
params.filterCriteria = { customer: { loginId: personId }, statusMapping: 'open' };
|
|
params.sortInfo = { sortFieldName: 'modifiedDate', sortFieldOrder: 'DESC' };
|
|
//params.filterCriteria = getFilterCriteria(filters);
|
|
return personService.getTickets(params).then(function (data) {
|
|
if (startIndex > 0) {
|
|
personModel.personOpenTickets.ticketList = _.union(personModel.personOpenTickets.ticketList, data.ticketList);
|
|
}
|
|
else {
|
|
personModel.personOpenTickets.ticketList = data.ticketList;
|
|
}
|
|
personModel.personOpenTickets.totalMatches = data.totalMatches;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch person open service broker tickets list.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getOpenServiceBrokerTickets = function (personId, startIndex) {
|
|
var params = {};
|
|
params.chunkInfo = {
|
|
startIndex: startIndex || 0,
|
|
chunkSize: personModel.defaultChunkSize
|
|
};
|
|
params.filterCriteria = { customer: { loginId: personId }, statusMapping: 'open' };
|
|
params.sortInfo = { sortFieldName: 'modifiedDate', sortFieldOrder: 'DESC' };
|
|
return personService.getServiceBrokerTickets(params).then(function (data) {
|
|
if (startIndex > 0) {
|
|
personModel.personOpenServiceBrokerTickets.ticketList = _.union(personModel.personOpenServiceBrokerTickets.ticketList, data.ticketList);
|
|
}
|
|
else {
|
|
personModel.personOpenServiceBrokerTickets.ticketList = data.ticketList;
|
|
}
|
|
personModel.personOpenServiceBrokerTickets.totalMatches = data.totalMatches;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch person closed tickets list.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getClosedTickets = function (personId, startIndex) {
|
|
var params = {};
|
|
params.filterCriteria = { customer: { loginId: personId }, statusMapping: 'close' };
|
|
params.sortInfo = { sortFieldName: 'modifiedDate', sortFieldOrder: 'DESC' };
|
|
params.chunkInfo = {
|
|
startIndex: startIndex || 0,
|
|
chunkSize: personModel.defaultChunkSize
|
|
};
|
|
return personService.getTickets(params).then(function (data) {
|
|
if (startIndex > 0) {
|
|
personModel.personClosedTickets.ticketList = _.union(personModel.personClosedTickets.ticketList, data.ticketList);
|
|
}
|
|
else {
|
|
personModel.personClosedTickets.ticketList = data.ticketList;
|
|
}
|
|
personModel.personClosedTickets.totalMatches = data.totalMatches;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch person closed service broker tickets list.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getClosedServiceBrokerTickets = function (personId, startIndex) {
|
|
var params = {};
|
|
params.filterCriteria = { customer: { loginId: personId }, statusMapping: 'close' };
|
|
params.sortInfo = { sortFieldName: 'modifiedDate', sortFieldOrder: 'DESC' };
|
|
params.chunkInfo = {
|
|
startIndex: startIndex || 0,
|
|
chunkSize: personModel.defaultChunkSize
|
|
};
|
|
return personService.getServiceBrokerTickets(params).then(function (data) {
|
|
if (startIndex > 0) {
|
|
personModel.personClosedServiceBrokerTickets.ticketList = _.union(personModel.personClosedServiceBrokerTickets.ticketList, data.ticketList);
|
|
}
|
|
else {
|
|
personModel.personClosedServiceBrokerTickets.ticketList = data.ticketList;
|
|
}
|
|
personModel.personClosedServiceBrokerTickets.totalMatches = data.totalMatches;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch all tickets list requested by a person with personId.
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getAllTickets = function (personId, startIndex) {
|
|
var params = {};
|
|
params.filterCriteria = { customer: { loginId: personId } };
|
|
params.chunkInfo = {
|
|
startIndex: startIndex || 0,
|
|
chunkSize: personModel.defaultChunkSize
|
|
};
|
|
params.sortInfo = { sortFieldName: 'modifiedDate', sortFieldOrder: 'DESC' };
|
|
return personService.getTickets(params).then(function (data) {
|
|
if (startIndex > 0) {
|
|
personModel.personAllTickets.ticketList = _.union(personModel.personAllTickets.ticketList, data.ticketList);
|
|
}
|
|
else {
|
|
personModel.personAllTickets.ticketList = data.ticketList;
|
|
}
|
|
personModel.personAllTickets.totalMatches = data.totalMatches;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch all tickets list assigned to a person with personId
|
|
*
|
|
* @param {String} personId
|
|
* @param {int} startIndex
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getAssignedTickets = function (personId, startIndex) {
|
|
var params = {}, filters = [{ filter: 'assignees', option: 'me' }, { filter: 'statuses', option: 'allOpen' }], filterAssigneeMe = _.find(personModel.filterDict.assignees.options, { label: 'me' });
|
|
filterAssigneeMe.criteria.value = [{ loginId: personId }];
|
|
params.filterCriteria = getFilterCriteria(filters);
|
|
params.chunkInfo = {
|
|
startIndex: startIndex || 0,
|
|
chunkSize: personModel.defaultChunkSize
|
|
};
|
|
params.sortInfo = { sortFieldName: 'modifiedDate', sortFieldOrder: 'DESC' };
|
|
return personService.getAssignedTickets(params).then(function (data) {
|
|
if (startIndex > 0) {
|
|
var tickets = _.union(personModel.personAssignedTickets.ticketList, data.ticketList);
|
|
personModel.personAssignedTickets.ticketList = _.sortBy(tickets, 'modifiedDate').reverse();
|
|
}
|
|
else {
|
|
personModel.personAssignedTickets.ticketList = data.ticketList;
|
|
}
|
|
personModel.personAssignedTickets.totalMatches = data.totalMatches;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch all knowledge articles authored by a person with personId
|
|
*
|
|
* @param {String} personId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
personModel.getKnowledgeArticles = function (personId) {
|
|
var params = { authoredBy: { loginId: personId } };
|
|
return personService.getKnowledgeArticles(params).then(function (data) {
|
|
personModel.personKnowledgeArticles = data;
|
|
});
|
|
};
|
|
personModel.searchPersonInSocialByNameQuery = function (keyword) {
|
|
if (!keyword) {
|
|
return $q.when([]);
|
|
}
|
|
return personService.searchPersonInSocialByNameQuery(keyword);
|
|
};
|
|
personModel.updatePersonInfo = function (id, data) {
|
|
return personService.updatePersonInfo(id, data).then(function (personData) {
|
|
personModel.personDetails = _.merge(personModel.personDetails, personData);
|
|
if (userModel.userFullData.id === personData.id) {
|
|
userModel.userFullData = _.merge(userModel.userFullData, personData);
|
|
}
|
|
}).catch(function (error) {
|
|
if (error) {
|
|
systemAlertService.error({
|
|
text: error.data.error,
|
|
clear: false
|
|
});
|
|
}
|
|
return $q.reject(error);
|
|
});
|
|
};
|
|
personModel.getOrganizationList = function (companyName) {
|
|
return personService.getOrganizationList(companyName);
|
|
};
|
|
personModel.getDepartmentList = function (organizationName, companyName) {
|
|
return personService.getDepartmentList(organizationName, companyName);
|
|
};
|
|
personModel.getSiteList = function (companyName) {
|
|
return personService.getSiteList(companyName);
|
|
};
|
|
personModel.followPerson = function (userLoginId, personId) {
|
|
return personService.followPerson(userLoginId, personId);
|
|
};
|
|
personModel.unfollowPerson = function (userLoginId, personId) {
|
|
return personService.unfollowPerson(userLoginId, personId);
|
|
};
|
|
personModel.createPerson = function (personData) {
|
|
var params = {
|
|
firstName: personData.firstName,
|
|
middleName: personData.middleName,
|
|
lastName: personData.lastName,
|
|
email: personData.email,
|
|
company: personData.company,
|
|
clientType: personData.clientType ? personData.clientType.name : undefined,
|
|
clientSensitivity: personData.clientSensitivity ? personData.clientSensitivity.name : undefined,
|
|
contactType: personData.contactType ? personData.contactType.name : undefined,
|
|
isVIP: personData.isVIP.name === 'Yes',
|
|
jobTitle: personData.jobTitle,
|
|
organization: personData.organization,
|
|
department: personData.department,
|
|
site: personData.site && personData.site.name ? personData.site : {},
|
|
phone: personData.phone,
|
|
fax: personData.fax,
|
|
cell: personData.cell,
|
|
corporateId: personData.corporateId,
|
|
loginId: personData.loginId
|
|
};
|
|
return personService.createPerson(params).then(function (result) {
|
|
return result;
|
|
});
|
|
};
|
|
// Private functions
|
|
function getFilterCriteria(defaultFilters) {
|
|
var params = {};
|
|
_.forEach(defaultFilters, function (item) {
|
|
if (personModel.filterDict[item.filter]) {
|
|
var option = _.find(personModel.filterDict[item.filter].options, { name: item.option });
|
|
var name = option.criteria.name;
|
|
params[name] = option.criteria.value;
|
|
}
|
|
});
|
|
return params;
|
|
}
|
|
return personModel;
|
|
}
|
|
]);
|
|
}());
|