Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 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 | |
| 11 | window.angular && (function (angular) { |
| 12 | 'use strict'; |
| 13 | |
| 14 | angular |
| 15 | .module('app.common.services') |
| 16 | .service('dataService', ['Constants', function (Constants) { |
Michael Davis | 7f89fad | 2017-07-31 18:36:45 -0500 | [diff] [blame] | 17 | this.app_version = "V.0.0.1"; |
Iftekharul Islam | 3471409 | 2017-09-06 10:45:27 -0500 | [diff] [blame^] | 18 | this.server_health = Constants.SERVER_HEALTH.unknown; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 19 | this.server_state = 'Unreachable'; |
| 20 | this.server_status = -2; |
| 21 | this.chassis_state = 'On'; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 22 | this.LED_state = Constants.LED_STATE_TEXT.off; |
| 23 | this.server_id = Constants.API_CREDENTIALS.host.replace(/[^\d]+/m,""); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 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 = ''; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 32 | this.sensorData = []; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 33 | |
Iftekharul Islam | ba556c3 | 2017-08-11 08:37:12 -0500 | [diff] [blame] | 34 | this.hostname = ""; |
| 35 | this.mac_address = ""; |
Iftekharul Islam | 3471409 | 2017-09-06 10:45:27 -0500 | [diff] [blame^] | 36 | this.remote_window_active = false; |
Iftekharul Islam | ba556c3 | 2017-08-11 08:37:12 -0500 | [diff] [blame] | 37 | |
| 38 | this.setNetworkInfo = function(data){ |
| 39 | this.hostname = data.hostname; |
| 40 | this.mac_address = data.mac_address; |
| 41 | } |
| 42 | |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 43 | this.setPowerOnState = function(){ |
| 44 | this.server_state = Constants.HOST_STATE_TEXT.on; |
| 45 | this.server_status = Constants.HOST_STATE.on; |
Iftekharul Islam | ba556c3 | 2017-08-11 08:37:12 -0500 | [diff] [blame] | 46 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 47 | |
| 48 | this.setPowerOffState = function(){ |
| 49 | this.server_state = Constants.HOST_STATE_TEXT.off; |
| 50 | this.server_status = Constants.HOST_STATE.off; |
Iftekharul Islam | ba556c3 | 2017-08-11 08:37:12 -0500 | [diff] [blame] | 51 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 52 | |
| 53 | this.setBootingState = function(){ |
| 54 | this.server_state = Constants.HOST_STATE_TEXT.booting; |
| 55 | this.server_status = Constants.HOST_STATE.booting; |
Iftekharul Islam | ba556c3 | 2017-08-11 08:37:12 -0500 | [diff] [blame] | 56 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 57 | |
| 58 | this.setUnreachableState = function(){ |
| 59 | this.server_state = Constants.HOST_STATE_TEXT.unreachable; |
| 60 | this.server_status = Constants.HOST_STATE.unreachable; |
| 61 | } |
Iftekharul Islam | 3471409 | 2017-09-06 10:45:27 -0500 | [diff] [blame^] | 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 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 92 | }]); |
| 93 | |
| 94 | })(window.angular); |