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 | }, |
| 13 | 'controller': ['$scope','dataService', function($scope, dataService){ |
| 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 | |
| 28 | $scope.refresh = function(){ |
| 29 | console.log("--refresh status--"); |
| 30 | } |
| 31 | }] |
| 32 | }; |
| 33 | }]) |
| 34 | .directive('appNavigation', function(){ |
| 35 | |
| 36 | return { |
| 37 | 'restrict': 'E', |
| 38 | 'templateUrl': 'navigation.html', |
| 39 | 'scope': { |
| 40 | 'path': '=', |
| 41 | 'showNavigation': '=' |
| 42 | }, |
| 43 | 'controller': ['$scope', 'dataService', function($scope, dataService){ |
| 44 | $scope.$watch('showNavigation', function(){ |
| 45 | var padingTop = 0; |
| 46 | $scope.firstLevel = 'overview'; |
| 47 | $scope.secondLevel = 'system_overview'; |
| 48 | if($scope.showNavigation){ |
| 49 | paddingTop = document.getElementById('header__wrapper').offsetHeight; |
| 50 | } |
| 51 | dataService.bodyStyle = {'padding-top': paddingTop + 'px'}; |
| 52 | $scope.navStyle = {'top': paddingTop + 'px'}; |
| 53 | }); |
| 54 | }] |
| 55 | }; |
| 56 | }) |
| 57 | .directive('confirm', ['$timeout', function($timeout){ |
| 58 | |
| 59 | return { |
| 60 | 'restrict': 'E', |
| 61 | 'templateUrl': 'confirm.html', |
| 62 | 'scope': { |
| 63 | 'title': '@', |
| 64 | 'message': '@', |
| 65 | 'confirm': '=', |
| 66 | 'callback': '=' |
| 67 | }, |
| 68 | 'controller': ['$scope',function($scope){ |
| 69 | $scope.cancel = function(){ |
| 70 | $scope.confirm = false; |
| 71 | $scope.$parent.confirm = false; |
| 72 | }; |
| 73 | $scope.accept = function(){ |
| 74 | $scope.callback(); |
| 75 | $scope.cancel(); |
| 76 | } |
| 77 | }], |
| 78 | link: function(scope, e) { |
| 79 | scope.$watch('confirm', function(){ |
| 80 | if(scope.confirm){ |
| 81 | $timeout(function(){ |
| 82 | angular.element(e[0].parentNode).css({'min-height': e[0].querySelector('.power__confirm').offsetHeight + 'px'}); |
| 83 | }, 0); |
| 84 | }else{ |
| 85 | angular.element(e[0].parentNode).css({'min-height': 0+ 'px'}); |
| 86 | } |
| 87 | }); |
| 88 | } |
| 89 | }; |
| 90 | }]); |