blob: 00ea1ba9a0cd1c0ae828b55ec13f425eb174c28a [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
2 * data service
3 *
4 * @module app/common/services/dataService
5 * @exports dataService
6 * @name dataService
7
8 * @version 0.0.1
9 */
10
11window.angular && (function (angular) {
12 'use strict';
13
14 angular
15 .module('app.common.services')
16 .service('dataService', ['Constants', function (Constants) {
Michael Davis7f89fad2017-07-31 18:36:45 -050017 this.app_version = "V.0.0.1";
Iftekharul Islam34714092017-09-06 10:45:27 -050018 this.server_health = Constants.SERVER_HEALTH.unknown;
Iftekharul Islam99d199f2017-03-24 15:28:25 -050019 this.server_state = 'Unreachable';
20 this.server_status = -2;
21 this.chassis_state = 'On';
Iftekharul Islamcd789502017-04-19 14:37:55 -050022 this.LED_state = Constants.LED_STATE_TEXT.off;
23 this.server_id = Constants.API_CREDENTIALS.host.replace(/[^\d]+/m,"");
Iftekharul Islam99d199f2017-03-24 15:28:25 -050024 this.last_updated = new Date();
25
26 this.loading = false;
27 this.server_unreachable = false;
28 this.loading_message = "";
29 this.showNavigation = false;
30 this.bodyStyle = {};
31 this.path = '';
Iftekharul Islamd2269e22017-05-02 09:32:45 -050032 this.sensorData = [];
Iftekharul Islam99d199f2017-03-24 15:28:25 -050033
Iftekharul Islamba556c32017-08-11 08:37:12 -050034 this.hostname = "";
35 this.mac_address = "";
Iftekharul Islam34714092017-09-06 10:45:27 -050036 this.remote_window_active = false;
Iftekharul Islamba556c32017-08-11 08:37:12 -050037
38 this.setNetworkInfo = function(data){
39 this.hostname = data.hostname;
40 this.mac_address = data.mac_address;
41 }
42
Iftekharul Islam99d199f2017-03-24 15:28:25 -050043 this.setPowerOnState = function(){
44 this.server_state = Constants.HOST_STATE_TEXT.on;
45 this.server_status = Constants.HOST_STATE.on;
Iftekharul Islamba556c32017-08-11 08:37:12 -050046 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050047
48 this.setPowerOffState = function(){
49 this.server_state = Constants.HOST_STATE_TEXT.off;
50 this.server_status = Constants.HOST_STATE.off;
Iftekharul Islamba556c32017-08-11 08:37:12 -050051 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050052
53 this.setBootingState = function(){
54 this.server_state = Constants.HOST_STATE_TEXT.booting;
55 this.server_status = Constants.HOST_STATE.booting;
Iftekharul Islamba556c32017-08-11 08:37:12 -050056 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050057
58 this.setUnreachableState = function(){
59 this.server_state = Constants.HOST_STATE_TEXT.unreachable;
60 this.server_status = Constants.HOST_STATE.unreachable;
61 }
Iftekharul Islam34714092017-09-06 10:45:27 -050062
63 this.setRemoteWindowActive = function(){
64 this.remote_window_active = true;
65 }
66
67 this.setRemoteWindowInactive = function(){
68 this.remote_window_active = false;
69 }
70
71 this.updateServerHealth = function(logs){
72 var criticals = logs.filter(function(item){
73 return item.health_flags.critical == true;
74 });
75
76 if(criticals.length){
77 this.server_health = Constants.SERVER_HEALTH.critical;
78 return;
79 }
80
81 var warnings = logs.filter(function(item){
82 return item.health_flags.warning == true;
83 });
84
85 if(warnings.length){
86 this.server_health = Constants.SERVER_HEALTH.warning;
87 return;
88 }
89
90 this.server_health = Constants.SERVER_HEALTH.good;
91 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050092 }]);
93
94})(window.angular);