blob: a6cb77a42eb725031fabb51fe650c4374a7dff7f [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');
31 }
32
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(){
50 var padingTop = 0;
51 $scope.firstLevel = 'overview';
52 $scope.secondLevel = 'system_overview';
53 if($scope.showNavigation){
54 paddingTop = document.getElementById('header__wrapper').offsetHeight;
55 }
56 dataService.bodyStyle = {'padding-top': paddingTop + 'px'};
57 $scope.navStyle = {'top': paddingTop + 'px'};
58 });
59 }]
60 };
61 })
62 .directive('confirm', ['$timeout', function($timeout){
63
64 return {
65 'restrict': 'E',
66 'templateUrl': 'confirm.html',
67 'scope': {
68 'title': '@',
69 'message': '@',
70 'confirm': '=',
71 'callback': '='
72 },
73 'controller': ['$scope',function($scope){
74 $scope.cancel = function(){
75 $scope.confirm = false;
76 $scope.$parent.confirm = false;
77 };
78 $scope.accept = function(){
79 $scope.callback();
80 $scope.cancel();
81 }
82 }],
83 link: function(scope, e) {
84 scope.$watch('confirm', function(){
85 if(scope.confirm){
86 $timeout(function(){
Michael Davisea5241a2017-07-12 15:56:55 -050087 angular.element(e[0].parentNode).css({'min-height': e[0].querySelector('.inline__confirm').offsetHeight + 'px'});
Iftekharul Islamf157d372017-03-08 11:11:27 -060088 }, 0);
89 }else{
90 angular.element(e[0].parentNode).css({'min-height': 0+ 'px'});
91 }
92 });
93 }
94 };
95 }]);