From ff3386eb00cd8b5c1f3301168fca26e422595f71 Mon Sep 17 00:00:00 2001 From: Loïc Collignon Date: Fri, 26 Jan 2018 09:34:28 +0100 Subject: add debugging html ui. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4e84bec38d9a2483ad6dbe0e393cde62e8c2a862 Signed-off-by: Loïc Collignon --- .../htdocs/persistence/persistence-binding.js | 203 +++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 ll-database-binding/htdocs/persistence/persistence-binding.js (limited to 'll-database-binding/htdocs/persistence/persistence-binding.js') diff --git a/ll-database-binding/htdocs/persistence/persistence-binding.js b/ll-database-binding/htdocs/persistence/persistence-binding.js new file mode 100644 index 0000000..9b5550c --- /dev/null +++ b/ll-database-binding/htdocs/persistence/persistence-binding.js @@ -0,0 +1,203 @@ +var afb = new AFB("api", "HELLO"); +var ws; + +function add_debbug_panel() { + + if (document.getElementById("debug-panel")) + return; + + var itm = document.getElementById("debug-panel-container"); + if (itm) + { + var pnl = + "
\n" + + " \n" + + " \n" + + "
\n" + + "

Debug

\n" + + "

Call

\n" + + "
    \n" + + "
  • api :
  • \n" + + "
  • verb :
  • \n" + + "
  • query :
  • \n" + + "
\n" + + "
\n" +
+			"        
\n" + + "

Response

\n" +
+			"        

Event

\n" +
+			"    
\n" + + "
\n"; + itm.insertAdjacentHTML("afterbegin", pnl); + } +} + +function createClass(name,rules) { + var style = document.createElement('style'); + style.type = 'text/css'; + document.getElementsByTagName('head')[0].appendChild(style); + if(!(style.sheet||{}).insertRule) + (style.styleSheet || style.sheet).addRule(name, rules); + else + style.sheet.insertRule(name+"{"+rules+"}",0); +} + +function syntaxHighlight(json) { + if (typeof json != 'string') + json = JSON.stringify(json, undefined, 2); + + json = json.replace(/&/g, '&').replace(//g, '>'); + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { + var cls = 'json-number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'json-key'; + } else { + cls = 'json-string'; + } + } else if (/true|false/.test(match)) { + cls = 'json-boolean'; + } else if (/null/.test(match)) { + cls = 'json-null'; + } + return '' + match + ''; + }); +} + +function set_item_html(id, text) +{ + var itm = document.getElementById(id); + if (itm) itm.innerHTML = text; +} + +function set_item_text(id, text) +{ + var itm = document.getElementById(id); + if (itm) itm.innerText = text; +} + +function debug_panel_collapse() { + var pnl = document.getElementById('debug-panel'); + if (pnl) + { + pnl.classList.remove('expanded'); + pnl.classList.add('collapsed'); + } +} + +function debug_panel_expand() { + var pnl = document.getElementById('debug-panel'); + if (pnl) + { + pnl.classList.remove('collapsed'); + pnl.classList.add('expanded'); + } +} + +function init() { + add_debbug_panel(); + ws = new afb.ws(onopen, onabort); +} + +function onopen() { + //callbinder("ll-auth", "getuser", ""); + ws.onevent("*", gotevent); +} + +function onabort() { +} + +function replyok(obj) { + console.log("replyok:" + JSON.stringify(obj)); + set_item_html("debug-panel-response", syntaxHighlight(JSON.stringify(obj, null, 4))); +} + +function replyerr(obj) { + console.log("replyerr:" + JSON.stringify(obj)); + set_item_html("debug-panel-response", syntaxHighlight(JSON.stringify(obj, null, 4))); +} + +function gotevent(obj) { + console.log("gotevent:" + JSON.stringify(obj)); + set_item_html("debug-panel-event", syntaxHighlight(JSON.stringify(obj, null, 4))); +} + +function callbinder(api, verb, query) { + console.log ("subscribe api="+api+" verb="+verb+" query=" +query); + + set_item_text("debug-panel-call-api", api); + set_item_text("debug-panel-call-verb", verb); + set_item_html("debug-panel-call-query", syntaxHighlight(JSON.stringify(query, null, 4))); + + ws.call(api+"/"+verb, query).then(replyok, replyerr); +} + +function value(id){ + return document.getElementById(id).value; +} + +function readData() { + callbinder("persistence", "read", { "key": value("read-key") }); +} + +function deleteData() { + callbinder("persistence", "delete", { "key": value("read-key")}); +} + +function writeData() { + callbinder("persistence", "update", { + "key": value("write-key"), + "value": value("write-data") + }); +} + +function readProfile() { + var vin = value("profile-vin") + var token = value("get-profile-key") + var url = "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken?vin=" + vin + "&kind=nfc&keytoken=" + token + + callbinder("persistence", "read", { + "key": { + "url": url, + "vin": vin, + "kind": "nfc", + "key": token + } + }); +} + +function deleteProfile() { + var vin = value("profile-vin") + var token = value("get-profile-key") + var url = "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken?vin=" + vin + "&kind=nfc&keytoken=" + token + + callbinder("persistence", "delete", { + "key": { + "url": url, + "vin": vin, + "kind": "nfc", + "key": token + } + }); +} + +function writeProfile() { + var vin = value("profile-vin") + var token = value("set-profile-key") + var url = "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken?vin=" + vin + "&kind=nfc&keytoken=" + token + + callbinder("persistence", "update", { + "key": { + "url": url, + "vin": vin, + "kind": "nfc", + "key": token + }, + "value": { + "keytoken": token, + "name": value("set-profile-login"), + "first_name": value("set-profile-first-name"), + "last_name": value("set-profile-last-name"), + "graphPreferredLanguage": value("set-profile-language") + } + }); +} -- cgit 1.2.3-korg