935 lines
49 KiB
JavaScript
935 lines
49 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('searchModule')
|
|
.factory('searchModel', ['configurationModel', 'permissionModel', '$rootScope', 'searchService', '$q', 'roles', 'userModel', 'metadataModel', 'assetService', 'systemAlertService',
|
|
function (configurationModel, permissionModel, $rootScope, searchService, $q, roles, userModel, metadataModel, assetService, systemAlertService) {
|
|
var searchModel = {
|
|
siteCache: {},
|
|
groupsCache: {},
|
|
SupportOrganizationsCache: {},
|
|
approverSupportOrganizationsCache: {},
|
|
approverGroupsCache: {},
|
|
allGroups: null
|
|
};
|
|
var cacheHKMUrls = null;
|
|
searchModel.globalSearchResults = [];
|
|
searchModel.hkmSearchResults = [];
|
|
searchModel.smartSearchResults = [];
|
|
searchModel.selectedFilters = [];
|
|
searchModel.filterCriteria = {};
|
|
searchModel.filterConfig = {};
|
|
searchModel.categoriesConfig = configurationModel.get('search.categories');
|
|
searchModel.sbeConfig = {
|
|
name: 'sberequest',
|
|
totalCount: 0,
|
|
types: ['sberequest']
|
|
};
|
|
searchModel.chunkSize = 50;
|
|
// there will be a long team solution to handle various typeahead chuck size
|
|
// for now we will set it here
|
|
searchModel.companyChunkSize = 80;
|
|
searchModel.siteChunkSize = 100;
|
|
searchModel.organizationChunkSize = 80;
|
|
searchModel.supportGroupChunkSize = 80;
|
|
searchModel.regionChunkSize = 80;
|
|
searchModel.locationSiteChunkSize = 80;
|
|
searchModel.departmentChunkSize = 80;
|
|
searchModel.siteGroupChunkSize = 80;
|
|
searchModel.supportPersonChunkSize = 80;
|
|
searchModel.inventoryChunkSize = 80;
|
|
searchModel.isFilterConfigLoaded = false;
|
|
searchModel.isSBEIntegrationEnabled = true;
|
|
searchModel.useChunkingForOperatingCompanies = true;
|
|
searchModel.init = function () {
|
|
// overwrite the default if backend has global setting for chucksize
|
|
metadataModel.getMetadataByType(EntityVO.TYPE_GLOBAL).then(function () {
|
|
if (configurationModel.companyChunkSize) {
|
|
searchModel.companyChunkSize = configurationModel.companyChunkSize;
|
|
}
|
|
if (configurationModel.organizationChunkSize) {
|
|
searchModel.organizationChunkSize = configurationModel.organizationChunkSize;
|
|
}
|
|
if (configurationModel.supportGroupChunkSize) {
|
|
searchModel.supportGroupChunkSize = configurationModel.supportGroupChunkSize;
|
|
}
|
|
if (configurationModel.supportPersonChunkSize) {
|
|
searchModel.supportPersonChunkSize = configurationModel.supportPersonChunkSize;
|
|
}
|
|
if (configurationModel.disableCollisionManagement) {
|
|
searchModel.disableCollisionManagement = configurationModel.disableCollisionManagement;
|
|
}
|
|
if (configurationModel.disableImpactAnalysis) {
|
|
searchModel.disableImpactAnalysis = configurationModel.disableImpactAnalysis;
|
|
}
|
|
if (configurationModel.locationSiteChunkSize) {
|
|
searchModel.locationSiteChunkSize = configurationModel.locationSiteChunkSize;
|
|
}
|
|
});
|
|
userModel.getFullCurrentUserData().then(function (user) {
|
|
initFilterConfig(user);
|
|
});
|
|
};
|
|
function initFilterConfig(user) {
|
|
var filterDict = {};
|
|
searchModel.filterConfig = configurationModel.get('search.filter');
|
|
if (user && user.accessRestrictions && user.accessRestrictions.length <= 1) {
|
|
_.remove(searchModel.filterConfig, { name: 'searchCompanies' });
|
|
}
|
|
//TODO: make this configuration based
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_SERVICEREQUEST)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_SERVICEREQUEST;
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_WORKORDER)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_WORKORDER;
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_KNOWLEDGE) || !permissionModel.hasRole(roles.ITSM_KNOWLEDGE_USER_ROLE)
|
|
|| configurationModel.comaroundEnabled) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_KNOWLEDGE;
|
|
});
|
|
}
|
|
if (!permissionModel.hasRole(roles.ITSM_AGENT_ROLE)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return _.includes([EntityVO.TYPE_INCIDENT, EntityVO.TYPE_SERVICEREQUEST, EntityVO.TYPE_WORKORDER], item.name);
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_CHANGE) || !permissionModel.hasRole(roles.ITSM_CHANGE_USER_ROLE)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_CHANGE;
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_RELEASE) || !permissionModel.hasRole(roles.ITSM_RELEASE_USER_ROLE)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_RELEASE || item.name === EntityVO.TYPE_ACTIVITY;
|
|
});
|
|
}
|
|
if (!permissionModel.hasRole(roles.ITSM_AGENT_ROLE) && !permissionModel.hasRole(roles.ITSM_CHANGE_USER_ROLE)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_TASK;
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_KNOWNERROR) || !permissionModel.hasRole(roles.ITSM_PROBLEM_USER_ROLE)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_KNOWNERROR;
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_PROBLEM) || !permissionModel.hasRole(roles.ITSM_PROBLEM_USER_ROLE)) {
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_PROBLEM;
|
|
});
|
|
}
|
|
if (!configurationModel.isServerApplicationEnabled(EntityVO.TYPE_SBEREQUEST) || !permissionModel.hasRole(roles.ITSM_SBE_USER_ROLE)) {
|
|
searchModel.isSBEIntegrationEnabled = false;
|
|
filterDict = _.keyBy(searchModel.filterConfig, 'name');
|
|
filterDict.types.options = _.reject(filterDict.types.options, function (item) {
|
|
return item.name === EntityVO.TYPE_SBEREQUEST;
|
|
});
|
|
}
|
|
searchModel.isFilterConfigLoaded = true;
|
|
}
|
|
/**
|
|
* Run smart search
|
|
*
|
|
* @param searchText
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.runSmartSearch = function (searchText) {
|
|
return searchService.getSmartSearchResults(searchText).then(function (data) {
|
|
searchModel.smartSearchResults = data;
|
|
});
|
|
};
|
|
/**
|
|
*
|
|
* @param searchText
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.getSuggestedSearchResults = function (searchText) {
|
|
return searchService.getSuggestedSearchResults(searchText).then(function (result) {
|
|
searchModel.suggestedSearchResults = result;
|
|
return result;
|
|
});
|
|
};
|
|
/**
|
|
* Get first 50 (searchModel.chunkSize) results of the global search.
|
|
* @param searchText - the text being searched
|
|
* @param filters - applied filters
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.getGlobalSearchResults = function (searchText, filters, suggestSearch) {
|
|
return searchModel.loadMoreGlobalSearchResults(searchText, filters, 0, suggestSearch);
|
|
};
|
|
/**
|
|
* Loads results of the global search in amount of searchModel.chunkSize from the chunkIndex page.
|
|
* @param searchText - the text being searched
|
|
* @param filters - applied filters
|
|
* @param chunkIndex
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.loadMoreGlobalSearchResults = function (searchText, filters, chunkIndex, suggestSearch) {
|
|
var params = {
|
|
search_text: searchText,
|
|
chunk_index: chunkIndex,
|
|
suggest_search: suggestSearch && suggestSearch === true ? suggestSearch : false,
|
|
chunk_size: searchModel.chunkSize
|
|
};
|
|
filters = _.cloneDeep(filters); //To avoid overriding values in filter
|
|
if (configurationModel.comaroundEnabled && _.includes(filters.types, EntityVO.TYPE_KNOWLEDGE)) {
|
|
_.remove(filters.types, function (value) { return value === EntityVO.TYPE_KNOWLEDGE; });
|
|
}
|
|
//Dummy promise is passed if only knowledge is selected in filter
|
|
var globalSearchPromise = filters.types.length ? searchService.getGlobalSearchResults(params, filters) : $q.when(1);
|
|
return globalSearchPromise.catch(function (error) {
|
|
console.error("Search failure: " + JSON.stringify(error));
|
|
}).then(function (data) {
|
|
// Merge if not empty, infinite scrolling
|
|
if (chunkIndex) {
|
|
_.forEach(data.items, function (dataItem) {
|
|
var selectedCategoryItem = _.find(searchModel.globalSearchResults.items, function (item) {
|
|
return item.searchCategory === dataItem.searchCategory;
|
|
});
|
|
if (selectedCategoryItem) {
|
|
selectedCategoryItem.results = _.union(selectedCategoryItem.results, dataItem.results);
|
|
selectedCategoryItem.chunkIndex = dataItem.chunkIndex;
|
|
selectedCategoryItem.nextChunkIndex = dataItem.nextChunkIndex;
|
|
selectedCategoryItem.totalCount = dataItem.totalCount;
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
searchModel.globalSearchResults = data;
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
* Get first 50 (searchModel.chunkSize) results of the HKM search.
|
|
* @param searchText - the text being searched
|
|
* @param suggestSearch - if search text should appear in suggestions next time
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.getHKMSearchResults = function (searchText, suggestSearch) {
|
|
return searchModel.loadMoreHKMSearchResults(searchText, 0, suggestSearch);
|
|
};
|
|
/**
|
|
* Loads results of the knowledge search in amount of searchModel.chunkSize from the chunkIndex page.
|
|
* @param searchText - the text being searched
|
|
* @param chunkIndex
|
|
* @param suggestSearch - if search text should appear in suggestions next time
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.loadMoreHKMSearchResults = function (searchText, chunkIndex, suggestSearch) {
|
|
var hkmQueryParams = {
|
|
chunk_index: chunkIndex,
|
|
suggest_search: suggestSearch && suggestSearch === true ? suggestSearch : false,
|
|
chunk_size: searchModel.chunkSize
|
|
};
|
|
var postParams = {
|
|
search_text: searchText
|
|
};
|
|
return searchService.getHKMRecommendedKA(hkmQueryParams, postParams).then(function (data) {
|
|
// Merge if not empty, infinite scrolling
|
|
if (chunkIndex) {
|
|
_.forEach(data.items, function (dataItem) {
|
|
var selectedCategoryItem = _.find(searchModel.hkmSearchResults.items, function (item) {
|
|
return item.searchCategory === dataItem.searchCategory;
|
|
});
|
|
if (selectedCategoryItem) {
|
|
selectedCategoryItem.results = _.union(selectedCategoryItem.results, dataItem.results);
|
|
selectedCategoryItem.chunkIndex = dataItem.chunkIndex;
|
|
selectedCategoryItem.nextChunkIndex = dataItem.nextChunkIndex;
|
|
selectedCategoryItem.totalCount = dataItem.totalCount;
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
searchModel.hkmSearchResults = data;
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
*
|
|
* @param searchText
|
|
* @return {$promise|*}
|
|
*/
|
|
searchModel.getFoundationRegionsByText = function (searchText) {
|
|
var searchParams = {
|
|
type: 'region',
|
|
searchText: searchText
|
|
};
|
|
return searchService.getFoundationItems(searchParams).then(function (results) {
|
|
return results.foundationItems;
|
|
});
|
|
};
|
|
searchModel.getFoundationSiteGroupsByText = function (searchText) {
|
|
var searchParams = {
|
|
type: 'siteGroup',
|
|
searchText: searchText
|
|
};
|
|
return searchService.getFoundationItems(searchParams).then(function (results) {
|
|
return results.foundationItems;
|
|
});
|
|
};
|
|
searchModel.getFoundationSitesByText = function (searchText) {
|
|
var searchParams = {
|
|
type: 'site',
|
|
searchText: searchText
|
|
};
|
|
return searchService.getFoundationItems(searchParams).then(function (results) {
|
|
return results.foundationItems;
|
|
});
|
|
};
|
|
searchModel.getFoundationSitesObjectByText = function (searchText) {
|
|
var searchParams = {
|
|
type: 'site',
|
|
searchText: searchText
|
|
};
|
|
return searchService.getFoundationItems(searchParams).then(function (results) {
|
|
return results;
|
|
});
|
|
};
|
|
searchModel.getSitesByText = function (searchText) {
|
|
return searchService.getSitesByText(searchText);
|
|
};
|
|
searchModel.getSitesObjectByText = function (searchText) {
|
|
return searchService.getSitesObjectByText(searchText);
|
|
};
|
|
searchModel.getSitesByTextAndCompany = function (searchText, companyName) {
|
|
return searchService.getSitesByTextAndCompany(searchText, companyName);
|
|
};
|
|
searchModel.getOrganizationsByText = function (searchText, chunkSize) {
|
|
return searchService.getOrganizationsByText(searchText, chunkSize ? chunkSize : searchModel.organizationChunkSize);
|
|
};
|
|
searchModel.getOrganizationsByCompany = function (companyName, searchText) {
|
|
if (!companyName) {
|
|
return $q.when({});
|
|
}
|
|
return searchService.getOrganizationsByCompany(companyName, searchText).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getDepartmentsByCompany = function (companyName, searchText) {
|
|
if (!companyName) {
|
|
return $q.when({});
|
|
}
|
|
return searchService.getDepartmentsByCompany(companyName, searchText).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportGroupsListByText = function (companyName, searchText) {
|
|
if (!companyName) {
|
|
return $q.when({});
|
|
}
|
|
return searchService.getSupportGroupsList({ companyName: companyName, searchText: searchText }).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getOrganizationsByTextAndCompany = function (searchText, companyName, chunkSize) {
|
|
return searchService.getOrganizationsByTextAndCompany(searchText, companyName, chunkSize ? chunkSize : searchModel.organizationChunkSize);
|
|
};
|
|
searchModel.getSupportOrganizationsByText = function (searchText, chunkSize) {
|
|
return searchService.getSupportOrganizationsByText(searchText, chunkSize ? chunkSize : searchModel.organizationChunkSize);
|
|
};
|
|
searchModel.getAssigneeSupportOrgByCompany = function (companyName, chunkSize, role, customerCompany, locationCompany, ownerCompany, primaryCompany, authorCompany) {
|
|
if (!role && !customerCompany && !ownerCompany && searchModel.SupportOrganizationsCache[companyName]) {
|
|
return $q.when({ organizations: searchModel.SupportOrganizationsCache[companyName], exceedsChunkSize: searchModel.exceedsChunkSizeAssigneeOrg });
|
|
}
|
|
var searchOptions = { companyName: companyName }, chunkInfo;
|
|
if (role) {
|
|
searchOptions.role = role;
|
|
}
|
|
if (chunkSize) { // chunking not yet working at backend, will uncomment once backend is fixed
|
|
chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
if (customerCompany) {
|
|
searchOptions.customerCompany = customerCompany;
|
|
}
|
|
if (locationCompany) {
|
|
searchOptions.locationCompany = locationCompany;
|
|
}
|
|
if (ownerCompany) {
|
|
searchOptions.ownerCompany = ownerCompany;
|
|
}
|
|
if (primaryCompany) {
|
|
searchOptions.primaryCompany = primaryCompany;
|
|
}
|
|
if (authorCompany) {
|
|
searchOptions.authorCompany = authorCompany;
|
|
}
|
|
return searchService.getAssigneeSupportOrgByCompany(searchOptions, chunkInfo).then(function (response) {
|
|
if (!role && !customerCompany && !ownerCompany) {
|
|
searchModel.SupportOrganizationsCache[companyName] = response.organizations;
|
|
searchModel.exceedsChunkSizeAssigneeOrg = response.exceedsChunkSize;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportOrganizationsByCompany = function (companyName, chunkSize, role, customerCompany, locationCompany, ownerCompany, primaryCompany) {
|
|
if (!companyName) {
|
|
return $q.when({ organizations: [], exceedsChunkSize: false });
|
|
}
|
|
if (!role && !customerCompany && !ownerCompany && searchModel.SupportOrganizationsCache[companyName]) {
|
|
return $q.when({ organizations: searchModel.SupportOrganizationsCache[companyName], exceedsChunkSize: searchModel.exceedsChunkSizeSupportOrg });
|
|
}
|
|
var searchOptions = { companyName: companyName }, chunkInfo;
|
|
if (role) {
|
|
searchOptions.role = role;
|
|
}
|
|
if (chunkSize) { // chunking not yet working at backend, will uncomment once backend is fixed
|
|
chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
if (customerCompany) {
|
|
searchOptions.customerCompany = customerCompany;
|
|
}
|
|
if (locationCompany) {
|
|
searchOptions.locationCompany = locationCompany;
|
|
}
|
|
if (ownerCompany) {
|
|
searchOptions.ownerCompany = ownerCompany;
|
|
}
|
|
if (primaryCompany) {
|
|
searchOptions.primaryCompany = primaryCompany;
|
|
}
|
|
return searchService.getSupportOrganizationsByCompany(searchOptions, chunkInfo).then(function (response) {
|
|
if (!role && !customerCompany && !ownerCompany) {
|
|
searchModel.SupportOrganizationsCache[companyName] = response.organizations;
|
|
searchModel.exceedsChunkSizeSupportOrg = response.exceedsChunkSize;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportOrganizationsByTextAndCompany = function (searchText, companyName, chunkSize, customerCompany, locationCompany, ownerCompany, primaryCompany) {
|
|
var searchOptions = { companyName: companyName };
|
|
if (customerCompany) {
|
|
searchOptions.customerCompany = customerCompany;
|
|
}
|
|
if (locationCompany) {
|
|
searchOptions.locationCompany = locationCompany;
|
|
}
|
|
if (ownerCompany) {
|
|
searchOptions.ownerCompany = ownerCompany;
|
|
}
|
|
if (primaryCompany) {
|
|
searchOptions.primaryCompany = primaryCompany;
|
|
}
|
|
return searchService.getSupportOrganizationsByTextAndCompany(searchText, searchOptions, chunkSize).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getAssigneeByText = function (searchText) {
|
|
return searchService.getAssigneeByText(searchText);
|
|
};
|
|
searchModel.getCompaniesByText = function (searchText, chunkSize, options) {
|
|
var attrs = { chunkInfo: { startIndex: 0, chunkSize: chunkSize ? chunkSize : searchModel.companyChunkSize } };
|
|
if (chunkSize && chunkSize === -1) {
|
|
attrs = {};
|
|
}
|
|
if (options) {
|
|
attrs.searchOptions = options;
|
|
}
|
|
return searchService.getCompaniesByText(searchText, attrs).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getListOfCompaniesByText = function (searchText, chunkSize, options) {
|
|
var attrs = { chunkInfo: { startIndex: 0, chunkSize: chunkSize ? chunkSize : searchModel.companyChunkSize } };
|
|
if (chunkSize && chunkSize === -1) {
|
|
attrs = {};
|
|
}
|
|
if (options) {
|
|
attrs.searchOptions = options;
|
|
}
|
|
return searchService.getCompaniesByText(searchText, attrs).then(function (response) {
|
|
return response.companies;
|
|
});
|
|
};
|
|
searchModel.getSupportCompaniesByText = function (searchText, options, chunkSize) {
|
|
var attrs = { chunkInfo: { startIndex: 0, chunkSize: chunkSize ? chunkSize : searchModel.companyChunkSize } };
|
|
if (options) {
|
|
attrs.searchOptions = options;
|
|
}
|
|
return searchService.getSupportCompaniesByText(searchText, attrs);
|
|
};
|
|
searchModel.getAssigneeSupportCompaniesByText = function (searchText, options, chunkSize) {
|
|
return searchService.getAssigneeSupportCompaniesByText(searchText, chunkSize, options).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getOutages = function (searchParams) {
|
|
return searchService.getOutages(searchParams);
|
|
};
|
|
searchModel.getOperatingCompanies = function (options, chunkSize) {
|
|
if (chunkSize && chunkSize === -1) {
|
|
searchModel.useChunkingForOperatingCompanies = false;
|
|
}
|
|
if (!(options && (options.customerCompany || options.ownerCompany)) && searchModel.operatingCompanies) {
|
|
return $q.when(searchModel.operatingCompanies).then(function (companies) {
|
|
if (searchModel.useChunkingForOperatingCompanies) {
|
|
return companies;
|
|
}
|
|
else {
|
|
return {
|
|
companies: companies,
|
|
exceedsChunkSize: searchModel.exceedsChunkSizeOperatingCompanies
|
|
};
|
|
}
|
|
});
|
|
}
|
|
return searchModel.getCompaniesByText(null, chunkSize, options).then(function (response) {
|
|
if (!(options && (options.customerCompany || options.ownerCompany))) {
|
|
searchModel.operatingCompanies = response.companies;
|
|
searchModel.exceedsChunkSizeOperatingCompanies = response.exceedsChunkSize;
|
|
}
|
|
if (searchModel.useChunkingForOperatingCompanies) {
|
|
return response.companies;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportCompanies = function (options, chunkSize) {
|
|
return searchModel.getSupportCompaniesByText(null, options, chunkSize);
|
|
};
|
|
searchModel.getAssigneeSupportCompanies = function (options, chunkSize) {
|
|
return searchModel.getAssigneeSupportCompaniesByText(null, options, chunkSize);
|
|
};
|
|
searchModel.getAssigneeSupportGroupsForCompanyAndOrg = function (companyName, orgName, role, chunkSize, customerCompany, locationCompany, ownerCompany, primaryCompany, authorCompany, isAssignmentBlade) {
|
|
if (!companyName && !orgName && !customerCompany && !locationCompany && !ownerCompany && !authorCompany) {
|
|
if (!role) {
|
|
return searchModel.getSupportGroups(isAssignmentBlade);
|
|
}
|
|
else {
|
|
return searchModel.getSupportGroupsForRole(role, isAssignmentBlade);
|
|
}
|
|
}
|
|
if (!orgName && !role && !customerCompany && !ownerCompany && !authorCompany && searchModel.groupsCache[companyName]) {
|
|
return $q.when({ supportGroups: searchModel.groupsCache[companyName], exceedsChunkSize: searchModel.exceedsChunkSizeAssigneeGroup });
|
|
}
|
|
var payloadParams = { companyName: companyName }, urlParams = {};
|
|
if (orgName) {
|
|
payloadParams.organization = orgName;
|
|
}
|
|
if (role) {
|
|
payloadParams.role = role;
|
|
}
|
|
if (chunkSize) {
|
|
urlParams.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
if (customerCompany) {
|
|
payloadParams.customerCompany = customerCompany;
|
|
}
|
|
if (locationCompany) {
|
|
payloadParams.locationCompany = locationCompany;
|
|
}
|
|
if (ownerCompany) {
|
|
payloadParams.ownerCompany = ownerCompany;
|
|
}
|
|
if (primaryCompany) {
|
|
payloadParams.primaryCompany = primaryCompany;
|
|
}
|
|
if (authorCompany) {
|
|
payloadParams.authorCompany = authorCompany;
|
|
}
|
|
return searchService.getAssigneeSupportGroupsList(urlParams, payloadParams).then(function (response) {
|
|
if (!orgName && !role && !customerCompany && !ownerCompany && !authorCompany) {
|
|
searchModel.groupsCache[companyName] = response.supportGroups;
|
|
searchModel.exceedsChunkSizeAssigneeGroup = response.exceedsChunkSize;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getAssigneeSupportGroupsForCompanyAndOrgByName = function (companyName, orgName, name, chunkSize, customerCompany, locationCompany, ownerCompany, primaryCompany, authorCompany, role) {
|
|
// this call is used by typeahead, so no caching
|
|
var payloadParams = {
|
|
companyName: companyName
|
|
}, urlParams = {
|
|
searchText: name
|
|
};
|
|
if (orgName) {
|
|
payloadParams.organization = orgName;
|
|
}
|
|
if (role) {
|
|
payloadParams.role = role;
|
|
}
|
|
if (chunkSize) {
|
|
urlParams.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
if (customerCompany) {
|
|
payloadParams.customerCompany = customerCompany;
|
|
}
|
|
if (locationCompany) {
|
|
payloadParams.locationCompany = locationCompany;
|
|
}
|
|
if (ownerCompany) {
|
|
payloadParams.ownerCompany = ownerCompany;
|
|
}
|
|
if (primaryCompany) {
|
|
payloadParams.primaryCompany = primaryCompany;
|
|
}
|
|
if (authorCompany) {
|
|
payloadParams.authorCompany = authorCompany;
|
|
}
|
|
return searchService.getAssigneeSupportGroupsList(urlParams, payloadParams).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportGroupsForCompanyAndOrg = function (companyName, orgName, role, chunkSize, customerCompany, locationCompany, ownerCompany, primaryCompany) {
|
|
if (!companyName) {
|
|
if (!role) {
|
|
return searchModel.getSupportGroups();
|
|
}
|
|
else {
|
|
return searchModel.getSupportGroupsForRole(role);
|
|
}
|
|
}
|
|
if (!orgName && !role && !customerCompany && !ownerCompany && searchModel.groupsCache[companyName]) {
|
|
return $q.when({ supportGroups: searchModel.groupsCache[companyName], exceedsChunkSize: searchModel.exceedsChunkSizeAssigneeGroup });
|
|
}
|
|
var param = { companyName: companyName };
|
|
if (orgName) {
|
|
param.organization = orgName;
|
|
}
|
|
if (role) {
|
|
param.role = role;
|
|
}
|
|
if (chunkSize) {
|
|
param.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
if (customerCompany) {
|
|
param.customerCompany = customerCompany;
|
|
}
|
|
if (locationCompany) {
|
|
param.locationCompany = locationCompany;
|
|
}
|
|
if (ownerCompany) {
|
|
param.ownerCompany = ownerCompany;
|
|
}
|
|
if (primaryCompany) {
|
|
param.primaryCompany = primaryCompany;
|
|
}
|
|
return searchService.getSupportGroupsList(param).then(function (response) {
|
|
if (!orgName && !role && !customerCompany && !ownerCompany) {
|
|
searchModel.groupsCache[companyName] = response.supportGroups;
|
|
searchModel.exceedsChunkSizeAssigneeGroup = response.exceedsChunkSize;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getRecommendedSupportGroups = function (ticketType, searchText, companyWithSite, locationCompany) {
|
|
var param = {
|
|
searchText: searchText,
|
|
company: companyWithSite
|
|
};
|
|
if (locationCompany) {
|
|
param.locationCompany = locationCompany;
|
|
}
|
|
return searchService.getRecommendedSupportGroupsList({ ticketType: ticketType }, param);
|
|
};
|
|
searchModel.getSupportGroupsForCompanyAndOrgByName = function (companyName, orgName, name, chunkSize) {
|
|
// this call is used by typeahead, so no caching
|
|
var param = {
|
|
companyName: companyName,
|
|
searchText: name
|
|
};
|
|
if (orgName) {
|
|
param.organization = orgName;
|
|
}
|
|
if (chunkSize) {
|
|
param.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
return searchService.getSupportGroupsList(param);
|
|
};
|
|
searchModel.getAffectedBusinessService = function (searchText) {
|
|
// this call is used by typeahead, so no caching
|
|
return searchService.getListOfServiceByText(searchText).then(function (response) {
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportGroups = function (isAssignmentBlade) {
|
|
if (searchModel.allGroups) {
|
|
return $q.when({ supportGroups: searchModel.allGroups, exceedsChunkSize: searchModel.exceedsChunkSizeAssigneeGroup });
|
|
}
|
|
var params = {};
|
|
if (isAssignmentBlade) {
|
|
params.assignmentAvailability = true;
|
|
}
|
|
return searchService.getSupportGroupsList(params).then(function (response) {
|
|
searchModel.allGroups = response.supportGroups;
|
|
searchModel.groupsCache = _.groupBy(searchModel.allGroups, 'companyName');
|
|
searchModel.exceedsChunkSizeAssigneeGroup = response.exceedsChunkSize;
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportGroupsForKAShare = function (chunkSize) {
|
|
var param = {};
|
|
if (chunkSize) {
|
|
param.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
return searchService.getSupportGroupsList(param).then(function (response) {
|
|
searchModel.allGroups = response.supportGroups;
|
|
searchModel.groupsCache = _.groupBy(searchModel.allGroups, 'companyName');
|
|
searchModel.exceedsChunkSizeAssigneeGroup = response.exceedsChunkSize;
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getSupportGroupsForRole = function (role, isAssignmentBlade) {
|
|
var params = {
|
|
role: role
|
|
};
|
|
if (isAssignmentBlade) {
|
|
params.assignmentAvailability = true;
|
|
}
|
|
return searchService.getSupportGroupsList(params);
|
|
};
|
|
searchModel.getSupportGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({ searchText: searchText });
|
|
};
|
|
searchModel.getListOfSupportGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({ searchText: searchText })
|
|
.then(function (response) {
|
|
return response.supportGroups;
|
|
});
|
|
};
|
|
searchModel.getChangeManagerGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({
|
|
searchText: searchText,
|
|
role: 'changemanager'
|
|
}).then(function (result) {
|
|
return result.supportGroups;
|
|
});
|
|
};
|
|
searchModel.getChangeCoordinatorGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({
|
|
searchText: searchText,
|
|
role: 'changecoordinator'
|
|
}).then(function (response) {
|
|
return response.supportGroups;
|
|
});
|
|
};
|
|
searchModel.getRequestManagerGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({
|
|
searchText: searchText,
|
|
role: 'workordermanager'
|
|
}).then(function (response) {
|
|
return response.supportGroups;
|
|
});
|
|
};
|
|
searchModel.getProblemCoordinatorGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({
|
|
searchText: searchText,
|
|
role: 'problemcoordinator'
|
|
}).then(function (response) {
|
|
return response.supportGroups;
|
|
});
|
|
};
|
|
searchModel.getReleaseCoordinatorGroupsByText = function (searchText) {
|
|
return searchService.getSupportGroupsList({
|
|
searchText: searchText,
|
|
role: 'problemcoordinator' // change this to releasecoordinator when backend code is done
|
|
}).then(function (response) {
|
|
return response.supportGroups;
|
|
});
|
|
};
|
|
searchModel.getApproverSupportCompanies = function (searchText, chunkSize, ticketType) {
|
|
var attrs = { chunkInfo: { startIndex: 0, chunkSize: chunkSize ? chunkSize : searchModel.companyChunkSize } };
|
|
return searchService.getApproverSupportCompanies(searchText, attrs, ticketType);
|
|
};
|
|
searchModel.getApproverSupportOrganizations = function (searchText, companyName, chunkSize, ticketType) {
|
|
if (!companyName) {
|
|
return $q.when([]);
|
|
}
|
|
if (!searchText && searchModel.approverSupportOrganizationsCache[companyName]) {
|
|
return $q.when(searchModel.approverSupportOrganizationsCache[companyName]);
|
|
}
|
|
var searchOptions = {
|
|
companyName: companyName,
|
|
role: (ticketType && ticketType === EntityVO.TYPE_RELEASE) ? 'releaseapprover' : 'changeapprover'
|
|
}, chunkInfo = { startIndex: 0, chunkSize: chunkSize ? chunkSize : searchModel.organizationChunkSize };
|
|
return searchService.getApproverSupportOrganizations(searchText, searchOptions, chunkInfo).then(function (response) {
|
|
if (!searchText) {
|
|
searchModel.approverSupportOrganizationsCache[companyName] = response;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
searchModel.getApproverSupportGroups = function (searchText, companyName, orgName, chunkSize, ticketType) {
|
|
if (!companyName) {
|
|
return $q.when({ supportGroups: [], exceedsChunkSize: false });
|
|
}
|
|
if (!searchText && !orgName && searchModel.approverGroupsCache[companyName]) {
|
|
return $q.when({ supportGroups: searchModel.approverGroupsCache[companyName], exceedsChunkSize: searchModel.exceedsChunkSizeApproverGroup });
|
|
}
|
|
var param = {
|
|
companyName: companyName,
|
|
role: (ticketType && ticketType === EntityVO.TYPE_RELEASE) ? 'releaseapprover' : 'changeapprover',
|
|
chunkInfo: { startIndex: 0, chunkSize: chunkSize ? chunkSize : searchModel.supportGroupChunkSize }
|
|
};
|
|
if (searchText) {
|
|
param.searchText = searchText;
|
|
}
|
|
if (orgName) {
|
|
param.organization = orgName;
|
|
}
|
|
return searchService.getSupportGroupsList(param).then(function (response) {
|
|
if (!searchText && !orgName) {
|
|
searchModel.approverGroupsCache[companyName] = response.supportGroups;
|
|
searchModel.exceedsChunkSizeApproverGroup = response.exceedsChunkSize;
|
|
}
|
|
return response;
|
|
});
|
|
};
|
|
/**
|
|
* Get list of sites based on company
|
|
* @param companyName
|
|
* @returns {*}
|
|
*/
|
|
searchModel.getSitesByCompany = function (companyName) {
|
|
if (searchModel.siteCache[companyName]) {
|
|
return $q.when({ objects: searchModel.siteCache[companyName], exceedsChunkSize: searchModel.exceedsChunkSizeSite });
|
|
}
|
|
return searchService.getSitesByCompany(companyName).then(function (data) {
|
|
searchModel.siteCache[companyName] = data.objects;
|
|
searchModel.exceedsChunkSizeSite = data.exceedsChunkSize;
|
|
return data;
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.searchModel#getFilteredSuggestedOutagesList
|
|
*
|
|
* @description
|
|
* Get list of Outages based on the search criteria
|
|
* @param {Array} filters - List of filters to be used while searching Outages
|
|
* @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
|
|
* */
|
|
searchModel.getFilteredOutagesList = function (filters, ticket) {
|
|
if (!filters) {
|
|
return $q.when({ error: 'No search filters specified!' });
|
|
}
|
|
return searchService.getFilteredOutagesList(filters, ticket)
|
|
.then(function (outageList) {
|
|
return outageList;
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.searchModel#getFilteredSuggestedOutagesList
|
|
*
|
|
* @description
|
|
* Get list of Outages, suggested to specific Ticket. Basically gets all outages related to the CIs, which have a relation to the ticket
|
|
* @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
|
|
* */
|
|
searchModel.getFilteredSuggestedOutagesList = function (ticket) {
|
|
var filters = {
|
|
relatedCI: true,
|
|
unavailabilityStatus: (ticket.timing === 'Latent' ? ["Restored"] : ['Scheduled'])
|
|
};
|
|
return searchService.getFilteredOutagesList(filters, ticket)
|
|
.then(function (suggestedOutages) {
|
|
return suggestedOutages;
|
|
});
|
|
};
|
|
searchModel.searchCIsRelatedToChangeRequestByCriteria = function (ticket, params, chunkInfo) {
|
|
if (!params || !ticket) {
|
|
return $q.when({ error: 'Missing required params' });
|
|
}
|
|
return searchService.searchCIsRelatedToChangeRequestByCriteria(params, ticket, chunkInfo);
|
|
};
|
|
searchModel.searchBusinessServiceByKeyword = function (searchText) {
|
|
return assetService.getListOfAssetsByType(searchText, "Business Service").then(function (result) {
|
|
var ciList = [];
|
|
try {
|
|
ciList = result[0].items[0].objects;
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
}
|
|
return ciList;
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.searchModel#getFoundationSuppliersByText
|
|
*
|
|
* @description
|
|
* Get list of Suppliers in the system for asset console filters
|
|
* @param {String} searchText - Type ahead text
|
|
* */
|
|
searchModel.getFoundationSuppliersByText = function (searchText) {
|
|
var searchParams = {
|
|
type: 'company',
|
|
searchText: searchText,
|
|
searchOptions: {
|
|
companyType: 'Supplier'
|
|
}
|
|
};
|
|
return searchService.getFoundationItems(searchParams).then(function (results) {
|
|
return results.foundationItems;
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.searchModel#getFoundationManufacturersByText
|
|
*
|
|
* @description
|
|
* Get list of all Manufacturers in the system for asset console filters
|
|
* @param {String} searchText - Type ahead text
|
|
* */
|
|
searchModel.getFoundationManufacturersByText = function (searchText) {
|
|
var searchParams = {
|
|
type: 'company',
|
|
searchText: searchText,
|
|
searchOptions: {
|
|
companyType: 'Manufacturer'
|
|
}
|
|
};
|
|
return searchService.getFoundationItems(searchParams).then(function (results) {
|
|
return results.foundationItems;
|
|
});
|
|
};
|
|
searchModel.removeKnowledgeOptionsIfHKMEnabled = function (searchMetadata) {
|
|
if (configurationModel.comaroundEnabled) {
|
|
_.remove(searchMetadata, function (option) {
|
|
if (option.name === "tickets") {
|
|
option.selected = true;
|
|
}
|
|
if (option.name === "all") {
|
|
option.types = ["tickets", "asset", "person"];
|
|
}
|
|
return (option.name === "knowledge" || option.name === "ticketKnowledge");
|
|
});
|
|
}
|
|
};
|
|
searchModel.getHKMUrls = function () {
|
|
if (cacheHKMUrls) {
|
|
return $q.when(_.cloneDeep(cacheHKMUrls));
|
|
}
|
|
cacheHKMUrls = searchService.getHKMUrls().then(function (urls) {
|
|
cacheHKMUrls = _.cloneDeep(urls);
|
|
return urls;
|
|
}).catch(function (error) {
|
|
systemAlertService.error({
|
|
text: error.data.errorCode ? i18nService.getLocalizedString('error.unknown') : error.data.error
|
|
});
|
|
});
|
|
return cacheHKMUrls;
|
|
};
|
|
return searchModel;
|
|
}]);
|
|
}());
|