From 9e620e46271260d3be7827961f36acf3fd15caa5 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Thu, 3 Sep 2020 20:00:37 -0600 Subject: [PATCH] Add event support and improve UI/UX --- www/assets/js/addevent.js | 125 ++++++++++++++++++++++++++++++++++++++ www/assets/js/machine.js | 32 +++++----- www/assets/js/util.js | 10 ++- www/index.html | 1 + www/pages/addevent.html | 92 ++++++++++++++++++++++++++++ www/pages/machine.html | 104 ++++++++++++++++++++++++++----- www/routes.js | 17 +++++- 7 files changed, 350 insertions(+), 31 deletions(-) create mode 100644 www/assets/js/addevent.js create mode 100644 www/pages/addevent.html diff --git a/www/assets/js/addevent.js b/www/assets/js/addevent.js new file mode 100644 index 0000000..337f1d5 --- /dev/null +++ b/www/assets/js/addevent.js @@ -0,0 +1,125 @@ +/* + * Copyright 2020 Netsyms Technologies. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function openEventAddScreen(machineid) { + app.dialog.preloader("Loading..."); + apirequest( + "geteventtypes", + {}, + function (resp) { + app.dialog.close(); + + catoptions = [ + + ]; + + for (const catlabel in resp) { + var options = []; + for (const optionval in resp[catlabel]) { + options.push({ + value: optionval, + label: resp[catlabel][optionval] + }); + } + catoptions.push({ + label: catlabel, + options: options + }); + } + + console.log(catoptions); + + router.navigate("/addevent", { + context: { + machineid: machineid, + fields: [ + { + name: "event", + label: "Event", + type: "select", + catoptions: catoptions, + value: "", + tabindex: 0 + }, + { + name: "date", + label: "Date/Time", + type: "datetime", + value: "", + tabindex: 1 + }, + { + name: "privatenotes", + label: "Private Notes", + type: "textarea", + value: "", + tabindex: 2 + }, + { + name: "publicnotes", + label: "Public Notes", + type: "textarea", + value: "", + tabindex: 3 + } + ] + } + }); + }, + function (xhr) { + app.dialog.close(); + var error = $.parseJSON(xhr.responseText); + if (error && typeof error.msg != 'undefined') { + app.dialog.alert(error.msg, "Error"); + } else { + app.dialog.alert("A server or network error occurred.", "Error"); + } + }, + getStorage("username"), + getStorage("password") + ); +} + +function addEvent(machineid) { + app.dialog.preloader("Adding event..."); + + var eventdata = { + id: machineid + }; + $("#eventform .eventfield").each(function (i, o) { + if ($(this).parent().is(".smart-select")) { + eventdata[$(this).attr("name")] = app.smartSelect.get('#smartselect-' + $(this).attr("name")).getValue(); + } else { + eventdata[$(this).attr("name")] = $(this).val(); + } + }); + + apirequest( + "addevent", + eventdata, + function (resp) { + app.dialog.close(); + if (resp.status == "ERROR") { + app.dialog.alert(resp.msg, "Error"); + } else { + app.toast.create({ + text: 'Event added!', + closeTimeout: 2000, + }).open(); + openMachineInfo(machineid); + } + }, + function (xhr) { + app.dialog.close(); + var error = $.parseJSON(xhr.responseText); + if (error && typeof error.msg != 'undefined') { + app.dialog.alert(error.msg, "Error"); + } else { + app.dialog.alert("A server or network error occurred.", "Error"); + } + }); +} \ No newline at end of file diff --git a/www/assets/js/machine.js b/www/assets/js/machine.js index b0fd714..76247ff 100644 --- a/www/assets/js/machine.js +++ b/www/assets/js/machine.js @@ -32,7 +32,7 @@ function addMachineToSearchHistory(machineid) { } function openMachineEditor(machineid) { - app.dialog.preloader("Loading..."); + app.dialog.preloader("Loading editor..."); apirequest( "lookup", @@ -89,14 +89,11 @@ function openMachineEditor(machineid) { } else { app.dialog.alert("A server or network error occurred.", "Error"); } - }, - getStorage("username"), - getStorage("password") - ); + }); } function openMachineInfo(machineid) { - app.dialog.preloader("Searching..."); + app.dialog.preloader("Loading..."); apirequest( "lookup", @@ -108,10 +105,23 @@ function openMachineInfo(machineid) { if (resp.status == "ERROR") { app.dialog.alert(resp.msg, "Error"); } else { + + var events = []; + for (var i = 0; i < resp.events.length; i++) { + events.push({ + name: resp.events[i].name, + date: timestampToDateTimeString(resp.events[i].date), + shortdate: formatTimestamp("M j", resp.events[i].date), + publicnotes: resp.events[i].publicnotes, + privatenotes: resp.events[i].privatenotes + }); + } + var context = { machineid: resp.id, type: resp.type, icon: resp.icon, + events: events, machineprops: { machineid: { name: "machineid", @@ -178,10 +188,7 @@ function openMachineInfo(machineid) { } else { app.dialog.alert("A server or network error occurred.", "Error"); } - }, - getStorage("username"), - getStorage("password") - ); + }); } function saveMachineEdits(machineid) { @@ -221,10 +228,7 @@ function saveMachineEdits(machineid) { } else { app.dialog.alert("A server or network error occurred.", "Error"); } - }, - getStorage("username"), - getStorage("password") - ); + }); } $("#app").on("keypress", "#machineform .machinefield", function (evt) { diff --git a/www/assets/js/util.js b/www/assets/js/util.js index ffea335..231b9e8 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -26,11 +26,17 @@ function uuidv4() { * @param {array} data AJAX data to POST * @param {function} success * @param {function} error - * @param {string|undefined} username - * @param {string|undefined} password + * @param {string|null|undefined} username null will send no authentication, undefined will fill from getStorage('username') + * @param {string|null|undefined} password null will send no authentication, undefined will fill from getStorage('password') * @returns {jqXHR} */ function apirequest(action, data, success, error, username, password) { + if (typeof username == 'undefined') { + username = getStorage("username"); + } + if (typeof password == 'undefined') { + password = getStorage("password"); + } return $.ajax({ url: SETTINGS.apiserver + action, dataType: "json", diff --git a/www/index.html b/www/index.html index 8c872c6..bd7aaf5 100644 --- a/www/index.html +++ b/www/index.html @@ -37,5 +37,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + diff --git a/www/pages/addevent.html b/www/pages/addevent.html new file mode 100644 index 0000000..8c33085 --- /dev/null +++ b/www/pages/addevent.html @@ -0,0 +1,92 @@ + + +
+ + + + + +
+
+
+ +
+
+
+ + +
\ No newline at end of file diff --git a/www/pages/machine.html b/www/pages/machine.html index 651bef0..9140ef5 100644 --- a/www/pages/machine.html +++ b/www/pages/machine.html @@ -20,17 +20,35 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. {{#if editable}} -
+ + + {{/if}} -
-
-
-
+
+
+ Info + Events + Client +
+
+ +
+
+
+
    {{#each machineprops}} {{#if value}} @@ -49,19 +67,75 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
- {{#if clientinfo}} - {{#with clientinfo}} -
-

Client

+
+
+
    + {{#each events}} +
  • +
    +
    {{name}}
    +
    {{shortdate}}
    +
    +
    +
    +
    +
    +
      +
    • +
      +
      +
      +
      Date/Time
      + {{date}} +
      +
      +
      +
    • + {{#if privatenotes}} +
    • +
      +
      +
      +
      Private Notes
      + {{privatenotes}} +
      +
      +
      +
    • + {{/if}} + {{#if publicnotes}} +
    • +
      +
      +
      +
      Public Notes
      + {{publicnotes}} +
      +
      +
      +
    • + {{/if}} +
    +
    +
    +
    +
    +
  • + {{/each}} +
+
+
-
-
+
+ {{#if clientinfo}} + {{#with clientinfo}} +
  • +
    Name
    {{name}}
    @@ -106,10 +180,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. {{/if}}
+ {{/with}} + {{else}} +
No client has been linked.
+ {{/if}}
- {{/with}} - {{/if}}