Attempt to get image streaming page back from the dead (untested).
[matches/MCTX3420.git] / testing / MCTXWeb / public_html / static / mctx.gui.js
index c609ef5..1c3eb1f 100644 (file)
@@ -25,8 +25,12 @@ mctx.menu = [
     {'text' : 'Help', href : mctx.location + 'help.html'}
 ];
 
-mctx.statusCodes = {
-    STATUS_OK : 1
+mctx.status = {
+    OK : 1,
+    ERROR : -1,
+    UNAUTHORIZED : -2,
+    NOTRUNNING : -3,
+    ALREADYEXISTS : -4
 };
 
 mctx.statusCodesDescription = {
@@ -54,6 +58,9 @@ mctx.actuators = {
     3 : {name : "Pressure regulator"}
 };
 
+mctx.actuator = {};
+mctx.actuator.pressure_regulator = 0;
+
 mctx.strain_gauges = {};
 mctx.strain_gauges.ids = [0, 1, 2, 3];
 mctx.strain_gauges.time_limit = 20;
@@ -71,7 +78,14 @@ function debugLog () {
                 alert(arguments[i]);
             }
         } else {
-            console.log.apply(this, arguments);
+            try {
+              console.log.apply(this, arguments);
+            } catch (e) {
+              //Chromie
+              for (var i = 0; i < arguments.length; i++) {
+                console.log(arguments[i]);
+              }
+            }
         }
     }
 }
@@ -109,8 +123,30 @@ function runBeforeLoad(isLoginPage) {
                 window.location = mctx.location + "login.html";
             }
         } else {
-            mctx.friendlyName = data.friendly_name;
+            mctx.friendlyName = data.user_name;
         }
+        
+        $(document).ready(function () {
+          //Show the content!
+          $("#content").css("display", "block");
+          
+          //Set the welcome bar
+          var name = " " + (mctx.friendlyName ? mctx.friendlyName : "");
+          $("#welcome-container").text("Welcome"+ name + "!");
+          $("#logout-container").css("display", "block");
+          //$("#menu-container").populateNavbar();
+
+          $("#logout").click(function () {
+            $("#logout").logout();
+          });\r
+          \r
+          $("#change-password").click(function () {\r
+            window.open("users/user_change_details.php");\r
+          });
+          
+          //Enable the error log, if present
+          $("#errorlog").setErrorLog();
+        });
     }).fail(function (jqHXR) {
         if (mctx.debug) {
             debugLog("Failed to ident server. Is API running?")
@@ -138,74 +174,6 @@ $.fn.populateNavMenu = function() {
     return this;
 }
 
-/**
-* Sets the camera autoupdater
-* Obsolete?
-* @returns {$.fn}
-*/
-$.fn.setCamera = function () {
-    var url = mctx.api + "image";  //http://beaglebone/api/image
-    var update = true;
-
-    //Stop updating if we can't retrieve an image!
-    this.error(function() {
-        update = false;
-    });
-
-    var parent = this;
-
-    var updater = function() {
-        if (!update) {
-            alert("Cam fail");
-            parent.attr("src", "");
-            return;
-        }
-        
-        parent.attr("src", url + "#" + (new Date()).getTime());
-        
-        setTimeout(updater, 10000);
-    };
-
-    updater();
-    return this;
-};
-
-/**
-* Sets the strain graphs to graph stuff. Obsolete?
-* @returns {$.fn}
-*/
-$.fn.setStrainGraphs = function () {
-    var sensor_url = mctx.api + "sensors";
-    var graphdiv = this;
-
-    var updater = function () {
-        var time_limit = mctx.strain_gauges.time_limit;
-        var responses = new Array(mctx.strain_gauges.ids.length);
-        
-        for (var i = 0; i < mctx.strain_gauges.ids.length; i++) {
-            var parameters = {id : i, start_time: -time_limit};
-            responses[i] = $.ajax({url : sensor_url, data : parameters});
-        }
-        
-        $.when.apply(this, responses).then(function () {
-            var data = new Array(arguments.length);
-            for (var i = 0; i < arguments.length; i++) {
-                var raw_data = arguments[i][0].data;
-                var pruned_data = [];
-                var step = ~~(raw_data.length/100);
-                for (var j = 0; j < raw_data.length; j += step)
-                pruned_data.push(raw_data[j]); 
-                data[i] = pruned_data;
-            }
-            $.plot(graphdiv, data);
-            setTimeout(updater, 1000);
-        }, function () {debugLog("It crashed");});
-    };
-
-    updater();
-    return this;
-};
-
 /**
 * Performs a login attempt.
 * @returns The AJAX object of the login request */
@@ -222,6 +190,7 @@ $.fn.login = function () {
 
     return $.ajax({
         url : mctx.api + "bind",
+        type : "POST",
         data : {user: username, pass : password}
     }).done(function (data) {
         if (data.status < 0) {
@@ -258,6 +227,40 @@ $.fn.logout = function () {
     });
 };
 
+/**
+* Sets the camera autoupdater
+* Obsolete?
+* @returns {$.fn}
+*/
+$.fn.setCamera = function () {
+  var url = mctx.api + "image"; //http://beaglebone/api/image
+  var update = true;
+
+  //Stop updating if we can't retrieve an image!
+  this.error(function() {
+    update = false;
+  });
+  
+  var parent = this;
+  
+  var updater = function() {
+    if (!update) {
+      parent.parent().text("Cam fail");
+      parent.attr("src", "");
+      return;
+    }
+    
+    parent.attr("src", url + "#" + (new Date()).getTime());
+    
+    setTimeout(updater, 2000);
+  };
+  
+  updater();
+  return this;
+};
+
+
+
 /**
 * Sets the error log to continuously update.
 * @returns itself */
@@ -265,11 +268,16 @@ $.fn.setErrorLog = function () {
     var url = mctx.api + "errorlog";
     var outdiv = this;
 
+    if ($(this).length <= 0) {
+      //No error log, so do nothing.
+      return;
+    }
+
     var updater = function () {
         $.ajax({url : url}).done(function (data) {
             outdiv.text(data);
             outdiv.scrollTop(
-            outdiv[0].scrollHeight - outdiv.height()
+              outdiv[0].scrollHeight - outdiv.height()
             );
             setTimeout(updater, 3000);
         }).fail(function (jqXHR) {
@@ -284,6 +292,30 @@ $.fn.setErrorLog = function () {
     return this;
 };
 
+$.fn.checkStatus = function(data) {
+  if (data.status !== mctx.status.OK) {
+    $(this).text(data.description).removeClass("pass").addClass("fail");
+    return false;
+  }
+  $(this).removeClass("fail");
+  return true;
+};
+
+$(document).ready(function () {
+  //Enable the hide/show clicks
+  $("#sidebar-hide").click(function () {
+    $("#sidebar").hide();
+    $("#sidebar-show").show();
+    return this;
+  });
+
+  $("#sidebar-show").click(function () {
+    $("#sidebar-show").hide();
+    $("#sidebar").show();
+    return this;
+  });
+});
+
 $(document).ajaxError(function (event, jqXHR) {
     //console.log("AJAX query failed with: " + jqXHR.status + " (" + jqXHR.statusText + ")");
 });
\ No newline at end of file

UCC git Repository :: git.ucc.asn.au