Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1 | window.angular && (function(angular) { |
| 2 | 'use strict'; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 3 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 4 | 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) { |
kathy | cee23d9 | 2019-11-11 10:35:31 -0800 | [diff] [blame^] | 13 | $scope.showHealthMenu = false; |
| 14 | $scope.showControlMenu = false; |
| 15 | $scope.showConfigMenu = false; |
| 16 | $scope.showAccessMenu = false; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 17 | $scope.dataService = dataService; |
kathy | cee23d9 | 2019-11-11 10:35:31 -0800 | [diff] [blame^] | 18 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 19 | $scope.change = function(firstLevel) { |
kathy | cee23d9 | 2019-11-11 10:35:31 -0800 | [diff] [blame^] | 20 | 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 Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 37 | }; |
| 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 | } |
kathy | cee23d9 | 2019-11-11 10:35:31 -0800 | [diff] [blame^] | 45 | $scope.showSubMenu = true; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 46 | }); |
| 47 | $scope.$watch('showNavigation', function() { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 48 | var urlRoot = $location.path().split('/')[1]; |
| 49 | if (urlRoot != '') { |
| 50 | $scope.firstLevel = urlRoot; |
| 51 | } else { |
| 52 | $scope.firstLevel = 'overview'; |
| 53 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 54 | }); |
| 55 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 56 | ], |
| 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() { |
kathy | cee23d9 | 2019-11-11 10:35:31 -0800 | [diff] [blame^] | 64 | scope.showSubMenu = true; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 65 | }); |
| 66 | } |
| 67 | }); |
| 68 | } |
| 69 | }; |
| 70 | }); |
kathy | cee23d9 | 2019-11-11 10:35:31 -0800 | [diff] [blame^] | 71 | })(window.angular); |