blob: 79224f022727b8a6448698d044e168dc79549ea6 [file] [log] [blame]
Iftekharul Islamf157d372017-03-08 11:11:27 -06001
2
3angular
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 Islam115984a2017-03-09 09:47:35 -060013 'controller': ['$scope','dataService', 'userModel', '$location', function($scope, dataService, userModel, $location){
Iftekharul Islamf157d372017-03-08 11:11:27 -060014 $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 Islam115984a2017-03-09 09:47:35 -060028 $scope.logout = function(){
29 userModel.logout();
30 $location.path('/logout');
Michael Davis9e00ce92017-03-09 18:31:02 -060031 };
Iftekharul Islam115984a2017-03-09 09:47:35 -060032
Iftekharul Islamf157d372017-03-08 11:11:27 -060033 $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 Davis9e00ce92017-03-09 18:31:02 -060050 var paddingTop = 0;
51 $scope.toggle = false;
Iftekharul Islamf157d372017-03-08 11:11:27 -060052 $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 Davis9e00ce92017-03-09 18:31:02 -060060
Iftekharul Islamf157d372017-03-08 11:11:27 -060061 }]
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 Davisea5241a2017-07-12 15:56:55 -050089 angular.element(e[0].parentNode).css({'min-height': e[0].querySelector('.inline__confirm').offsetHeight + 'px'});
Iftekharul Islamf157d372017-03-08 11:11:27 -060090 }, 0);
91 }else{
92 angular.element(e[0].parentNode).css({'min-height': 0+ 'px'});
93 }
94 });
95 }
96 };
97 }]);