diff --git a/www/assets/images/largebox.png b/www/assets/images/largebox.png new file mode 100644 index 0000000..9c7aba4 Binary files /dev/null and b/www/assets/images/largebox.png differ diff --git a/www/assets/images/largebox.svg b/www/assets/images/largebox.svg new file mode 100644 index 0000000..21ac168 --- /dev/null +++ b/www/assets/images/largebox.svg @@ -0,0 +1,63 @@ + + diff --git a/www/assets/images/largeboxes.png b/www/assets/images/largeboxes.png new file mode 100644 index 0000000..58b3fb6 Binary files /dev/null and b/www/assets/images/largeboxes.png differ diff --git a/www/assets/images/largeboxes.svg b/www/assets/images/largeboxes.svg new file mode 100644 index 0000000..7aa1767 --- /dev/null +++ b/www/assets/images/largeboxes.svg @@ -0,0 +1,63 @@ + + diff --git a/www/assets/images/signature.png b/www/assets/images/signature.png new file mode 100644 index 0000000..7c03943 Binary files /dev/null and b/www/assets/images/signature.png differ diff --git a/www/assets/images/signature.svg b/www/assets/images/signature.svg new file mode 100644 index 0000000..d2abc65 --- /dev/null +++ b/www/assets/images/signature.svg @@ -0,0 +1,63 @@ + + diff --git a/www/assets/images/signatures.png b/www/assets/images/signatures.png new file mode 100644 index 0000000..45aac69 Binary files /dev/null and b/www/assets/images/signatures.png differ diff --git a/www/assets/images/signatures.svg b/www/assets/images/signatures.svg new file mode 100644 index 0000000..357fd0e --- /dev/null +++ b/www/assets/images/signatures.svg @@ -0,0 +1,74 @@ + + diff --git a/www/assets/js/map_leaflet.js b/www/assets/js/map_leaflet.js index 7447cc4..1899a6a 100644 --- a/www/assets/js/map_leaflet.js +++ b/www/assets/js/map_leaflet.js @@ -17,7 +17,7 @@ function leafletMap() { if (localStorage.getItem("mapsource") == null) { localStorage.setItem("mapsource", "liberty"); } - + $("#mapbox").css("background-color", SETTINGS.maptileurls[localStorage.getItem("mapsource")].bgcolor); L.tileLayer(SETTINGS.maptileurls[localStorage.getItem("mapsource")].url, { @@ -65,6 +65,7 @@ function leafletMap() { // of the loop, or something like that (function (datai) { var iconName = getMapIconForItems(datai.items); + console.log(iconName); var icon = L.icon({ iconUrl: "assets/images/" + iconName + ".png", diff --git a/www/assets/js/packages.js b/www/assets/js/packages.js index 16a9360..90a71c5 100644 --- a/www/assets/js/packages.js +++ b/www/assets/js/packages.js @@ -35,25 +35,12 @@ function getPackage(packageid) { } } -function getIconForType(packagetype) { - switch (packagetype) { - case "package": - return "fas fa-box"; - case "letter": - return "fas fa-envelope"; - case "express": - return "fas fa-shipping-fast"; - default: - return "fas fa-box"; - } +function getIconForType(type) { + return SETTINGS.itemtypes[type].icon; } function getMapIconForItems(items) { - var types = { - package: 0, - letter: 0, - express: 0 - }; + var types = {}; var deliveredcount = 0; var type = "package"; for (var i = 0; i < items.length; i++) { @@ -63,27 +50,36 @@ function getMapIconForItems(items) { deliveredcount++; continue; } + if (isNaN(types[items[i].type])) { + types[items[i].type] = 0; + } types[items[i].type]++; } + if (deliveredcount == items.length) { return "check"; } - if (types.letter == 0 && types.express == 0) { - if (types.package > 1) { - return "boxes"; + + item_types = 0; + icon = "multiple-items"; + // Count how many types we have, and set/overwrite the icon assuming we + // only have that type. If we end up with multiple types, we return that + // icon instead of a specific one. + console.log(types); + for (var type in types) { + console.log(type); + item_types++; + if (types[type] == 1) { + icon = SETTINGS.itemtypes[type].mapicon; + } else { + icon = SETTINGS.itemtypes[type].pluralmapicon; } - return "box"; + console.log(icon); } - if (types.package == 0 && types.express == 0) { - if (types.letter > 1) { - return "envelopes"; - } - return "envelope"; + if (item_types > 1) { + return "multiple-items"; } - if (types.package == 0 && types.letter == 0) { - return "express"; - } - return "multiple-items"; + return icon; } function addPackage(address, latitude, longitude, type, callback) { @@ -281,7 +277,7 @@ function addPackageByAddress(address, citystate, type, callback) { app.dialog.alert("There was a network issue while finding the address. Please try adding the item again.", "Error"); } }); - + // Open a loading message if there's a delay finding the address setTimeout(function () { if (!requestfinished) { diff --git a/www/assets/js/toolbox_track.js b/www/assets/js/toolbox_track.js new file mode 100644 index 0000000..2b3c2a6 --- /dev/null +++ b/www/assets/js/toolbox_track.js @@ -0,0 +1,125 @@ +/* + * 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 locationArrayToString(location) { + var locarray = []; + if (location.street != "" && location.street != null) { + locarray.push(location.street); + } + if (location.city != "" && location.city != null) { + locarray.push(location.city); + } + if (location.state != "" && location.state != null) { + locarray.push(location.state); + } + if (location.zip != "" && location.zip != null) { + locarray.push(location.zip); + } + if (location.country != "" && location.country != "US" && location.country != null) { + locarray.push(location.country); + } + return locarray.join(", "); +} + +function timestampToDateTimeString(timestamp) { + var date = new Date(timestamp * 1000); + + var pm = date.getHours() >= 12; + var hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours(); + var minutes = date.getMinutes(); + var time = hours + ":" + minutes + " " + (pm ? "PM" : "AM"); + + return date.toLocaleDateString() + " " + time; +} + +function trackingStatusToNiceString(status, icon) { + if (typeof icon == 'undefined' || icon !== true) { + var icon = false; + } + switch (status) { + case "UNKNOWN": + return (icon ? ' ' : '') + "Unknown"; + case "PRE_TRANSIT": + return (icon ? ' ' : '') + "Pre-transit"; + case "TRANSIT": + return (icon ? ' ' : '') + "In Transit"; + case "DELIVERED": + return (icon ? ' ' : '') + "Delivered"; + case "RETURNED": + return (icon ? ' ' : '') + "Returned"; + case "FAILURE": + return (icon ? ' ' : '') + "Failure"; + default: + return status; + } +} + +function openTrackingHistory(trackingcode) { + var requestfinished = false; + var trackingdialogopen = false; + $.ajax({ + url: SETTINGS.trackingapi, + dataType: 'json', + data: { + code: trackingcode + }, + timeout: 15 * 1000, + success: function (resp) { + if (trackingdialogopen) { + app.dialog.close(); + trackingdialogopen = false; + } + requestfinished = true; + if (resp.status == "OK") { + var infocontext = resp; + + infocontext.current.location.display = locationArrayToString(infocontext.current.location); + infocontext.current.date = timestampToDateTimeString(infocontext.current.date); + infocontext.current.status = trackingStatusToNiceString(infocontext.current.status, true); + + for (var i = 0; i < infocontext.history.length; i++) { + infocontext.history[i].location.display = locationArrayToString(infocontext.history[i].location); + infocontext.history[i].date = timestampToDateTimeString(infocontext.history[i].date); + infocontext.history[i].status = trackingStatusToNiceString(infocontext.history[i].status, true); + } + // TODO: format timestamps as local time + router.navigate("/toolbox/track/info", { + context: infocontext + }); + } else { + playSound("error"); + app.dialog.alert(resp.message, "Error"); + } + }, + error: function (jqXHR, status, errorThrown) { + if (trackingdialogopen) { + app.dialog.close(); + searchingdialogopen = false; + } + requestfinished = true; + playSound("error"); + app.dialog.alert("There was a network issue while tracking the item. Please try again.", "Error"); + } + }); + + // Open a loading message if there's a delay + setTimeout(function () { + if (!requestfinished) { + app.dialog.preloader("Tracking..."); + trackingdialogopen = true; + } + }, 750); +} + +$("#trackbtn").click(function () { + var code = $("input[name=trackingcode]").val(); + + if (code != "" && code.length > 5) { + openTrackingHistory(code); + } else { + app.dialog.alert("That's not a valid tracking code.", "Error"); + } +}); \ No newline at end of file diff --git a/www/pages/home.html b/www/pages/home.html index 28972bf..34b1b67 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -27,7 +27,7 @@ > -
+
+
  • + +
    +
    +
    Toolbox
    +
    +
    +
  • diff --git a/www/pages/manage.html b/www/pages/manage.html index 5103925..75a9a9a 100644 --- a/www/pages/manage.html +++ b/www/pages/manage.html @@ -64,33 +64,17 @@
  • Item Type
  • + {{#each itemtypes}}
  • -
  • -
  • - -
  • -
  • -
  • + {{/each}} diff --git a/www/pages/toolbox.html b/www/pages/toolbox.html new file mode 100644 index 0000000..b140372 --- /dev/null +++ b/www/pages/toolbox.html @@ -0,0 +1,41 @@ + + +
    + + + +
    + +
    +
    \ No newline at end of file diff --git a/www/pages/toolbox/track.html b/www/pages/toolbox/track.html new file mode 100644 index 0000000..4b5525f --- /dev/null +++ b/www/pages/toolbox/track.html @@ -0,0 +1,48 @@ + + +
    + + + +
    +
    +
      +
    • +
      +
      Tracking Code
      +
      + + +
      +
      +
    • + +
    • + Track +
    • +
    +
    + +
    + Compatible with USPS, UPS, FedEx, and DHL tracking codes. +
    +
    + + +
    \ No newline at end of file diff --git a/www/pages/toolbox/trackinginfo.html b/www/pages/toolbox/trackinginfo.html new file mode 100644 index 0000000..116bb05 --- /dev/null +++ b/www/pages/toolbox/trackinginfo.html @@ -0,0 +1,70 @@ + + +
    + + + +
    +
    +
      +
    • Current Status
    • + +
    • +
      +
      + {{#with current}} +
      +
      {{status}}
      +
      {{date}}
      +
      +
      {{details}}
      +
      {{location.display}}
      + {{/with}} +
      {{carrier.name}} | {{service.name}}
      +
      +
      +
    • +
    • Item Info
    • +
    • +
      +
      +
      Tracking Code: {{code}}
      +
      Carrier: {{carrier.name}} | {{service.name}}
      +
      +
      +
    • +
    • History
    • + {{#each history}} +
    • +
      +
      +
      +
      {{status}}
      +
      {{date}}
      +
      +
      {{details}}
      +
      {{location.display}}
      +
      +
      +
    • + {{else}} +
    • + No item history found. +
    • + {{/each}} +
    +
    +
    +
    \ No newline at end of file diff --git a/www/routes.js b/www/routes.js index dfb30e2..4f516c3 100644 --- a/www/routes.js +++ b/www/routes.js @@ -27,7 +27,12 @@ var routes = [ }, { path: '/manage', - url: './pages/manage.html', + templateUrl: './pages/manage.html', + options: { + context: { + itemtypes: SETTINGS.itemtypes + } + }, name: 'manage', on: { pageAfterIn: function () { @@ -83,6 +88,21 @@ var routes = [ } } }, + { + path: '/toolbox', + url: './pages/toolbox.html', + name: 'toolbox' + }, + { + path: '/toolbox/track', + url: './pages/toolbox/track.html', + name: 'track' + }, + { + path: '/toolbox/track/info', + templateUrl: './pages/toolbox/trackinginfo.html', + name: 'trackinginfo' + }, { path: '/credits', url: './pages/credits.html', diff --git a/www/settings.js b/www/settings.js index 52dec58..ef0f6a5 100644 --- a/www/settings.js +++ b/www/settings.js @@ -40,5 +40,44 @@ var SETTINGS = { file: "alert.sonar.mp3" } }, - geocodeapi: "https://apis.netsyms.net/packagehelper/geocode.php" + itemtypes: { + package: { + id: "package", + name: "Package", + icon: "fas fa-box fa-fw", + mapicon: "box", + pluralmapicon: "boxes", + selected: true + }, + letter: { + id: "letter", + name: "Letter", + icon: "fas fa-envelope fa-fw", + mapicon: "envelope", + pluralmapicon: "envelopes" + }, + signature: { + id: "signature", + name: "Signature", + icon: "fas fa-file-signature fa-fw", + mapicon: "signature", + pluralmapicon: "signatures" + }, + large: { + id: "large", + name: "Large Package", + icon: "fas fa-pallet fa-fw", + mapicon: "largebox", + pluralmapicon: "largeboxes" + }, + express: { + id: "express", + name: "Express", + icon: "fas fa-shipping-fast fa-fw", + mapicon: "express", + pluralmapicon: "multiple-items" + } + }, + geocodeapi: "https://apis.netsyms.net/packagehelper/geocode.php", + trackingapi: "https://apis.netsyms.net/packagehelper/track.php" }