From 664d54ae97218ea78f306d87a41108415174bc43 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 8 Jan 2020 01:10:09 -0700 Subject: [PATCH] Add route notes feature (#22) TODO: street autofill and integration --- www/assets/images/note-dashed.svg | 61 ++++++++++++++ www/assets/js/main.js | 12 --- www/assets/js/notes.js | 128 ++++++++++++++++++++++++++++++ www/assets/js/util.js | 11 +++ www/pages/home.html | 8 ++ www/pages/login.html | 2 +- www/pages/myroute.html | 66 +++++++++++++++ www/pages/myroute/editnote.html | 79 ++++++++++++++++++ www/routes.js | 68 ++++++++++++++-- www/settings.js | 14 ++++ 10 files changed, 428 insertions(+), 21 deletions(-) create mode 100644 www/assets/images/note-dashed.svg create mode 100644 www/assets/js/notes.js create mode 100644 www/pages/myroute.html create mode 100644 www/pages/myroute/editnote.html diff --git a/www/assets/images/note-dashed.svg b/www/assets/images/note-dashed.svg new file mode 100644 index 0000000..594b374 --- /dev/null +++ b/www/assets/images/note-dashed.svg @@ -0,0 +1,61 @@ + + diff --git a/www/assets/js/main.js b/www/assets/js/main.js index aec5a32..efa64bf 100644 --- a/www/assets/js/main.js +++ b/www/assets/js/main.js @@ -37,18 +37,6 @@ function restartApplication() { window.location = "index.html"; } -/** - * Generate a UUID. - * From https://stackoverflow.com/a/2117523 - * @returns {String} - */ -function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} - router.on("pageInit", function (pagedata) { pagedata.$el.find('script').each(function (el) { diff --git a/www/assets/js/notes.js b/www/assets/js/notes.js new file mode 100644 index 0000000..8ee6476 --- /dev/null +++ b/www/assets/js/notes.js @@ -0,0 +1,128 @@ +/* + * 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/. + */ + +if (inStorage("notes")) { + var notes = JSON.parse(getStorage("notes")); +} else { + var notes = []; + setStorage("notes", "[]"); +} + +function saveNote(id) { + var exists = false; + var index = -1; + for (var i = 0; i < notes.length; i++) { + if (notes[i].id == id) { + exists = true; + index = i; + } + } + + var note = { + id: id, + number: "", + street: "", + notes: "", + toggles: {} + }; + if (exists) { + note = notes[index]; + } + + note.number = $("input[name=number]").val(); + note.street = $("input[name=street]").val(); + note.notes = $("textarea#notes").val(); + + for (i in SETTINGS.routenotetoggles) { + var toggle = SETTINGS.routenotetoggles[i]; + note.toggles[toggle.id] = $(".note-toggle[data-id=" + toggle.id + "]").is(":checked"); + } + if (exists) { + notes[index] = note; + } else { + notes.push(note); + } + + + setStorage("notes", JSON.stringify(notes)); + + app.toast.show({ + text: " Note saved!", + position: "bottom", + destroyOnClose: true, + closeTimeout: 1000 * 3 + }); +} + +function deleteNote(id) { + for (var i = 0; i < notes.length; i++) { + if (notes[i].id == id) { + notes.splice(i, 1); + } + } + setStorage("notes", JSON.stringify(notes)); +} + +$(".view-main").on("click", "#savenotebtn", function () { + saveNote($(this).data("noteid")); +}); + +$(".view-main").on("click", ".editnotebtn", function () { + var noteid = $(this).data("noteid"); + + var note = {}; + for (var i = 0; i < notes.length; i++) { + if (notes[i].id == noteid) { + note = notes[i]; + } + } + + var toggles = []; + for (t in SETTINGS.routenotetoggles) { + var toggle = SETTINGS.routenotetoggles[t]; + toggles.push({ + id: toggle.id, + name: toggle.name, + checked: note.toggles[toggle.id] == true + }); + } + + router.navigate("/myroute/editnote", { + context: { + title: "Edit Note", + toggles: toggles, + noteid: noteid, + note: note + } + }); +}); + +$(".view-main").on("click", ".deletenotebtn", function () { + var noteid = $(this).data("noteid"); + app.dialog.confirm("Delete note?", "Confirm", function () { + deleteNote(noteid); + router.navigate("/myroute", { + reloadCurrent: true + }) + }); +}); + +function getToggleName(id) { + for (i in SETTINGS.routenotetoggles) { + if (SETTINGS.routenotetoggles[i].id == id) { + return SETTINGS.routenotetoggles[i].name; + } + } + return ""; +} + +Template7.registerHelper('notetogglename', function (key) { + return getToggleName(key); +}); + +Template7.registerHelper('newlinestobr', function (text) { + return text.replace(/(?:\r\n|\r|\n)/g, '
'); +}); \ No newline at end of file diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 064d4f2..b2d4aa8 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -4,6 +4,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/** + * Generate a UUID. + * From https://stackoverflow.com/a/2117523 + * @returns {String} + */ +function uuidv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +} function timestampToDateTimeString(timestamp) { var date = new Date(timestamp * 1000); diff --git a/www/pages/home.html b/www/pages/home.html index 34b1b67..2149a34 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -53,6 +53,14 @@ +
  • + +
    +
    +
    Route Notes
    +
    +
    +
  • diff --git a/www/pages/login.html b/www/pages/login.html index f6ea537..ea5bec7 100644 --- a/www/pages/login.html +++ b/www/pages/login.html @@ -16,7 +16,7 @@ -
    +
    diff --git a/www/pages/myroute.html b/www/pages/myroute.html new file mode 100644 index 0000000..0d34af0 --- /dev/null +++ b/www/pages/myroute.html @@ -0,0 +1,66 @@ + + +
    + + + +
    +
    Notes
    + {{#if notes}} +
    + +
    + {{else}} +
    + +
    Press add to add a note.
    +
    + {{/if}} + + +
    +
    \ No newline at end of file diff --git a/www/pages/myroute/editnote.html b/www/pages/myroute/editnote.html new file mode 100644 index 0000000..ede7e89 --- /dev/null +++ b/www/pages/myroute/editnote.html @@ -0,0 +1,79 @@ + + +
    + + + + + +
    + +
    +
      +
    • Address
    • +
    • +
      +
      Number
      +
      + + +
      +
      +
    • +
    • +
      +
      Street
      +
      + + +
      +
      +
    • + +
    • Options
    • + {{#each toggles}} +
    • +
      +
      + {{name}} +
      +
      + +
      +
      +
    • + {{/each}} + +
    • Notes
    • +
    • +
      +
      + + +
      +
      +
    • +
    +
    +
    +
    \ No newline at end of file diff --git a/www/routes.js b/www/routes.js index 663211b..669bd63 100644 --- a/www/routes.js +++ b/www/routes.js @@ -52,7 +52,6 @@ var routes = [ dropdownPlaceholderText: '', source: function (query, render) { var streets = searchAutofill(query, $("input[name=number]").val()); - render(streets); } }); @@ -71,7 +70,6 @@ var routes = [ on: { pageAfterIn: function () { loadPackageList(); - searchbar = app.searchbar.create({ el: '.package-list-searchbar', searchContainer: '#addresslist', @@ -101,6 +99,65 @@ var routes = [ } } }, + { + path: '/myroute', + name: 'myroute', + async: function (routeTo, routeFrom, resolve, reject) { + var notes = false; + if (inStorage("notes")) { + notes = JSON.parse(getStorage("notes")); + if (notes.length == 0) { + notes = false; + } + } + resolve({ + templateUrl: './pages/myroute.html' + }, { + context: { + notes: notes + } + }); + }, + on: { + pageAfterIn: function () { + // TODO: searchbar + } + }, + routes: [ + { + path: '/addnote', + async: function (routeTo, routeFrom, resolve, reject) { + var uuid = uuidv4(); + resolve({ + templateUrl: './pages/myroute/editnote.html' + }, { + context: { + noteid: uuid, + title: "Add Note", + toggles: SETTINGS.routenotetoggles, + note: { + id: uuid, + number: "", + street: "", + notes: "", + toggles: {} + } + } + }); + }, + }, + { + path: '/editnote', + templateUrl: './pages/myroute/editnote.html', + options: { + context: { + title: "Edit Note", + toggles: SETTINGS.routenotetoggles + } + } + } + ] + }, { path: '/login', templateUrl: './pages/login.html', @@ -131,7 +188,6 @@ var routes = [ async: function (routeTo, routeFrom, resolve, reject) { if (localStorage.getItem("scanevents") != null && localStorage.getItem("scanevents") != "[]") { var entries = JSON.parse(localStorage.getItem("scanevents")); - for (i in entries) { entries[i].event = entries[i].event.join(' '); } @@ -260,7 +316,7 @@ var routes = [ link: true, onclick: "logout()" }, - ); + ); } else { settings.push( { @@ -288,7 +344,6 @@ var routes = [ link: true } ); - if (platform_type == "cordova" && cordova.platformId != "browser") { settings.push({ setting: "wakelock", @@ -337,7 +392,6 @@ var routes = [ onclick: "openBrowser('https://netsyms.com/legal?pk_campaign=PackageHelperApp')", link: true }); - resolve({ templateUrl: './pages/settings.html' }, { @@ -399,7 +453,6 @@ var routes = [ slider: true } ]; - resolve({ templateUrl: './pages/settings.html' }, { @@ -481,7 +534,6 @@ var routes = [ onclick: "" } ]; - resolve({ templateUrl: './pages/settings.html' }, { diff --git a/www/settings.js b/www/settings.js index a3f91b2..8285cc4 100644 --- a/www/settings.js +++ b/www/settings.js @@ -301,6 +301,20 @@ var SETTINGS = { ] } ], + routenotetoggles: [ + { + name: "Vacant", + id: "vacant" + }, + { + name: "Outside delivery radius", + id: "undeliverable" + }, + { + name: "On hold", + id: "hold" + } + ], synckeyblacklist: [ "username", "password", "trackingcodehistory", "packages", "user_latitude", "user_longitude", "geocode_cache", "scanevents",