blob: 0553bf6c7e89ab2cec2884191f96b8cca3f28116 [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;
Iftekharul Islam99d199f2017-03-24 15:28:25 -050023 this.last_updated = new Date();
24
25 this.loading = false;
26 this.server_unreachable = false;
27 this.loading_message = "";
28 this.showNavigation = false;
29 this.bodyStyle = {};
30 this.path = '';
Iftekharul Islamd2269e22017-05-02 09:32:45 -050031 this.sensorData = [];
Iftekharul Islam99d199f2017-03-24 15:28:25 -050032
Iftekharul Islamba556c32017-08-11 08:37:12 -050033 this.hostname = "";
34 this.mac_address = "";
Iftekharul Islam34714092017-09-06 10:45:27 -050035 this.remote_window_active = false;
Iftekharul Islamba556c32017-08-11 08:37:12 -050036
Iftekharul Islam1acb4122017-11-02 13:20:32 -050037 this.getServerId = function(){
Sivas SRRbb9092a2018-01-27 08:40:58 -060038 return this.host.replace(/^https?\:\/\//ig,"");
Iftekharul Islam1acb4122017-11-02 13:20:32 -050039 }
40
41 this.reloadServerId = function(){
42 this.server_id = this.getServerId();
43 }
44
45 this.getHost = function(){
46 if(sessionStorage.getItem(Constants.API_CREDENTIALS.host_storage_key) !== null){
47 return sessionStorage.getItem(Constants.API_CREDENTIALS.host_storage_key);
48 }else{
49 return Constants.API_CREDENTIALS.default_protocol + "://" +
50 window.location.hostname + ':' +
51 window.location.port;
52 }
53 }
54
55 this.setHost = function(hostWithPort){
56 hostWithPort = hostWithPort.replace(/^https?\:\/\//ig, '');
57 var hostURL = Constants.API_CREDENTIALS.default_protocol + "://" + hostWithPort;
58 sessionStorage.setItem(Constants.API_CREDENTIALS.host_storage_key, hostURL);
59 this.host = hostURL;
60 this.reloadServerId();
61 }
62
Gunnar Mills1a60f6e2018-03-14 13:42:08 -050063 this.getUser = function(){
64 return sessionStorage.getItem('LOGIN_ID');
65 }
66
Iftekharul Islam1acb4122017-11-02 13:20:32 -050067 this.host = this.getHost();
68 this.server_id = this.getServerId();
69
Iftekharul Islamba556c32017-08-11 08:37:12 -050070 this.setNetworkInfo = function(data){
71 this.hostname = data.hostname;
72 this.mac_address = data.mac_address;
73 }
74
Iftekharul Islam99d199f2017-03-24 15:28:25 -050075 this.setPowerOnState = function(){
76 this.server_state = Constants.HOST_STATE_TEXT.on;
77 this.server_status = Constants.HOST_STATE.on;
Iftekharul Islamba556c32017-08-11 08:37:12 -050078 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050079
80 this.setPowerOffState = function(){
81 this.server_state = Constants.HOST_STATE_TEXT.off;
82 this.server_status = Constants.HOST_STATE.off;
Iftekharul Islamba556c32017-08-11 08:37:12 -050083 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050084
85 this.setBootingState = function(){
86 this.server_state = Constants.HOST_STATE_TEXT.booting;
87 this.server_status = Constants.HOST_STATE.booting;
Iftekharul Islamba556c32017-08-11 08:37:12 -050088 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050089
90 this.setUnreachableState = function(){
91 this.server_state = Constants.HOST_STATE_TEXT.unreachable;
92 this.server_status = Constants.HOST_STATE.unreachable;
93 }
Iftekharul Islam34714092017-09-06 10:45:27 -050094
95 this.setRemoteWindowActive = function(){
96 this.remote_window_active = true;
97 }
98
99 this.setRemoteWindowInactive = function(){
100 this.remote_window_active = false;
101 }
102
103 this.updateServerHealth = function(logs){
104 var criticals = logs.filter(function(item){
105 return item.health_flags.critical == true;
106 });
107
108 if(criticals.length){
109 this.server_health = Constants.SERVER_HEALTH.critical;
110 return;
111 }
112
113 var warnings = logs.filter(function(item){
114 return item.health_flags.warning == true;
115 });
116
117 if(warnings.length){
118 this.server_health = Constants.SERVER_HEALTH.warning;
119 return;
120 }
121
122 this.server_health = Constants.SERVER_HEALTH.good;
123 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500124 }]);
125
Sivas SRRbb9092a2018-01-27 08:40:58 -0600126})(window.angular);