"use strict"; (function () { 'use strict'; angular.module('headerNavigationModule') .controller('HeaderNavigationController', ['$scope', '$rootScope', '$window', 'screenConfigurationModel', 'metadataModel', 'userModel', 'screenConfigurationService', 'events', 'session', 'headerNavigationModel', 'configurationModel', 'searchModel', '$state', 'gainsightModel', function ($scope, $rootScope, $window, screenConfigurationModel, metadataModel, userModel, screenConfigurationService, events, session, headerNavigationModel, configurationModel, searchModel, $state, gainsightModel) { var sessionInfo = { serverVersion: session.serverVersion, appName: 'Galileo UC', locale: window.myitsmLocale, deviceToken: 'dummyToken', model: 'Web Client' }; $scope.enableAnalyticsSettings = false; $scope.enableInAppSurvey = false; $scope.cssEnabledForCalendar = false; $scope.cssEnabledForLiveChat = false; function getCustomActionsAndInit(navConfig) { if (!navConfig || !navConfig.actionList.length) { headerNavigationModel.clearCustomActions(); initNavigation(); return; } headerNavigationModel.clearCustomActions(); if (navConfig.actionList && navConfig.actionList.length) { headerNavigationModel.getCustomActions(navConfig); } initNavigation(); } function checkIfCCSEnabled() { var index = $scope.navigationItems.length; while (index--) { if ($scope.navigationItems[index].state === "calendarStudio" && !$scope.cssEnabledForCalendar) { $scope.navigationItems.splice(index, 1); } if ($scope.navigationItems[index].state === "liveChat" && !$scope.cssEnabledForLiveChat) { $scope.navigationItems.splice(index, 1); } if ($scope.navigationItems[index].type === "dropdown" && $scope.navigationItems[index] && $scope.navigationItems[index].elements && $scope.navigationItems[index].elements.length) { if (configurationModel.comaroundEnabled) { _.remove($scope.navigationItems[index].elements, function (navItem) { return (navItem.app === EntityVO.TYPE_KNOWLEDGE && !(navItem.name === "createKnowledgeHKM" || navItem.name === "knowledgeConsoleHKM")); }); } else { _.remove($scope.navigationItems[index].elements, function (element) { return (element.name === "createKnowledgeHKM" || element.name === "knowledgeConsoleHKM"); }); } } if ($scope.navigationItems[index].app === EntityVO.TYPE_KNOWLEDGE && configurationModel.comaroundEnabled) { $scope.navigationItems.splice(index, 1); } } } function initNavigation() { $scope.navigationItems = headerNavigationModel.updateNavigationItems(); metadataModel.getMetadataByType('global').then(function (metadata) { //Fetch comaround create url on load of navigation bar if (configurationModel.comaroundEnabled) { searchModel.getHKMUrls(); } gainsightModel.getTelemetryConfiguration().then(function (config) { $scope.enableAnalyticsSettings = metadata.enableGainsight && config.settings.enableGainsight; }); $scope.enableInAppSurvey = metadata && metadata.configurationParameters && metadata.configurationParameters.enableInAppSurvey === 'true'; $scope.cssEnabledForCalendar = metadata && metadata.configurationParameters && metadata.configurationParameters.calendarFeatureEnabled === 'true'; $scope.cssEnabledForLiveChat = metadata && metadata.configurationParameters && metadata.configurationParameters.enableESChatIntegration === 'true'; checkIfCCSEnabled(); }); } $scope.launchURL = function (item) { metadataModel.getMetadataByType('global').then(function (metadata) { //regex for finding square brackets [params] in the url var re = new RegExp('\\[\\w+\\]'), url = item.url, target = item.target === 'new' ? '_blank' : '_self', match, key, userFullDataValue, isPwaEnabled = (metadata.configurationParameters['Enable-Progressive-Views'] === 'T' || metadata.configurationParameters['Enable-Progressive-Views'] === 'true'), midtierUrl = localStorage.getItem('midtierUrl'); isPwaEnabled = localStorage.getItem('overridePV') === 'T' ? false : isPwaEnabled; if (isPwaEnabled && midtierUrl) { if (url.indexOf("pv://") > -1) { url = url.replace("pv://", ""); $state.go('pwaAction', { data: { formName: encodeURI(url) } }); return false; } } if (!metadata.ootbMapping) { $window.open(encodeURI(url), target); return; } while (url.search(re) !== -1) { match = url.match(re); key = match[0].replace(/[\[\]']+/g, ''); //remove the square brackets if (_.has(sessionInfo, key)) { url = url.replace(re, sessionInfo[key]); } else { userFullDataValue = key === 'supportGroups' ? _.map(userModel.userFullData.supportGroups, 'name').join(',') : screenConfigurationService.getContextPropertyByMetadataMapping(userModel.userFullData, metadata, key) || ''; url = url.replace(re, userFullDataValue); } } var newWindow = $window.open(encodeURI(url), target); newWindow.opener = null; }); }; screenConfigurationModel.loadActionsForRuntime('global').then(function () { getCustomActionsAndInit(screenConfigurationModel.runtimeActionsCache.global); }); $scope.$on(events.PERMISSIONS_CHANGED, headerNavigationModel.updateNavigationItems()); var unbind = $rootScope.$on(events.GLOBAL_MENU_ACTIONS_UPDATE, function () { getCustomActionsAndInit(screenConfigurationModel.runtimeActionsCache.global); }); $scope.$on("$destroy", function () { console.log("destroy root scope events bound from here"); unbind(); }); } ]); })();