Skip to content

Commit

Permalink
upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Mar 6, 2024
1 parent f3e96b1 commit 15182de
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 148 deletions.
20 changes: 10 additions & 10 deletions application/assets/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,17 @@ const helper = (() => {
document.querySelector("div#top-bar").style.display = "block";
}
}
function wakeLock(param, lock_type) {
if ("requestWakeLock" in navigator) {
let lock;

function screenWakeLock(param, lock_type) {
let lock;
if (window.navigator.requestWakeLock == "is not a function") return false;
if (param == "lock") {
lock = window.navigator.requestWakeLock(lock_type);
return false;
}
if (param === "lock") {
lock = window.navigator.requestWakeLock(lock_type);

if (param == "unlock") {
if (lock.topic == lock_type) {
if ("b2g" in Navigator) {
lock = navigator.b2g.requestWakeLock(lock_type);
}
} else if (param === "unlock" && lock && lock.topic === lock_type) {
lock.unlock();
}
}
Expand All @@ -404,7 +404,7 @@ const helper = (() => {
return {
bottom_bar,
top_bar,
screenWakeLock,
wakeLock,
calculateDatabaseSizeInMB,
getManifest,
toaster,
Expand Down
65 changes: 42 additions & 23 deletions application/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const module = (() => {
/////////////////////////
/////Load GPX///////////
///////////////////////
function loadGPX(filename, url) {
function loadGPX(filename, url, move_to = true) {
if (url) {
new L.GPX(url, {
async: true,
Expand All @@ -152,8 +152,10 @@ const module = (() => {
})
.addTo(gpx_group);

document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
if (move_to) {
document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
}
}

if (filename) {
Expand Down Expand Up @@ -205,8 +207,10 @@ const module = (() => {
})
.addTo(gpx_group);

document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
if (move_to) {
document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
}
};

reader.readAsText(r);
Expand Down Expand Up @@ -265,7 +269,7 @@ const module = (() => {
/////////////////////////
/////Load GeoJSON///////////
///////////////////////
let loadGeoJSON = function (filename, callback) {
let loadGeoJSON = function (filename, callback, move_to = true) {
//file reader
try {
let sdcard = navigator.getDeviceStorage("sdcard");
Expand Down Expand Up @@ -364,9 +368,10 @@ const module = (() => {

// Popup
}).addTo(geoJSON_group);

document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
if (move_to) {
document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
}
};

reader.readAsText(r);
Expand Down Expand Up @@ -546,21 +551,34 @@ const module = (() => {
map.fitBounds(gpx_selection[gpx_selection_count].getBounds());
let m = gpx_selection[gpx_selection_count].getLayers();

var parser = new DOMParser();
var xmlDoc = parser.parseFromString(
gpx_selection[gpx_selection_count]._gpx,
"text/xml"
);

var eleElements = xmlDoc.getElementsByTagName("ele");

let altitudes = [];
for (var i = 0; i < eleElements.length; i++) {
var currentElement = eleElements[i];
altitudes.push(currentElement.textContent);
}

const { gain, loss } = calculateGainAndLoss(altitudes);

console.log(gain, loss);

const keys = Object.keys(m[0]._layers);
const firstKey = keys[0];
general.gpx_selection_latlng = m[0]._layers[firstKey]._latlngs;

//store info in object
gpx_selection_info.duration =
gpx_selection[gpx_selection_count]._info.duration.total;
gpx_selection_info.elevation_gain =
gpx_selection[gpx_selection_count]._info.elevation.gain;

gpx_selection_info.elevation_loss =
gpx_selection[gpx_selection_count]._info.elevation.loss;
gpx_selection_info.elevation_gain = gain;

gpx_selection_info.elevation_loss =
gpx_selection[gpx_selection_count]._info.elevation.loss;
gpx_selection_info.elevation_loss = loss;

gpx_selection_info.distance =
gpx_selection[gpx_selection_count]._info.length;
Expand Down Expand Up @@ -799,7 +817,6 @@ const module = (() => {
let tracking_cache = [];
//let gps_lock;
let tracking_altitude = [];
let calc = 0;
let tracking = { duration: "" };
let polyline = L.polyline(latlngs, path_option).addTo(measure_group_path);
let polyline_tracking = L.polyline(tracking_latlngs, path_option).addTo(
Expand Down Expand Up @@ -900,10 +917,7 @@ const module = (() => {
if (action == "tracking") {
status.tracking_running = true;

if ("requestWakeLock" in navigator) {
if (setting.tracking_screenlock)
helper.screenWakeLock("lock", "screen");
}
if (setting.tracking_screenlock) helper.wakeLock("lock", "screen");

if (localStorage.getItem("tracking_cache") !== null) {
if (
Expand Down Expand Up @@ -1098,7 +1112,11 @@ const module = (() => {
//Upload gpx file every 5min, unfortunately the update function doesn't work, so I have to combine create/delete
if (status.live_track) {
if (status.live_track_file_created == false) {
osm.osm_server_upload_gpx("live_track.gpx", toGPX(), false);
const currentDate = new Date();
const isoString = currentDate.toISOString();
const a = isoString.substring(0, 10);

osm.osm_server_upload_gpx("live_track.gpx-" + a, toGPX(), false);
status.live_track_file_created = true;
} else {
let calc_dif =
Expand All @@ -1110,7 +1128,8 @@ const module = (() => {
osm.osm_delete_gpx(e, false);
});

osm.osm_server_upload_gpx("live_track.gpx", toGPX(), false);
osm.osm_server_upload_gpx("live_track.gpx-" + a, toGPX(), false);

status.tracking_backupup_at = new Date().getTime() / 1000;
}
}
Expand Down
22 changes: 13 additions & 9 deletions application/assets/js/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const osm = (() => {
type: "application/gpx",
});

if (notify) helper.side_toaster("try uploading file", 5000);
//if (notify) helper.side_toaster("try uploading file", 5000);

let formData = new FormData();
formData.append("description", "uploaded from o.map");
Expand All @@ -31,8 +31,8 @@ const osm = (() => {
})
.then((response) => response.text())
.then((data) => {
if (notify) helper.side_toaster("file uploaded", 4000);
status.live_track_id.push(data);
if (notify == true) helper.side_toaster("file uploaded", 4000);
})

.catch((error) => {
Expand Down Expand Up @@ -110,9 +110,10 @@ const osm = (() => {
xhr.setRequestHeader("Authorization", n);

xhr.onload = function () {
helper.side_toaster("file uploaded", 5000);

if (xhr.status === 200) {
const data = xhr.responseText;
helper.side_toaster("file updated", 2000);
} else {
const error = "Error: " + xhr.status;
helper.side_toaster(error, 4000);
Expand Down Expand Up @@ -272,12 +273,15 @@ const osm = (() => {
id: s[i].getAttribute("id"),
};

files.push({
name: "_" + m.name,
path: m.id,
id: m.id,
type: "osm_sever",
});
if (!files.some((file) => file.id === m.id)) {
// If not present, add it to the array
files.push({
name: m.name,
path: m.id,
id: m.id,
type: "osm_sever",
});
}

files.sort((a, b) => {
return b.name.localeCompare(a.name);
Expand Down
3 changes: 2 additions & 1 deletion application/assets/js/overpass.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ const overpass = (() => {
fetchDataWithXHR(
resultUrl,
function (data) {
console.log(data);
if (data.elements.length === 0) {
helper.side_toaster("no data", 4000);
document.querySelector(".loading-spinner").style.display = "none";
document.activeElement.classList.remove("");
return false;
}

if (data.elements.length > 80000) {
if (data.elements.length > 50000) {
helper.side_toaster(
"There is too much data to process, please use a different zoom level",
6000
Expand Down
2 changes: 1 addition & 1 deletion application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ <h2>Unit of measurement</h2>
<h2>Tracking</h2>
<div class="item input-parent flex" tabindex="6">
<label for="screenlock-ckb" class="grid-col-14"
>screen lock during tracking ?</label
>The screen should not be switched off during tracking ?</label
>
<input
class="checkboxes grid-col-2"
Expand Down
22 changes: 15 additions & 7 deletions application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let gpx_selection_info = {};
let gpx_string;
let tilesLayer = "";
let n;
let gps_lock;

let files = [];

Expand Down Expand Up @@ -126,7 +125,10 @@ if (!navigator.geolocation) {
}

if ("requestWakeLock" in navigator) {
gps_lock = window.navigator.requestWakeLock("gps");
window.navigator.requestWakeLock("gps");
if ("b2g" in Navigator) {
window.navigator.b2g.requestWakeLock("gps");
}
}

if ("b2g" in Navigator) {
Expand Down Expand Up @@ -426,8 +428,6 @@ document.addEventListener("DOMContentLoaded", function () {
general.last_map_type
);

console.log(general);

//get files and store

// Function to remove duplicates based on the 'name' property
Expand All @@ -452,7 +452,7 @@ document.addEventListener("DOMContentLoaded", function () {
});

// Remove duplicates based on the 'name' property
var uniqueData = removeDuplicates(data, "name");
var uniqueData = removeDuplicates(data, "path");

files = uniqueData;

Expand All @@ -475,7 +475,11 @@ document.addEventListener("DOMContentLoaded", function () {

// Load gpx file on start
if (e.name.substring(0, 1) == "_") {
module.loadGPX(e.path);
if (status.windowOpen == "map") {
module.loadGPX(e.path, false, true);
} else {
module.loadGPX(e.path, false, false);
}
}
}

Expand All @@ -497,7 +501,11 @@ document.addEventListener("DOMContentLoaded", function () {

// Load startup item
if (e.name.substring(0, 1) == "_") {
module.loadGeoJSON(e.path, false);
if (status.windowOpen == "map") {
module.loadGeoJSON(e.path, false, true);
} else {
module.loadGeoJSON(e.path, false, false);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.9.782",
"version": "1.9.791",
"version_name": "hotline",
"name": "o.map",
"description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.",
Expand Down
2 changes: 1 addition & 1 deletion application/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],

"b2g_features": {
"version": "2.0.87",
"version": "2.0.95",
"id": "o.map",
"core": true,
"categories": ["utilities"],
Expand Down
3 changes: 2 additions & 1 deletion application/oauth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function getToken() {
const code = location.search.split("?code=")[1];
let code = location.search.split("?code=")[1];

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();

urlencoded.append("code", code);
urlencoded.append("grant_type", "authorization_code");
urlencoded.append(
Expand Down
20 changes: 10 additions & 10 deletions docs/assets/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,17 @@ const helper = (() => {
document.querySelector("div#top-bar").style.display = "block";
}
}
function wakeLock(param, lock_type) {
if ("requestWakeLock" in navigator) {
let lock;

function screenWakeLock(param, lock_type) {
let lock;
if (window.navigator.requestWakeLock == "is not a function") return false;
if (param == "lock") {
lock = window.navigator.requestWakeLock(lock_type);
return false;
}
if (param === "lock") {
lock = window.navigator.requestWakeLock(lock_type);

if (param == "unlock") {
if (lock.topic == lock_type) {
if ("b2g" in Navigator) {
lock = navigator.b2g.requestWakeLock(lock_type);
}
} else if (param === "unlock" && lock && lock.topic === lock_type) {
lock.unlock();
}
}
Expand All @@ -404,7 +404,7 @@ const helper = (() => {
return {
bottom_bar,
top_bar,
screenWakeLock,
wakeLock,
calculateDatabaseSizeInMB,
getManifest,
toaster,
Expand Down
Loading

0 comments on commit 15182de

Please sign in to comment.