You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PackageHelper/www/routes.js

448 lines
16 KiB
JavaScript

/*
* 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/.
*/
var show_help = function () {
return localStorage.getItem("show_help") != "false";
}
var routes = [
{
path: '/home',
name: 'home',
async: function (routeTo, routeFrom, resolve, reject) {
var total = countPackages();
var undelivered = countRemainingPackages();
var delivered = total - undelivered;
var percent = (total > 0 ? (delivered / total) : 1);
resolve({
templateUrl: './pages/home.html'
}, {
context: {
packageTotal: total,
packageLeft: undelivered,
packageDelivered: delivered,
packagePercent: percent
}
});
}
},
{
path: '/manage',
name: 'manage',
templateUrl: './pages/manage.html',
options: {
context: {
show_help: show_help,
itemtypes: SETTINGS.itemtypes
}
},
on: {
pageAfterIn: function () {
app.autocomplete.create({
inputEl: '#streetInput',
openIn: 'dropdown',
/* If we set valueProperty to "id" then input value on select will be set according to this property */
valueProperty: 'name', //object's "value" property name
textProperty: 'name', //object's "text" property name
limit: 10, //limit to 10 results
typeahead: true,
dropdownPlaceholderText: '',
source: function (query, render) {
var streets = searchAutofill(query, $("input[name=number]").val());
render(streets);
}
});
}
}
},
{
path: '/list',
name: 'list',
templateUrl: './pages/list.html',
options: {
context: {
show_help: show_help
}
},
on: {
pageAfterIn: function () {
loadPackageList();
searchbar = app.searchbar.create({
el: '.package-list-searchbar',
searchContainer: '#addresslist',
searchIn: '.item-title',
backdrop: false,
on: {
search(sb, query, previousQuery) {
console.log(query, previousQuery);
}
}
});
}
}
},
{
path: '/map',
templateUrl: './pages/map.html',
name: 'map',
options: {
context: {
show_help: show_help
}
},
on: {
pageAfterIn: function () {
reloadMap();
}
}
},
{
path: '/toolbox',
url: './pages/toolbox.html',
name: 'toolbox',
routes: [
{
path: '/scanner',
templateUrl: './pages/toolbox/scanner.html',
routes: [
{
path: '/scanner',
templateUrl: './pages/toolbox/scanner/scanner.html',
name: 'scanner'
},
{
path: '/entries',
name: 'entries',
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(' <i class="fas fa-chevron-right"></i> ');
}
} else {
var entries = false;
}
resolve({
templateUrl: './pages/toolbox/scanner/entries.html'
}, {
context: {
entries: entries
}
});
},
on: {
pageAfterIn: function () {
$(".barcode_entry").each(function () {
var code = $(this).data("barcode");
JsBarcode("#barcode_" + code, code, {
format: "code128",
ean128: true,
width: 2,
height: 40
});
});
}
}
}
]
},
{
path: '/track',
name: 'track',
async: function (routeTo, routeFrom, resolve, reject) {
var history = localStorage.getItem("trackingcodehistory");
if (history == null) {
history = false;
} else {
history = JSON.parse(history).reverse(); // Most recent on top
}
resolve({
templateUrl: './pages/toolbox/track.html'
}, {
context: {
trackingcodehistory: history
}
});
},
routes: [
{
path: '/info',
templateUrl: './pages/toolbox/trackinginfo.html',
name: 'trackinginfo'
}
]
},
{
path: '/weather',
url: './pages/toolbox/weather.html',
name: 'weather',
on: {
pageAfterIn: function () {
loadWeather();
}
}
},
{
path: '/sharelist',
url: './pages/toolbox/sharelist.html',
name: 'sharelist'
}
]
},
{
path: '/help',
routes: [
{
path: '/list',
panel: {
url: './pages/help/list.html'
}
},
{
path: '/map',
panel: {
url: './pages/help/map.html'
}
}
]
},
{
path: '/credits',
url: './pages/credits.html',
name: 'credits'
},
{
path: '/settings',
name: 'settings',
async: function (routeTo, routeFrom, resolve, reject) {
var settings = [
{
setting: "alerts",
title: "Package Alerts",
text: "Change the alert sound, volume, and distance.",
onclick: "router.navigate('/settings/alerts')",
link: true
},
{
setting: "maps",
title: "Map and Navigation",
text: "Change map settings and units.",
onclick: "router.navigate('/settings/maps')",
link: true
}
];
if (platform_type == "cordova" && cordova.platformId != "browser") {
settings.push({
setting: "wakelock",
title: "Keep screen on",
text: "Improves GPS accuracy and alert sound reliability, but uses more battery.",
toggle: true,
checked: localStorage.getItem("wakelock") == "true",
onclick: ""
});
}
settings.push(
{
setting: "darktheme",
title: "Use dark theme",
text: "Saves power on phones with OLED screens.",
toggle: true,
checked: localStorage.getItem("darktheme") == "true",
onclick: ""
},
{
setting: "showhelp",
title: "Show help",
text: "Show the <span class=material-icons-intext><i class=material-icons>help</i></span> icons",
toggle: true,
checked: localStorage.getItem("show_help") != "false",
onclick: ""
},
{
setting: "versions",
title: "PackageHelper app v" + app_version,
text: "Copyright &copy; 2019-2020 Netsyms Technologies. Licensed under the Mozilla Public License 2.0.",
onclick: ""
},
{
setting: "opensource",
title: "Credits and open source info",
text: "",
onclick: "router.navigate('/credits')",
link: true
},
{
setting: "privacy",
title: "Privacy policy and legal",
text: "",
onclick: "openBrowser('https://netsyms.com/legal?pk_campaign=PackageHelperApp')",
link: true
});
resolve({
templateUrl: './pages/settings.html'
}, {
context: {
page_title: "Settings",
settings: settings
}
});
},
routes: [
{
path: '/alerts',
name: 'settings',
async: function (routeTo, routeFrom, resolve, reject) {
var alertsounds = [];
for (var id in SETTINGS.alertsounds) {
if (SETTINGS.alertsounds.hasOwnProperty(id)) {
alertsounds.push({
value: id,
label: SETTINGS.alertsounds[id].name,
selected: localStorage.getItem("alertsound") == id
});
}
}
var settings = [
{
setting: "alertsound",
title: "Alert sound",
text: "Select which sound to play when a package is nearby.",
select: true,
options: alertsounds
},
{
setting: "alertvolume",
title: "Alert volume",
min: 0,
max: 100,
step: 1,
value: localStorage.getItem("alertvolume"),
slider: true
},
{
setting: "alertradius",
title: "Alert radius (meters)",
min: 50,
max: 500,
step: 50,
value: localStorage.getItem("alertradius"),
slider: true
},
{
setting: "alertinterval",
title: "Alert interval (seconds)",
min: 15,
max: 120,
step: 15,
value: localStorage.getItem("alertinterval") == null ? 30 : localStorage.getItem("alertinterval"),
slider: true
}
];
resolve({
templateUrl: './pages/settings.html'
}, {
context: {
page_title: "Alert Settings",
settings: settings
}
});
}
},
{
path: '/maps',
name: 'settings',
async: function (routeTo, routeFrom, resolve, reject) {
var mapstyles = [];
for (var id in SETTINGS.maptileurls) {
if (SETTINGS.maptileurls.hasOwnProperty(id)) {
mapstyles.push({
value: id,
label: SETTINGS.maptileurls[id].name,
selected: localStorage.getItem("mapsource") == id
});
}
}
var settings = [
{
setting: "mapsource",
title: "Map style",
select: true,
options: mapstyles,
text: "Choose which map style to use."
},
{
setting: "units",
title: "Measurement units",
select: true,
options: [
{
value: "metric",
label: "Meters/Kilometers",
selected: localStorage.getItem("units") == "metric"
},
{
value: "imperial",
label: "Feet/Miles",
selected: localStorage.getItem("units") == "imperial"
}
]
},
{
setting: "trackzoom",
title: "Zoom when tracking location",
select: true,
options: [
{
value: 15,
label: "Low",
selected: localStorage.getItem("trackzoom") == 15
},
{
value: 16,
label: "Normal",
selected: localStorage.getItem("trackzoom") == null || localStorage.getItem("trackzoom") == 16
},
{
value: 17,
label: "High",
selected: localStorage.getItem("trackzoom") == 17
}
]
},
{
setting: "maptype",
title: "Alternative map",
text: "Turn this on if you have problems with the map.",
toggle: true,
checked: localStorage.getItem("maptype") == "leaflet",
onclick: ""
}
];
resolve({
templateUrl: './pages/settings.html'
}, {
context: {
page_title: "Map Settings",
settings: settings
}
});
}
}
]
}
];