cleanup
authorJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 13 Sep 2011 09:53:00 +0000 (09:53 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 13 Sep 2011 09:53:00 +0000 (09:53 +0000)
www/monitor.html
www/psensor.js

index 0e6bc06..04bfdc8 100644 (file)
@@ -8,26 +8,8 @@
     <script type="text/javascript" src="psensor.js"></script>
     <script>  
       $(document).ready(function() {          
-          $.getJSON("/api/1.0/sensors", function(data) {
-              $.each(data, function(i, item) {
-                  var sname = item["name"];
-                  var svalue = item["last_measure"]["value"];
-                  var smin = item["min"];
-                  var smax = item["max"];
-                  var stype = item["type"];
-                  var stype_str;
-                  var unit;
-
-                  unit = type_to_unit(stype);
-                  stype_str = type_to_str(stype);
-
-                  $("#sensors").append("<tr>"
-                                      +"<td>"
-                                      +"<a href='details.html?id="+escape("/api/1.0/sensors/"+item["id"])
-                                       +"'>"+sname+"</a></td>"
-                                      +"<td>"+svalue+unit+"</td><td>"+smin+unit+"</td><td>"+smax+unit+"</td><td>"+stype_str+"</td></tr>");                 
-              });          
-          });
+      
+          update_summary_sensors();
 
           $.getJSON("/api/1.0/sysinfo", function(data) {
               var load = Math.round(data["load"] * 100);
index 28d9c46..862aa1d 100644 (file)
@@ -67,13 +67,17 @@ function type_to_str(stype) {
 
 function type_to_unit(stype) {
     if (stype & 0x0001)
-        unit = " C";
+        unit = "C";
     else if (stype & 0x0002)
-        unit = " RPM";
+        unit = "RPM";
 
     return unit;
 }
 
+function value_to_str(value, type) {
+    return value+type_to_unit(type);
+}
+
 function get_url_params()
 {
     var vars, hashes, i;
@@ -162,4 +166,28 @@ function update_menu() {
        $("#menu-list").append(str);
     });
 
+}
+
+function update_summary_sensors() {
+    var name, value_str, min_str, max_str, type, type_str, url;
+
+    $.getJSON("/api/1.0/sensors", function(data) {
+        $.each(data, function(i, item) {
+            name = item["name"];
+            type = item["type"];
+            value_str = value_to_str(item["last_measure"]["value"], type);
+            min_str = value_to_str(item["min"], type);
+            max_str = value_to_str(item["max"], type);
+           type_str = type_to_str(type);
+           url = "details.html?id="+escape("/api/1.0/sensors/"+item["id"]);
+
+            $("#sensors").append("<tr>"
+                                +"<td><a href='"+url+"'>"+name+"</a></td>"
+                                +"<td>"+value_str+"</td>"
+                                +"<td>"+min_str+"</td>"
+                                +"<td>"+max_str+"</td>"
+                                +"<td>"+type_str+"</td>"
+                                +"</tr>");                 
+        });          
+    });
 }
\ No newline at end of file