monitoring: add copyrights
[src/app-framework-binder.git] / test / monitoring / monitor.js
index c4f24a0..2c53256 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 var afb;
 var ws;
@@ -8,10 +24,13 @@ var t_logmsg;
 var t_traceevent;
 var t_verbosity;
 var t_trace;
+var t_separator;
+
 var apis = {};
 var events = [];
 var inhibit = false;
 var msgs = false;
+var autoscroll = false;
 
 var root_node;
 var connected_node;
@@ -66,6 +85,7 @@ function init() {
        t_traceevent = at("t-traceevent").content.firstElementChild;
        t_verbosity = at("t-verbosity").content.firstElementChild;
        t_trace = at("t-trace").content.firstElementChild;
+       t_separator = at("t-separator").content.firstElementChild;
 
        root_node = at("root");
        connected_node = at("connected");
@@ -90,6 +110,9 @@ function init() {
        at("stopmsgs").onclick = toggle_logmsgs;
        start_logmsgs(false);
        trace_events_node.onclick = on_toggle_traceevent;
+       at("autoscroll").onclick = toggle_autoscroll;
+       start_autoscroll(true);
+       at("addsep").onclick = add_separator;
 
        connect();
 }
@@ -127,6 +150,21 @@ function onabort() {
        connected_node.className = "error";
 }
 
+function start_autoscroll(val) {
+       at("autoscroll").textContent = (autoscroll = val) ? "Stop scroll" : "Start scroll";
+}
+
+function toggle_autoscroll() {
+       start_autoscroll(!autoscroll);
+}
+
+function add_separator() {
+       var x = document.importNode(t_separator, true);
+       trace_events_node.append(x);
+       if (autoscroll)
+               x.scrollIntoView();
+}
+
 function start_logmsgs(val) {
        at("stopmsgs").textContent = (msgs = val) ? "Stop logs" : "Get logs";
 }
@@ -151,7 +189,9 @@ function add_logmsg(tag, content, add) {
        get(".close", x).onclick = function(evt){x.remove();};
        if (add)
                x.className = x.className + " " + add;
-       logmsgs_node.prepend(x);
+       logmsgs_node.append(x);
+       if (autoscroll)
+               x.scrollIntoView();
 }
 
 function add_error(tag, obj) {
@@ -164,15 +204,15 @@ function on_error_apis(obj) {
 
 function do_call(api_verb, request, onsuccess, onerror) {
        var call = api_verb + "(" + JSON.stringify(request, null, 1) + ")";
-       add_logmsg(call, "", "call");
+       add_logmsg("send request", call, "call");
        ws.call(api_verb, request).then(
                function(obj){
-                       add_logmsg(call + " SUCCESS:", JSON.stringify(obj, null, 1), "retok");
+                       add_logmsg("receive success", call + " -> " + JSON.stringify(obj, null, 1), "retok");
                        if (onsuccess)
                                onsuccess(obj);
                },
                function(obj){
-                       add_logmsg(call + " ERROR:", JSON.stringify(obj, null, 1), "reterr");
+                       add_logmsg("receive error", call + " -> ", JSON.stringify(obj, null, 1), "reterr");
                        if (onerror)
                                onerror(obj);
                });
@@ -377,9 +417,11 @@ function gottraceevent(obj) {
                })[type](desc);
        var tab = makeobj(desc, 4);
        if ("data" in data)
-               makeobjitem(tab, 1, "data", data.data);
+               makeobjitem(tab, 2, "data", data.data);
        get(".content", x).append(tab);
        trace_events_node.append(x);
+       if (autoscroll)
+               x.scrollIntoView();
 }
 
 function toggle_opened_closed(node, defval) {