summaryrefslogtreecommitdiffstats
path: root/app/common/services
diff options
context:
space:
mode:
authorIftekharul Islam <iislam@us.ibm.com>2017-05-02 09:32:45 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-09-20 12:44:06 -0500
commitd2269e22c6b5f992b2e6a10e9786f1c2421b4d42 (patch)
treef4f67b389057a7f9ed6cb0c1f06202c44a103ba4 /app/common/services
parent2284d2c3d5cf7cd218958480b7e9d71f41a9f27f (diff)
downloadphosphor-webui-d2269e22c6b5f992b2e6a10e9786f1c2421b4d42.tar.gz
phosphor-webui-d2269e22c6b5f992b2e6a10e9786f1c2421b4d42.zip
Updating sensors logics with mock data
Change-Id: Icede8defdae3a677db5c13dcd6324a1117ce25db Signed-off-by: Iftekharul Islam <iislam@us.ibm.com>
Diffstat (limited to 'app/common/services')
-rw-r--r--app/common/services/api-utils.js116
-rw-r--r--app/common/services/constants.js88
-rw-r--r--app/common/services/dataService.js1
3 files changed, 205 insertions, 0 deletions
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index d177366..120bcb8 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -360,6 +360,122 @@ window.angular && (function (angular) {
}).error(function(error){
console.log(error);
});
+ },
+ getAllSensorStatus: function(callback){
+ /**
+ GET https://9.3.185.156/xyz/openbmc_project/sensors/enumerate
+ */
+ $http({
+ method: 'GET',
+ url: "/assets/mocks/sensors.json",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ var dataClone = JSON.parse(JSON.stringify(content.data));
+ var sensorData = [];
+ var allSensorSeveries = [];
+ var allSensorRows = [];
+ var total = 0;
+ var status = 'normal';
+ var data = {
+ total: 0,
+ status: '',
+ sensors: [{
+ title: 'All Sensors',
+ type: 'all',
+ status: '',
+ severity_flags: {},
+ search_text: '',
+ display_headers: ['Sensor (Unit)', 'Reading', 'State'],
+ data: []
+ }]
+ };
+
+ function getSensorStatus(reading){
+ var severityFlags = {critical: false, warning: false, normal: false}, severityText = '';
+ if(reading.Value >= reading.CriticalLow && reading.Value <= reading.CriticalHigh){
+ severityFlags.critical = true;
+ severityText = 'critical';
+ }
+ else if(reading.Value >= reading.WarningLow && reading.Value <= reading.WarningHigh){
+ severityFlags.warning = true;
+ severityText = 'warning';
+ }else{
+ severityFlags.normal = true;
+ severityText = 'normal';
+ }
+ return { flags: severityFlags, severityText: severityText};
+ }
+
+ for(var key in content.data){
+ if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){
+ sensorData.push(Object.assign({
+ path: key,
+ selected: false,
+ confirm: false,
+ copied: false,
+ original_data: {key: key, value: content.data[key]}
+ }, content.data[key]));
+ }
+ }
+
+ Constants.SENSOR_DATA_TEMPLATE.sensors.forEach(function(sensor){
+ var rowData = [];
+ var severities = [];
+ var thisSensorData = sensorData.filter(function(el){
+ return el.path.indexOf('sensors/'+sensor.key_search) > -1;
+ });
+
+ for(var i = 0; i < thisSensorData.length; i++){
+
+ var severity = getSensorStatus(thisSensorData[i]);
+ severities.push(severity.severityText);
+ rowData.push(Object.assign({
+ title: sensor.sensor_row.title + (i+1),
+ status: severity.severityText,
+ severity_flags: severity.flags,
+ reading: thisSensorData[i].Value + sensor.sensor_row.reading,
+ search_text: (sensor.sensor_row.title + (i+1) + " " + severity.severityText + " " + thisSensorData[i].Value + sensor.sensor_row.reading).toLowerCase(),
+ indicator: (severity.flags.critical) ? '90%' : ((severity.flags.warning) ? '15%' : '50%')
+ }, thisSensorData[i]));
+ }
+
+ status = (severities.indexOf('critical') > -1) ? 'critical' : ((severities.indexOf('warning') > -1) ? 'warning' : 'normal');
+ total += rowData.length;
+ allSensorSeveries.push(status);
+ var sevFlags = {critical: false, warning: false, normal: false};
+ sevFlags[status] = true;
+ data.sensors.push({
+ title: sensor.title,
+ type: sensor.type,
+ status: status,
+ severity_flags: sevFlags,
+ search_text: (sensor.title + " " + status).toLowerCase(),
+ display_headers: sensor.display_headers,
+ data: rowData
+ });
+ Array.prototype.push.apply(allSensorRows, rowData);
+ });
+
+ data.status = (allSensorSeveries.indexOf('critical') > -1) ? 'critical' : ((allSensorSeveries.indexOf('warning') > -1) ? 'warning' : 'normal');
+ data.total = total;
+ if(allSensorRows.length){
+ data.sensors[0].status = data.status;
+ data.sensors[0].data = allSensorRows;
+ data.sensors[0].search_text = (data.sensors[0].title + " " + data.sensors[0].status).toLowerCase();
+ var flags = {critical: false, warning: false, normal: false};
+ flags[data.status] = true;
+ data.sensors[0].severity_flags = flags;
+ }
+ callback(data, dataClone);
+ }).error(function(error){
+ console.log(error);
+ });
}
};
return SERVICE;
diff --git a/app/common/services/constants.js b/app/common/services/constants.js
index 86ba54e..dba4afa 100644
--- a/app/common/services/constants.js
+++ b/app/common/services/constants.js
@@ -59,6 +59,94 @@ window.angular && (function (angular) {
},
PAGINATION: {
LOG_ITEMS_PER_PAGE: 4
+ },
+ SENSOR_DATA_TEMPLATE: {
+ sensors: [
+ {
+ type: 'fan',
+ title: 'Fan Speed',
+ key_search: 'fan_tach',
+ display_headers: ['Fan Speed(RPM)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Fan Speed ',
+ reading: ' rpms',
+ status: '',
+ indicator: ''
+ }
+ },
+ {
+ type: 'temperature',
+ title: 'Temperature',
+ 'key_search': 'temperature',
+ display_headers: ['Temperature (DegreesC)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Temperature ',
+ reading: ' degreeC',
+ status: '',
+ indicator: ''
+ }
+ },
+ {
+ type: 'altitude',
+ title: 'Altitude',
+ 'key_search': 'altitude',
+ display_headers: ['Altitude (Meters)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Altitude ',
+ reading: ' Meters',
+ status: '',
+ indicator: ''
+ }
+ },
+ {
+ type: 'voltage',
+ title: 'Voltage',
+ 'key_search': 'voltage',
+ display_headers: ['Temperature (Volts)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Voltage ',
+ reading: ' volts',
+ status: '',
+ indicator: ''
+ }
+ },
+ {
+ type: 'current',
+ title: 'Current',
+ 'key_search': 'current',
+ display_headers: ['Current (Amperes)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Current ',
+ reading: ' amperes',
+ status: '',
+ indicator: ''
+ }
+ },
+ {
+ type: 'power',
+ title: 'Power',
+ 'key_search': 'power',
+ display_headers: ['Power (Watts)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Power ',
+ reading: ' watts',
+ status: '',
+ indicator: ''
+ }
+ },
+ {
+ type: 'energy',
+ title: 'Energy',
+ 'key_search': 'energy',
+ display_headers: ['Energy (Joules)', 'Reading', 'State'],
+ sensor_row: {
+ title: 'Energy ',
+ reading: ' joules',
+ status: '',
+ indicator: ''
+ }
+ }
+ ]
}
};
});
diff --git a/app/common/services/dataService.js b/app/common/services/dataService.js
index 2affcc4..4cb72c5 100644
--- a/app/common/services/dataService.js
+++ b/app/common/services/dataService.js
@@ -29,6 +29,7 @@ window.angular && (function (angular) {
this.showNavigation = false;
this.bodyStyle = {};
this.path = '';
+ this.sensorData = [];
this.setPowerOnState = function(){
this.server_state = Constants.HOST_STATE_TEXT.on;
OpenPOWER on IntegriCloud