summaryrefslogtreecommitdiffstats
path: root/app/common/directives/app-header.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/common/directives/app-header.js')
-rw-r--r--app/common/directives/app-header.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/common/directives/app-header.js b/app/common/directives/app-header.js
new file mode 100644
index 0000000..23038a1
--- /dev/null
+++ b/app/common/directives/app-header.js
@@ -0,0 +1,57 @@
+window.angular && (function (angular) {
+ 'use strict';
+
+ angular
+ .module('app.common.directives')
+ .directive('appHeader', ['APIUtils', function (APIUtils) {
+ return {
+ 'restrict': 'E',
+ 'templateUrl': 'common/directives/app-header.html',
+ 'scope': {
+ 'path': '='
+ },
+ 'controller': ['$rootScope', '$scope','dataService', 'userModel', '$location', function($rootScope, $scope, dataService, userModel, $location){
+ $scope.dataService = dataService;
+
+ $scope.loadServerStatus = function(){
+ if(!userModel.isLoggedIn()){
+ //@TODO:some error message?
+ return;
+ }
+ APIUtils.getHostState(function(status){
+ if(status == 'xyz.openbmc_project.State.Host.HostState.Off'){
+ dataService.setPowerOffState();
+ }else if(status == 'xyz.openbmc_project.State.Host.HostState.Running'){
+ dataService.setPowerOnState();
+ }else{
+ dataService.setBootingState();
+ }
+ });
+ }
+ $scope.loadServerStatus();
+
+ $scope.logout = function(){
+ userModel.logout(function(status, error){
+ if(status){
+ $location.path('/logout');
+ }else{
+ console.log(error);
+ }
+ });
+ }
+
+ $scope.refresh = function(){
+ $scope.loadServerStatus();
+ }
+
+ var loginListener = $rootScope.$on('user-logged-in', function(event, arg){
+ $scope.loadServerStatus();
+ });
+
+ $scope.$on('$destroy', function(){
+ loginListener();
+ });
+ }]
+ };
+ }]);
+})(window.angular);
OpenPOWER on IntegriCloud