"use strict"; (function () { 'use strict'; angular.module('headerNavigationModule') .factory('headerNavigationModel', ['permissionModel', 'configurationModel', 'screenConfigurationModel', 'systemAlertService', 'i18nService', 'roles', '$window', function (permissionModel, configurationModel, screenConfigurationModel, systemAlertService, i18nService, roles, $window) { var headerNavigationModel = {}, allNavItems = [ { state: 'dashboard', i18nKey: 'dashboard', type: 'link' }, { i18nKey: 'console', type: 'dropdown', elements: [ { state: 'ticketConsole', i18nKey: 'ticketConsole', icon: 'file_text_o', roles: [roles.ITSM_AGENT_ROLE, roles.ITSM_CHANGE_USER_ROLE, roles.ITSM_PROBLEM_USER_ROLE] }, { state: 'knowledgeConsole', i18nKey: 'knowledgeConsole', icon: 'lightbulb_o', app: EntityVO.TYPE_KNOWLEDGE, role: roles.ITSM_KNOWLEDGE_USER_ROLE }, { state: 'assetConsole', i18nKey: 'assetConsole', icon: 'cube_o', app: EntityVO.TYPE_ASSET, role: roles.ITSM_ASSET_USER_ROLE } ] }, { state: 'smartRecorder', i18nKey: 'smartRecorder', type: 'link', role: roles.ITSM_AGENT_ROLE }, { i18nKey: 'create', type: 'dropdown', elements: [ { state: 'createIncident', i18nKey: 'incident', icon: 'file_text_o', permission: roles.ITSM_AGENT_ROLE }, { state: 'createWorkorder', i18nKey: 'workorder', icon: 'file_wrench_o', app: EntityVO.TYPE_WORKORDER, permission: roles.ITSM_AGENT_ROLE }, { state: 'createKnowledge', i18nKey: 'knowledge', icon: 'lightbulb_o', app: EntityVO.TYPE_KNOWLEDGE, permission: roles.ITSM_KNOWLEDGE_USER_ROLE }, { state: 'createChange.selector', i18nKey: 'change', icon: 'files_change_o', app: EntityVO.TYPE_CHANGE, permission: roles.ITSM_CHANGE_USER_ROLE }, { state: 'createRelease.selector', i18nKey: 'release', icon: 'app_box_open_o', app: EntityVO.TYPE_RELEASE, permission: roles.ITSM_RELEASE_USER_ROLE }, { state: 'createProblem', i18nKey: 'problem', icon: 'search_exclamation', app: EntityVO.TYPE_PROBLEM, permission: roles.ITSM_PROBLEM_USER_ROLE }, { state: 'createKnownerror', i18nKey: 'knownerror', icon: 'file_exclamation_o', app: EntityVO.TYPE_KNOWNERROR, permission: roles.ITSM_PROBLEM_USER_ROLE }, { state: 'createBroadcast', i18nKey: 'broadcast', icon: 'speaker', permission: roles.ITSM_BROADCAST_USER_ROLE }, { state: 'createAsset', i18nKey: 'asset', icon: 'cube_o', app: EntityVO.TYPE_ASSET, permission: roles.ITSM_ASSET_USER_ROLE } ] }, { handler: handleSmartReporterClick, i18nKey: 'reports', app: EntityVO.TYPE_REPORTS, type: 'link' }, { i18nKey: 'configuration', type: 'dropdown', elements: [ { state: 'screenConfiguration', i18nKey: 'screenConfiguration', icon: 'gear', permission: 'admin:screenConfiguration' }, { state: 'knowledgeStyleConfiguration', i18nKey: 'knowledgeTemplateStyles', icon: 'lightbulb_o', app: EntityVO.TYPE_KNOWLEDGE, role: roles.ITSM_ADMIN_ROLE }, { state: 'createAqiQuestions', i18nKey: 'aqi', icon: 'pencil', app: EntityVO.TYPE_KNOWLEDGE, permission: roles.ITSM_KCS_COACH_ROLE }, { state: 'adminConsoleConfig', i18nKey: 'adminConsoleConfig', icon: 'gear', permission: 'admin:screenConfiguration' } ] }, { state: 'knowledgeTeam', i18nKey: 'knowledge', type: 'link', app: EntityVO.TYPE_KNOWLEDGE, role: roles.ITSM_KCS_COACH_ROLE }, { i18nKey: 'customActions', type: 'dropdown', hideHeader: true, elements: [] } ], navItemCustom = _.find(allNavItems, { i18nKey: 'customActions' }); function handleSmartReporterClick() { screenConfigurationModel.getSmartReporterUrl().then(function (url) { url = decodeURI(url); $window.open(url, '_blank'); }).catch(function (error) { systemAlertService.error({ text: error.data.errorCode ? i18nService.getLocalizedString('error.unknown') : error.data.error }); }); } function updateNavigationItems(navItemsArray) { var availableNavItems = []; _.forEach(navItemsArray, function (item) { if (!item.elements) { if (item.roles && item.roles.length) { var hasPermission = _.some(item.roles, function (role) { return permissionModel.hasRole(role); }); if (!hasPermission) { return; } } if (item.role && !permissionModel.hasRole(item.role)) { return; } if (item.app && !configurationModel.isServerApplicationEnabled(item.app)) { return; } if (item.permission && !permissionModel.hasPermission(item.permission)) { return; } availableNavItems.push(item); } else { item.elements = updateNavigationItems(item.elements); if (item.elements.length) { availableNavItems.push(item); } } }); return availableNavItems; } headerNavigationModel.updateNavigationItems = function () { return updateNavigationItems(allNavItems); }; headerNavigationModel.clearCustomActions = function () { _.remove(navItemCustom.elements, { extended: true }); }; headerNavigationModel.getCustomActions = function (navConfig) { _.forEach(navConfig.actionList, function (urlItem) { if (_.contains(urlItem.supportedPlatforms, 'web')) { var newElement = { extended: true }; newElement.label = urlItem.labels[i18nService.language] || urlItem.labels.default; newElement.url = urlItem.url; newElement.target = urlItem.target; newElement.sequenceNo = urlItem.sequenceNo; navItemCustom.elements.push(newElement); } }); if (navItemCustom.elements.length) { if (navConfig.actionOrder === 'alphabetical') { navItemCustom.elements = _.sortBy(navItemCustom.elements, 'label'); } else { navItemCustom.elements = _.sortBy(navItemCustom.elements, 'sequenceNo'); } } }; return headerNavigationModel; } ]); }());