304 lines
13 KiB
JavaScript
304 lines
13 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('personModule')
|
|
.service('personService', ['$resource', '$http', function ($resource, $http) {
|
|
var resource = $resource('/smartit/rest/person/:id', {}, {
|
|
getPersonDetailsByID: {
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getListOfPersonByName: {
|
|
method: 'GET',
|
|
url: '/smartit/rest/person/search?name=:name&thumbnail=:thumbnail',
|
|
isArray: true
|
|
},
|
|
getPersonAssets: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: '/smartit/rest/asset/:id?allAssets=:showAllAssets'
|
|
},
|
|
getTickets: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/v2/person/workitems/get'
|
|
},
|
|
getServiceBrokerTickets: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/sberequest/workitems'
|
|
},
|
|
searchPersonInSocialByNameQuery: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: '/smartit/rest/v2/profile',
|
|
params: {
|
|
type: 'user',
|
|
search_types: 'user',
|
|
fields: 'elementId,jid,tenantId,firstName,lastName'
|
|
}
|
|
},
|
|
getServiceSummaryStats: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/foundation/stats/get'
|
|
},
|
|
updatePersonInfo: {
|
|
method: 'PUT',
|
|
isArray: true,
|
|
url: '/smartit/rest/person/all/:id'
|
|
},
|
|
getOrganizationList: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/foundation/items?type=organization'
|
|
},
|
|
getDepartmentList: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/foundation/items?type=department'
|
|
},
|
|
getSiteList: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: '/smartit/rest/foundation/search/site?searchText=%&companyName=:companyName'
|
|
},
|
|
getKnowledgeArticlesList: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: '/smartit/rest/knowledge'
|
|
},
|
|
createPerson: {
|
|
method: 'POST',
|
|
isArray: true,
|
|
url: '/smartit/rest/person'
|
|
},
|
|
getServiceBrokerTicketsMock: {
|
|
method: 'GET',
|
|
isArray: true,
|
|
url: 'mocks/user-sberequest-workitems.json'
|
|
}
|
|
});
|
|
this.getPersonDetailsByID = function (id) {
|
|
return resource.getPersonDetailsByID({ id: id }).$promise.then(function (result) {
|
|
return processPersonDetails(result[0].items[0]);
|
|
});
|
|
};
|
|
this.getListOfPersonByName = function (searchText, skipResultProcessing, role) {
|
|
var params;
|
|
if (angular.isDefined(role)) {
|
|
params = { name: searchText, thumbnail: true, role: role };
|
|
}
|
|
else {
|
|
params = { name: searchText, thumbnail: true };
|
|
}
|
|
return resource.getListOfPersonByName(params).$promise
|
|
.then(function (result) {
|
|
if (result[0].items.length) {
|
|
if (skipResultProcessing) {
|
|
return result[0].items;
|
|
}
|
|
var personList = result[0].items;
|
|
var updatedPersonList = personList.map(function (item) {
|
|
return processPersonDetails(item);
|
|
});
|
|
return updatedPersonList;
|
|
}
|
|
return [];
|
|
});
|
|
};
|
|
this.getListOfPersonNamesByName = function (searchText) {
|
|
return resource.getListOfPersonByName({ name: searchText, thumbnail: false }).$promise
|
|
.then(function (result) {
|
|
if (result[0].items.length) {
|
|
var personList = result[0].items;
|
|
var updatedPersonList = personList.map(function (item) {
|
|
return processPersonDetails(item);
|
|
});
|
|
return updatedPersonList;
|
|
}
|
|
return [];
|
|
});
|
|
};
|
|
this.getPersonAssets = function (personId, showAllAssets) {
|
|
return resource.getPersonAssets({
|
|
id: personId,
|
|
showAllAssets: showAllAssets
|
|
}).$promise.then(function (result) {
|
|
return processPersonAssetList(result[0].items[0].objects);
|
|
});
|
|
};
|
|
this.getTickets = function (params) {
|
|
var criteria = composeFilterCriteria(params.filterCriteria);
|
|
criteria.chunkInfo = params.chunkInfo;
|
|
if (params.sortInfo) {
|
|
criteria.sortInfo = params.sortInfo;
|
|
}
|
|
return resource.getTickets(criteria).$promise.then(function (result) {
|
|
return {
|
|
ticketList: processTicketsList(result[0].items[0].objects),
|
|
totalMatches: result[0].items[0].totalMatches
|
|
};
|
|
});
|
|
};
|
|
this.getServiceBrokerTickets = function (params) {
|
|
var criteria = composeFilterCriteria(params.filterCriteria);
|
|
criteria.chunkInfo = params.chunkInfo;
|
|
if (params.sortInfo) {
|
|
criteria.sortInfo = params.sortInfo;
|
|
}
|
|
return resource.getServiceBrokerTickets(criteria).$promise.then(function (result) {
|
|
return {
|
|
ticketList: processTicketsList(result[0].items[0].objects),
|
|
totalMatches: result[0].items[0].totalMatches
|
|
};
|
|
});
|
|
};
|
|
this.getAssignedTickets = function (params) {
|
|
var criteria = composeFilterCriteria(params.filterCriteria);
|
|
criteria.chunkInfo = params.chunkInfo;
|
|
criteria.sortInfo = params.sortInfo;
|
|
return resource.getTickets(criteria).$promise.then(function (result) {
|
|
return {
|
|
ticketList: processTicketsList(result[0].items[0].objects),
|
|
totalMatches: result[0].items[0].totalMatches
|
|
};
|
|
});
|
|
};
|
|
this.getKnowledgeArticles = function (params) {
|
|
var criteria = { criteria: params };
|
|
return resource.getKnowledgeArticlesList(criteria).$promise.then(function (result) {
|
|
if (result[0].items.length > 0) {
|
|
return _.map(result[0].items[0].objects, function (article) {
|
|
return new KnowledgeArticleVO().build(article);
|
|
});
|
|
}
|
|
else {
|
|
return [];
|
|
}
|
|
});
|
|
};
|
|
this.searchPersonInSocialByNameQuery = function (keyword) {
|
|
return resource.searchPersonInSocialByNameQuery({ search_string: keyword }).$promise.then(function (searchResult) {
|
|
return searchResult[0].items;
|
|
});
|
|
};
|
|
this.updatePersonInfo = function (id, data) {
|
|
return resource.updatePersonInfo({ id: id }, data).$promise.then(function (result) {
|
|
return processPersonDetails(result[0].items[0].responseObject);
|
|
});
|
|
};
|
|
this.getOrganizationList = function (companyName) {
|
|
var params = angular.toJson({ companyName: companyName });
|
|
return resource.getOrganizationList(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getDepartmentList = function (organizationName, companyName) {
|
|
var params = angular.toJson({
|
|
organizationName: organizationName,
|
|
companyName: companyName
|
|
});
|
|
return resource.getDepartmentList(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getSiteList = function (companyName) {
|
|
return resource.getSiteList({ companyName: companyName }).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getServiceSummaryStats = function (loginId) {
|
|
var params = {
|
|
filterCriteria: {
|
|
customer: { loginId: loginId }
|
|
},
|
|
stats: [{ name: 'service-summary' }]
|
|
};
|
|
return resource.getServiceSummaryStats(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.followPerson = function (userLoginId, personId) {
|
|
return $http({
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
url: '/smartit/rest/v2/profile/user/' + userLoginId + '/following?follow_type=user&following_id=' + personId
|
|
});
|
|
};
|
|
this.unfollowPerson = function (userLoginId, personId) {
|
|
return $http({
|
|
method: 'DELETE',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
url: '/smartit/rest/v2/profile/user/' + userLoginId + '/following?follow_type=user&following_id=' + personId
|
|
});
|
|
};
|
|
this.createPerson = function (params) {
|
|
return resource.createPerson(params).$promise.then(function (result) {
|
|
return result[0].items[0];
|
|
});
|
|
};
|
|
/**
|
|
* Private functions
|
|
*/
|
|
/**
|
|
* Process raw data from server and transform it to VO.
|
|
*
|
|
* @param data
|
|
* @return {PersonProfileVO}
|
|
*/
|
|
function processPersonDetails(data) {
|
|
return new PersonProfileVO().build(data);
|
|
}
|
|
/**
|
|
* Process asset list from server.
|
|
*
|
|
* @param {Array} data
|
|
*/
|
|
function processPersonAssetList(data) {
|
|
var assetList = [];
|
|
angular.forEach(data, function (item) {
|
|
var personAssetItem = new PersonAssetVO().build(item);
|
|
assetList.push(personAssetItem);
|
|
});
|
|
return assetList;
|
|
}
|
|
/**
|
|
* Process tickets list from server.
|
|
*
|
|
* @param {Array} data
|
|
*/
|
|
function processTicketsList(data) {
|
|
var ticketsList = data;
|
|
for (var i = 0; i < ticketsList.length; i++) {
|
|
ticketsList[i] = processTicketItem(ticketsList[i]);
|
|
if (ticketsList[i].status === 'Resolved' || ticketsList[i].status === 'Closed') {
|
|
ticketsList[i].closedDate = moment(ticketsList[i].modifiedDate).fromNow();
|
|
}
|
|
else {
|
|
ticketsList[i].receivedDate = moment(ticketsList[i].modifiedDate).calendar();
|
|
}
|
|
}
|
|
return _.sortBy(ticketsList, 'modifiedDate').reverse();
|
|
}
|
|
/**
|
|
* Process raw data from server and transform it to VO.
|
|
*
|
|
* @param item
|
|
* @return {TicketSummaryVO}
|
|
*/
|
|
function processTicketItem(item) {
|
|
return new TicketSummaryVO().build(item);
|
|
}
|
|
/**
|
|
* Compose filterCriteria for tickets
|
|
*/
|
|
function composeFilterCriteria(criteria) {
|
|
return {
|
|
filterCriteria: criteria,
|
|
attributeNames: ['displayId', 'type', 'summary', 'submitDate', 'modifiedDate', 'assignee', 'status']
|
|
};
|
|
}
|
|
}]);
|
|
}());
|