SmartIT_Extensions/BMC/smart-it-full/scripts/app/navigation/header-navigation-controlle...

71 lines
3.7 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('headerNavigationModule')
.controller('HeaderNavigationController', ['$scope', '$rootScope', '$window', 'screenConfigurationModel', 'metadataModel', 'userModel',
'screenConfigurationService', 'events', 'session', 'headerNavigationModel',
function ($scope, $rootScope, $window, screenConfigurationModel, metadataModel, userModel, screenConfigurationService, events, session, headerNavigationModel) {
var sessionInfo = {
serverVersion: session.serverVersion,
appName: 'Galileo UC',
locale: window.myitsmLocale,
deviceToken: 'dummyToken',
model: 'Web Client'
};
$scope.enableInAppSurvey = false;
metadataModel.getMetadataByType('global').then(function (metadata) {
$scope.enableInAppSurvey = metadata && metadata.configurationParameters && metadata.configurationParameters.enableInAppSurvey === 'true';
});
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 initNavigation() {
$scope.navigationItems = headerNavigationModel.updateNavigationItems();
}
$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;
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' ? _.pluck(userModel.userFullData.supportGroups, 'name').join(',') :
screenConfigurationService.getContextPropertyByMetadataMapping(userModel.userFullData, metadata, key) || '';
url = url.replace(re, userFullDataValue);
}
}
$window.open(encodeURI(url), target);
});
};
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();
});
}
]);
})();