blob: 23038a1151f60fd0eccc876925b68e91dbc90f5a [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001window.angular && (function (angular) {
2 'use strict';
3
4 angular
5 .module('app.common.directives')
6 .directive('appHeader', ['APIUtils', function (APIUtils) {
7 return {
8 'restrict': 'E',
9 'templateUrl': 'common/directives/app-header.html',
10 'scope': {
11 'path': '='
12 },
13 'controller': ['$rootScope', '$scope','dataService', 'userModel', '$location', function($rootScope, $scope, dataService, userModel, $location){
14 $scope.dataService = dataService;
15
16 $scope.loadServerStatus = function(){
17 if(!userModel.isLoggedIn()){
18 //@TODO:some error message?
19 return;
20 }
21 APIUtils.getHostState(function(status){
22 if(status == 'xyz.openbmc_project.State.Host.HostState.Off'){
23 dataService.setPowerOffState();
24 }else if(status == 'xyz.openbmc_project.State.Host.HostState.Running'){
25 dataService.setPowerOnState();
26 }else{
27 dataService.setBootingState();
28 }
29 });
30 }
31 $scope.loadServerStatus();
32
33 $scope.logout = function(){
34 userModel.logout(function(status, error){
35 if(status){
36 $location.path('/logout');
37 }else{
38 console.log(error);
39 }
40 });
41 }
42
43 $scope.refresh = function(){
44 $scope.loadServerStatus();
45 }
46
47 var loginListener = $rootScope.$on('user-logged-in', function(event, arg){
48 $scope.loadServerStatus();
49 });
50
51 $scope.$on('$destroy', function(){
52 loginListener();
53 });
54 }]
55 };
56 }]);
57})(window.angular);