Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 1 | |
| 2 | |
| 3 | angular |
| 4 | .module('app.directives', []) |
| 5 | .directive('appHeader', ['APIUtils', function(APIUtils){ |
| 6 | |
| 7 | return { |
| 8 | 'restrict': 'E', |
| 9 | 'templateUrl': 'header.html', |
| 10 | 'scope': { |
| 11 | 'path': '=' |
| 12 | }, |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 13 | 'controller': ['$scope','dataService', 'userModel', '$location', function($scope, dataService, userModel, $location){ |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 14 | $scope.server_status = 01; |
| 15 | $scope.dataService = dataService; |
| 16 | APIUtils.login(function(){ |
| 17 | APIUtils.getHostState(function(status){ |
| 18 | if(status == 'xyz.openbmc_project.State.Host.HostState.Off'){ |
| 19 | $scope.server_status = -1; |
| 20 | }else if(status == 'xyz.openbmc_project.State.Host.HostState.Running'){ |
| 21 | $scope.server_status = 1; |
| 22 | }else{ |
| 23 | $scope.server_status = 0; |
| 24 | } |
| 25 | }); |
| 26 | }); |
| 27 | |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 28 | $scope.logout = function(){ |
| 29 | userModel.logout(); |
| 30 | $location.path('/logout'); |
Michael Davis | 9e00ce9 | 2017-03-09 18:31:02 -0600 | [diff] [blame^] | 31 | }; |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 32 | |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 33 | $scope.refresh = function(){ |
| 34 | console.log("--refresh status--"); |
| 35 | } |
| 36 | }] |
| 37 | }; |
| 38 | }]) |
| 39 | .directive('appNavigation', function(){ |
| 40 | |
| 41 | return { |
| 42 | 'restrict': 'E', |
| 43 | 'templateUrl': 'navigation.html', |
| 44 | 'scope': { |
| 45 | 'path': '=', |
| 46 | 'showNavigation': '=' |
| 47 | }, |
| 48 | 'controller': ['$scope', 'dataService', function($scope, dataService){ |
| 49 | $scope.$watch('showNavigation', function(){ |
Michael Davis | 9e00ce9 | 2017-03-09 18:31:02 -0600 | [diff] [blame^] | 50 | var paddingTop = 0; |
| 51 | $scope.toggle = false; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 52 | $scope.firstLevel = 'overview'; |
| 53 | $scope.secondLevel = 'system_overview'; |
| 54 | if($scope.showNavigation){ |
| 55 | paddingTop = document.getElementById('header__wrapper').offsetHeight; |
| 56 | } |
| 57 | dataService.bodyStyle = {'padding-top': paddingTop + 'px'}; |
| 58 | $scope.navStyle = {'top': paddingTop + 'px'}; |
| 59 | }); |
Michael Davis | 9e00ce9 | 2017-03-09 18:31:02 -0600 | [diff] [blame^] | 60 | |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 61 | }] |
| 62 | }; |
| 63 | }) |
| 64 | .directive('confirm', ['$timeout', function($timeout){ |
| 65 | |
| 66 | return { |
| 67 | 'restrict': 'E', |
| 68 | 'templateUrl': 'confirm.html', |
| 69 | 'scope': { |
| 70 | 'title': '@', |
| 71 | 'message': '@', |
| 72 | 'confirm': '=', |
| 73 | 'callback': '=' |
| 74 | }, |
| 75 | 'controller': ['$scope',function($scope){ |
| 76 | $scope.cancel = function(){ |
| 77 | $scope.confirm = false; |
| 78 | $scope.$parent.confirm = false; |
| 79 | }; |
| 80 | $scope.accept = function(){ |
| 81 | $scope.callback(); |
| 82 | $scope.cancel(); |
| 83 | } |
| 84 | }], |
| 85 | link: function(scope, e) { |
| 86 | scope.$watch('confirm', function(){ |
| 87 | if(scope.confirm){ |
| 88 | $timeout(function(){ |
Michael Davis | ea5241a | 2017-07-12 15:56:55 -0500 | [diff] [blame] | 89 | angular.element(e[0].parentNode).css({'min-height': e[0].querySelector('.inline__confirm').offsetHeight + 'px'}); |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 90 | }, 0); |
| 91 | }else{ |
| 92 | angular.element(e[0].parentNode).css({'min-height': 0+ 'px'}); |
| 93 | } |
| 94 | }); |
| 95 | } |
| 96 | }; |
| 97 | }]); |