blob: a2ced03777513c1301bed50cc1e6f28964c96f31 [file] [log] [blame]
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001window.angular && (function(angular) {
2 'use strict';
Iftekharul Islam99d199f2017-03-24 15:28:25 -05003
Andrew Geisslerd27bb132018-05-24 11:07:27 -07004 angular.module('app.common.directives')
5 .directive('appNavigation', function() {
6 return {
7 'restrict': 'E',
8 'template': require('./app-navigation.html'),
9 'scope': {'path': '=', 'showNavigation': '='},
10 'controller': [
11 '$scope', '$location', 'dataService',
12 function($scope, $location, dataService) {
kathycee23d92019-11-11 10:35:31 -080013 $scope.showHealthMenu = false;
14 $scope.showControlMenu = false;
15 $scope.showConfigMenu = false;
16 $scope.showAccessMenu = false;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070017 $scope.dataService = dataService;
kathycee23d92019-11-11 10:35:31 -080018
Andrew Geisslerd27bb132018-05-24 11:07:27 -070019 $scope.change = function(firstLevel) {
kathycee23d92019-11-11 10:35:31 -080020 switch (firstLevel) {
21 case 'server-health':
22 $scope.showHealthMenu = !$scope.showHealthMenu;
23 break;
24 case 'server-control':
25 $scope.showControlMenu = !$scope.showControlMenu;
26 break;
27 case 'configuration':
28 $scope.showConfigMenu = !$scope.showConfigMenu;
29 break;
30 case 'access-control':
31 $scope.showAccessMenu = !$scope.showAccessMenu;
32 break;
33 case 'overview':
34 $location.url('/overview/server');
35 break;
36 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -070037 };
38 $scope.$watch('path', function() {
39 var urlRoot = $location.path().split('/')[1];
40 if (urlRoot != '') {
41 $scope.firstLevel = urlRoot;
42 } else {
43 $scope.firstLevel = 'overview';
44 }
kathycee23d92019-11-11 10:35:31 -080045 $scope.showSubMenu = true;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070046 });
47 $scope.$watch('showNavigation', function() {
Andrew Geisslerd27bb132018-05-24 11:07:27 -070048 var urlRoot = $location.path().split('/')[1];
49 if (urlRoot != '') {
50 $scope.firstLevel = urlRoot;
51 } else {
52 $scope.firstLevel = 'overview';
53 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070054 });
55 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070056 ],
57 link: function(scope, element, attributes) {
58 var rawNavElement = angular.element(element)[0];
59 angular.element(window.document).bind('click', function(event) {
60 if (rawNavElement.contains(event.target)) return;
61
62 if (scope.showSubMenu) {
63 scope.$apply(function() {
kathycee23d92019-11-11 10:35:31 -080064 scope.showSubMenu = true;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070065 });
66 }
67 });
68 }
69 };
70 });
kathycee23d92019-11-11 10:35:31 -080071})(window.angular);