1/**
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) {
17            this.app_version = "V.0.0.1";
18            this.server_health = Constants.SERVER_HEALTH.unknown;
19            this.server_state = 'Unreachable';
20            this.server_status = -2;
21            this.chassis_state = 'On';
22            this.LED_state = Constants.LED_STATE_TEXT.off;
23            this.server_id = Constants.API_CREDENTIALS.host.replace(/[^\d]+/m,"");
24            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 = '';
32            this.sensorData = [];
33
34            this.hostname = "";
35            this.mac_address = "";
36            this.remote_window_active = false;
37
38            this.setNetworkInfo = function(data){
39                this.hostname = data.hostname;
40                this.mac_address = data.mac_address;
41            }
42
43            this.setPowerOnState = function(){
44                this.server_state = Constants.HOST_STATE_TEXT.on;
45                this.server_status = Constants.HOST_STATE.on;
46            }
47
48            this.setPowerOffState = function(){
49                this.server_state = Constants.HOST_STATE_TEXT.off;
50                this.server_status = Constants.HOST_STATE.off;
51            }
52
53            this.setBootingState = function(){
54                this.server_state = Constants.HOST_STATE_TEXT.booting;
55                this.server_status = Constants.HOST_STATE.booting;
56            }
57
58            this.setUnreachableState = function(){
59                this.server_state = Constants.HOST_STATE_TEXT.unreachable;
60                this.server_status = Constants.HOST_STATE.unreachable;
61            }
62
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            }
92        }]);
93
94})(window.angular);