554 lines
27 KiB
JavaScript
554 lines
27 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('searchModule').service('searchService', ['$resource', 'utilityFunctions', function ($resource, utilityFunctions) {
|
|
var resource = $resource('/smartit/rest/v2/search', {}, {
|
|
getSmartSearchResults: {
|
|
url: '/smartit/rest/smartsearch?search_text=:searchText',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getSuggestedSearchResults: {
|
|
url: '/smartit/rest/globalsearch/suggest/search',
|
|
method: 'GET',
|
|
isArray: false,
|
|
transformResponse: function (data) {
|
|
return { results: angular.fromJson(data) };
|
|
}
|
|
},
|
|
getGlobalSearchResults: {
|
|
url: '/smartit/rest/globalsearch',
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
isArray: true
|
|
},
|
|
getSites: {
|
|
url: '/smartit/rest/foundation/search/site',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getList: {
|
|
url: '/smartit/rest/foundation/items',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getAssigneeByText: {
|
|
url: '/smartit/rest/foundation/items',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getCompaniesByText: {
|
|
url: '/smartit/rest/foundation/items',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getSupportGroupsList: {
|
|
url: '/smartit/rest/person/search/supportgroup',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getListOfServiceByText: {
|
|
url: '/smartit/rest/asset/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getOutages: {
|
|
url: '/smartit/rest/outage/search',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getFilteredOutagesList: {
|
|
url: '/smartit/rest/outage/search/filter',
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
isArray: true
|
|
},
|
|
getFilteredOutagesListMock: {
|
|
url: 'mocks/suggested-outages-list.json',
|
|
isArray: true,
|
|
method: 'GET'
|
|
},
|
|
searchCIsRelatedToChangeRequestByCriteria: {
|
|
url: '/smartit/rest/asset/list/get',
|
|
isArray: true,
|
|
method: 'POST'
|
|
},
|
|
getListForAssignee: {
|
|
url: '/smartit/rest/foundation/assignment/items',
|
|
isArray: true,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
method: 'POST'
|
|
},
|
|
getAssigneeSupportGroupsList: {
|
|
url: '/smartit/rest/foundation/assignment/supportgroup',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
getRecommendedSupportGroupsList: {
|
|
url: '/smartit/rest/foundation/recommendation/:ticketType/supportgroup',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
getRequestForRelatedTicket: {
|
|
url: '/smartit/rest/request/search/:id',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getLiveAgentDefaultSupportGroup: {
|
|
url: '/smartit/rest/foundation/supportgroup/:customerCompany',
|
|
method: 'GET',
|
|
isArray: true
|
|
},
|
|
getHKMRecommendedKA: {
|
|
url: '/smartit/rest/knowledge/search',
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
getHKMUrls: {
|
|
url: '/smartit/rest/knowledge/hkmurls',
|
|
method: 'GET',
|
|
isArray: true
|
|
}
|
|
});
|
|
var searchResultsCategoryOrderMap = {
|
|
tickets: 1,
|
|
knowledge: 2,
|
|
asset: 3,
|
|
person: 4
|
|
};
|
|
this.targetArea = { selectedTargetArea: null };
|
|
/**
|
|
* Public functions
|
|
*/
|
|
this.setSelectedTargetArea = function (targetArea) {
|
|
this.targetArea.selectedTargetArea = targetArea;
|
|
};
|
|
this.getSelectedTargetArea = function () {
|
|
return this.targetArea.selectedTargetArea;
|
|
};
|
|
this.getSmartSearchResults = function (searchText) {
|
|
return resource.getSmartSearchResults({ searchText: searchText }).$promise.then(function (data) {
|
|
return processSmartSearchResultsData(data);
|
|
});
|
|
};
|
|
this.getSuggestedSearchResults = function (searchText) {
|
|
return resource.getSuggestedSearchResults({ text: searchText }).$promise.then(function (data) {
|
|
return processSuggestedSearchResults(data.results || []);
|
|
});
|
|
};
|
|
this.getGlobalSearchResults = function (params, filters) {
|
|
return resource.getGlobalSearchResults(params, filters).$promise.then(function (data) {
|
|
return processGlobalSearchResultsData(data);
|
|
});
|
|
};
|
|
this.getHKMRecommendedKA = function (params, filters) {
|
|
return resource.getHKMRecommendedKA(params, filters).$promise.then(function (data) {
|
|
return processGlobalSearchResultsData(data);
|
|
});
|
|
};
|
|
this.getOrganizationsByText = function (searchText) {
|
|
var params = {
|
|
type: 'organization',
|
|
searchText: searchText
|
|
};
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
return _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
});
|
|
};
|
|
this.getOrganizationsByCompany = function (companyName, searchText) {
|
|
var params = {
|
|
type: 'organization',
|
|
searchOptions: { companyName: companyName },
|
|
searchText: searchText
|
|
};
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var data = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { organizations: data, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getOrganizationsByTextAndCompany = function (searchText, companyName) {
|
|
var params = {
|
|
type: 'organization',
|
|
searchText: searchText,
|
|
searchOptions: { companyName: companyName }
|
|
};
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var data = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { items: data, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getSupportOrganizationsByText = function (searchText) {
|
|
var params = {
|
|
type: 'supportOrganization',
|
|
searchText: searchText
|
|
};
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { organizations: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getAssigneeSupportOrgByCompany = function (searchOptions, chunkInfo) {
|
|
var params = {
|
|
type: 'supportOrganization'
|
|
};
|
|
if (chunkInfo) {
|
|
params.chunkInfo = chunkInfo;
|
|
}
|
|
return resource.getListForAssignee(params, searchOptions).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { organizations: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getSupportOrganizationsByCompany = function (searchOptions, chunkInfo) {
|
|
var params = {
|
|
type: 'supportOrganization',
|
|
searchOptions: searchOptions
|
|
};
|
|
if (chunkInfo) {
|
|
params.chunkInfo = chunkInfo;
|
|
}
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { organizations: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getSupportOrganizationsByTextAndCompany = function (searchText, searchOptions) {
|
|
var params = {
|
|
type: 'supportOrganization',
|
|
// chunking not yet working at backend, will uncomment once backend is fixed
|
|
// chunkInfo: { startIndex: 0, chunkSize: chunkSize },
|
|
searchText: searchText,
|
|
searchOptions: searchOptions
|
|
};
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { organizations: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getDepartmentsByCompany = function (companyName, searchText) {
|
|
var params = {
|
|
type: 'department',
|
|
searchOptions: { companyName: companyName },
|
|
searchText: searchText
|
|
};
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
return { organizations: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getAssigneeByText = function (searchText) {
|
|
var params = {
|
|
type: 'assignee',
|
|
searchText: searchText
|
|
};
|
|
return resource.getAssigneeByText(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getCompaniesByText = function (searchText, attrs) {
|
|
var params = {
|
|
type: 'company',
|
|
searchText: searchText
|
|
};
|
|
_.assign(params, attrs);
|
|
return resource.getCompaniesByText(params).$promise.then(function (result) {
|
|
var items = result[0].items[0];
|
|
return { companies: items.objects, exceedsChunkSize: items.exceedsChunkSize, totalMatches: items.totalMatches };
|
|
});
|
|
};
|
|
this.getSupportCompaniesByText = function (searchText, attrs) {
|
|
var params = {
|
|
type: 'supportCompany',
|
|
searchText: searchText
|
|
};
|
|
_.assign(params, attrs);
|
|
return resource.getCompaniesByText(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getAssigneeSupportCompaniesByText = function (searchText, attrs, options) {
|
|
var params = {
|
|
type: 'assigneeSupportCompany',
|
|
searchText: searchText
|
|
};
|
|
_.assign(params, attrs);
|
|
return resource.getListForAssignee(params, options).$promise.then(function (result) {
|
|
return { objects: result[0].items[0].objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getSupportGroupsList = function (params) {
|
|
return resource.getSupportGroupsList(params).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (group) {
|
|
return new SupportGroupVO().build(group);
|
|
});
|
|
return { supportGroups: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getAssigneeSupportGroupsList = function (urlParams, payloadParams) {
|
|
return resource.getAssigneeSupportGroupsList(urlParams, payloadParams).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (group) {
|
|
return new SupportGroupVO().build(group);
|
|
});
|
|
return { supportGroups: objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getRecommendedSupportGroupsList = function (urlParams, payloadParams) {
|
|
return resource.getRecommendedSupportGroupsList(urlParams, payloadParams).$promise.then(function (result) {
|
|
var objects = _.map(result[0].items[0].objects, function (group) {
|
|
return new SupportGroupVO().build(group);
|
|
});
|
|
return { supportGroups: objects };
|
|
});
|
|
};
|
|
this.getApproverSupportCompanies = function (searchText, attrs, ticketType) {
|
|
var params = {
|
|
searchText: searchText,
|
|
type: 'approverSupportCompany',
|
|
searchOptions: {
|
|
role: (ticketType && ticketType === EntityVO.TYPE_RELEASE) ? 'releaseapprover' : 'changeapprover',
|
|
}
|
|
};
|
|
_.assign(params, attrs);
|
|
return resource.getCompaniesByText(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getApproverSupportOrganizations = function (searchText, searchOptions, chunkInfo) {
|
|
var params = {
|
|
type: 'approverSupportOrganization',
|
|
searchOptions: searchOptions
|
|
};
|
|
if (searchText && searchText.length > 0) {
|
|
params.searchText = searchText;
|
|
}
|
|
if (chunkInfo) {
|
|
params.chunkInfo = chunkInfo;
|
|
}
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
return _.map(result[0].items[0].objects, function (org) {
|
|
return new OrganizationVO().build(org);
|
|
});
|
|
});
|
|
};
|
|
this.getFoundationItems = function (params) {
|
|
return resource.getList(params).$promise.then(function (result) {
|
|
var items = result[0].items[0];
|
|
return { foundationItems: items.objects, exceedsChunkSize: items.exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getSitesByText = function (searchText) {
|
|
return resource.getSites({ searchText: searchText }).$promise.then(function (result) {
|
|
return { list: result[0].items[0].objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getSitesObjectByText = function (searchText) {
|
|
return resource.getSites({ searchText: searchText }).$promise.then(function (result) {
|
|
return _.map(result[0].items[0].objects, function (site) {
|
|
return new SiteVO().build(site);
|
|
});
|
|
});
|
|
};
|
|
this.getOutages = function (searchParams) {
|
|
return resource.getOutages(searchParams).$promise.then(function (result) {
|
|
return _.map(result[0].items[0].objects, function (outage) {
|
|
return new OutageVO().build(outage);
|
|
});
|
|
});
|
|
};
|
|
this.getSitesByCompany = function (companyName) {
|
|
var params = {
|
|
companyName: companyName,
|
|
searchText: '%' //Viktor: temp workaround, backend does not support call without searchtext, todo: remove after change
|
|
};
|
|
return resource.getSites(params).$promise.then(function (result) {
|
|
return result[0].items[0];
|
|
});
|
|
};
|
|
this.getSitesByTextAndCompany = function (searchText, companyName) {
|
|
var params = {
|
|
searchText: searchText,
|
|
companyName: companyName
|
|
};
|
|
return resource.getSites(params).$promise.then(function (result) {
|
|
return { list: result[0].items[0].objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
this.getListOfServiceByText = function (searchText, companyName) {
|
|
var params = {
|
|
searchParam: searchText,
|
|
company: { name: companyName },
|
|
assetType: 'Business Service'
|
|
};
|
|
return resource.getListOfServiceByText(params).$promise.then(function (result) {
|
|
return result[0].items[0].objects;
|
|
});
|
|
};
|
|
this.getListObjOfServiceByText = function (searchText, companyName) {
|
|
var params = {
|
|
searchParam: searchText,
|
|
company: { name: companyName },
|
|
assetType: 'Business Service'
|
|
};
|
|
return resource.getListOfServiceByText(params).$promise.then(function (result) {
|
|
return { list: result[0].items[0].objects, exceedsChunkSize: result[0].items[0].exceedsChunkSize };
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.searchService#getFilteredSuggestedOutagesList
|
|
*
|
|
* @description
|
|
* Get list of Outages based on the criteria
|
|
* @param {Object} filters - Filters object, used for generating Outage filtering request
|
|
* @param {Boolean} filters.relatedCI - would filter Outages that are related to CIs, which have a relation to the ticket.
|
|
* @param {String} filters.searchText - would filter only Outages that have a matching by this value
|
|
* @param {String} filters.ciNames - would filter only Outages that have relation to CIs, which names are matching this value
|
|
* @param {Array} filters.unavailabilityType - would filter only Outages with Unavailability type matching any value in this array
|
|
* @param {Array} filters.unavailabilityStatus - would filter only Outages with Unavailability Status matching any value in this array
|
|
* @param {Array} filters.scheduledDate - Outage unavailability scheduled date filter object
|
|
* @param {Timestamp} filters.scheduledDate[].start - Outage unavailability scheduled date start value
|
|
* @param {Timestamp} filters.scheduledDate[].end - Outage unavailability scheduled date end value
|
|
* @param {Object} ticket - Ticket information (Optional)
|
|
* @param {String} ticket.id - Unique id of the ticket. Outages will be filtered based on the relation to this ticket
|
|
* @param {String} ticket.type - Ticket type value
|
|
*/
|
|
this.getFilteredOutagesList = function (filters, ticket) {
|
|
var defaultFilters = {
|
|
relatedCI: false,
|
|
searchText: '',
|
|
ciNames: '',
|
|
unavailabilityType: [],
|
|
unavailabilityStatus: [],
|
|
scheduledDate: []
|
|
}, requestFilters = {};
|
|
if (ticket && ticket.id && ticket.type) {
|
|
requestFilters.attributeMap = { id: ticket.id, ticketType: ticket.type };
|
|
}
|
|
_.each(defaultFilters, function (filter, key) {
|
|
if (filters[key]) {
|
|
requestFilters[key] = filters[key];
|
|
}
|
|
});
|
|
if (requestFilters.ciNames) {
|
|
if (requestFilters.relatedCI) {
|
|
requestFilters.relatedCI = false;
|
|
}
|
|
}
|
|
var params = { filterCriteria: { outageCriteria: requestFilters } };
|
|
//promise = requestFilters.relatedCI ? resource.getFilteredOutagesListMock().$promise : resource.getFilteredOutagesList(params).$promise;
|
|
return resource.getFilteredOutagesList(params).$promise
|
|
.then(function (data) {
|
|
var responseObjects = data[0] && data[0].items || [], filteredOutages = responseObjects[0] && responseObjects[0].objects || [];
|
|
return _.map(filteredOutages, function (outage) {
|
|
return new OutageVO().build(outage);
|
|
});
|
|
});
|
|
};
|
|
this.searchCIsRelatedToChangeRequestByCriteria = function (params, ticket, chunkInfo) {
|
|
var defaultParams = {
|
|
chunkInfo: {
|
|
chunkSize: 100,
|
|
startIndex: 0
|
|
},
|
|
filterCriteria: {
|
|
relatedCI: true,
|
|
attributeMap: {
|
|
id: ticket && ticket.id,
|
|
ticketType: EntityVO.TYPE_CHANGE
|
|
}
|
|
}
|
|
};
|
|
angular.extend(defaultParams.filterCriteria, params);
|
|
if (chunkInfo) {
|
|
angular.extend(defaultParams.chunkInfo, chunkInfo);
|
|
}
|
|
return resource.searchCIsRelatedToChangeRequestByCriteria({ source: 'cioutages' }, defaultParams).$promise
|
|
.then(function (data) {
|
|
var assetList = [];
|
|
try {
|
|
assetList = _.uniqBy(data[0].items[0].objects, function (ci) {
|
|
return ci.reconciliationId;
|
|
});
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
}
|
|
assetList.forEach(function (asset) {
|
|
return new AssetVO().build(asset);
|
|
});
|
|
return assetList;
|
|
});
|
|
};
|
|
/**
|
|
* Private functions
|
|
*/
|
|
function processSmartSearchResultsData(data) {
|
|
var searchResults = data[0] && data[0].items || [];
|
|
searchResults.forEach(function (value) {
|
|
value.results = value.results.map(function (item) {
|
|
return new GlobalSearchItemVO().build(item);
|
|
});
|
|
});
|
|
return searchResults;
|
|
}
|
|
function processSuggestedSearchResults(list) {
|
|
var result = [];
|
|
_.forEach(list, function (item) {
|
|
result.push(utilityFunctions.escapeHTML(item));
|
|
});
|
|
return result;
|
|
}
|
|
function processGlobalSearchResultsData(data) {
|
|
var searchResults = {
|
|
items: data[0] && data[0].items || [],
|
|
totalCount: 0
|
|
};
|
|
_.forEach(searchResults.items, function (item) {
|
|
searchResults.totalCount += item.totalCount;
|
|
item.active = true;
|
|
item.sortOrder = searchResultsCategoryOrderMap[item.searchCategory] || 100;
|
|
item.results = _.map(item.results, function (result) {
|
|
result = new GlobalSearchItemVO().build(result);
|
|
if (result.additionalInformation.accessMappings) {
|
|
result.additionalInformation.accessMappings = new AccessMappingVO().parseAccessMap(result.additionalInformation.accessMappings);
|
|
}
|
|
return result;
|
|
});
|
|
});
|
|
searchResults.items = _.sortBy(searchResults.items, 'sortOrder');
|
|
return searchResults;
|
|
}
|
|
this.getRequestForRelatedTicket = function (id) {
|
|
return resource.getRequestForRelatedTicket({ id: id }).$promise.then(function (response) {
|
|
return response[0].items[0] || undefined;
|
|
});
|
|
};
|
|
this.getLiveAgentDefaultSupportGroup = function (customerCompany) {
|
|
return resource.getLiveAgentDefaultSupportGroup({ customerCompany: customerCompany }).$promise.then(function (response) {
|
|
return response[0].items[0] || undefined;
|
|
});
|
|
};
|
|
this.getHKMUrls = function () {
|
|
return resource.getHKMUrls().$promise.then(function (response) {
|
|
return response[0].items[0] || undefined;
|
|
});
|
|
};
|
|
}]);
|
|
}());
|