blob: a2f510e8a35d27bf46e82997efae0219156b4d43 [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();
Michael Davisa5f222a2017-08-04 15:02:38 -050045
46 //Add flash class to header timestamp on click of refresh
47 var myEl = angular.element( document.querySelector( '.header__refresh' ) );
48 myEl.addClass('flash');
49 setTimeout(function () {
50 myEl.removeClass("flash");
51 },2000);
52
Iftekharul Islam99d199f2017-03-24 15:28:25 -050053 }
54
55 var loginListener = $rootScope.$on('user-logged-in', function(event, arg){
56 $scope.loadServerStatus();
57 });
58
59 $scope.$on('$destroy', function(){
60 loginListener();
61 });
62 }]
63 };
64 }]);
65})(window.angular);