Merge pull request #659 from hargata/Hargata/gps.integration

further bug fixes and hardening.
This commit is contained in:
Hargata Softworks
2024-10-21 10:53:40 -06:00
committed by GitHub
2 changed files with 43 additions and 13 deletions

View File

@@ -129,10 +129,10 @@
</div>
<script>
//Trip Recording Variables
let tripTimer; //interval to check GPS Location every 5 seconds.
let tripWakeLock; //wakelock handler to prevent screen from going to sleep.
let tripLastPosition; //last coordinates to compare/calculate distance from.
let tripCoordinates = ["Latitude,Longitude"]; //list of coordinates to generate a CSV for.
var tripTimer = undefined; //interval to check GPS Location every 5 seconds.
var tripWakeLock = undefined; //wakelock handler to prevent screen from going to sleep.
var tripLastPosition = undefined; //last coordinates to compare/calculate distance from.
var tripCoordinates = ["Latitude,Longitude"]; //list of coordinates to generate a CSV for.
var uploadedFiles = [];
getUploadedFilesFromModel();
function getUploadedFilesFromModel() {

View File

@@ -226,9 +226,25 @@ function showTripModal() {
$(".trip-odometer").text($("#initialOdometerRecordMileage").val());
}
function hideTripModal() {
stopRecording();
$(".odometer-modal").removeClass('d-none');
$(".trip-modal").addClass('d-none');
//check if recording is in progress
if (tripTimer != undefined || tripWakeLock != undefined) {
Swal.fire({
title: "Confirm Exit?",
text: "Recording in Progress, Exit?",
showCancelButton: true,
confirmButtonText: "Exit",
confirmButtonColor: "#dc3545"
}).then((result) => {
if (result.isConfirmed) {
stopRecording();
$(".odometer-modal").removeClass('d-none');
$(".trip-modal").addClass('d-none');
}
});
} else {
$(".odometer-modal").removeClass('d-none');
$(".trip-modal").addClass('d-none');
}
}
function startRecording() {
if (navigator.geolocation && navigator.wakeLock) {
@@ -240,6 +256,11 @@ function startRecording() {
}, 5000);
$(".trip-start").addClass('d-none');
$(".trip-stop").removeClass('d-none');
//modify modal to prevent closing
$("#odometerRecordModal").on("hide.bs.modal", function (event) {
event.preventDefault();
hideTripModal();
});
});
} catch (err) {
errorSwal('Location Services not Enabled');
@@ -280,13 +301,19 @@ function recordPosition(position) {
function stopRecording() {
if (tripTimer != undefined) {
clearInterval(tripTimer);
tripTimer = undefined;
}
if (tripWakeLock != undefined) {
tripWakeLock.release();
tripWakeLock = undefined;
}
if (tripLastPosition != undefined) {
tripLastPosition = undefined;
}
$(".trip-start").removeClass('d-none');
$(".trip-stop").addClass('d-none');
if (getRecordedOdometer() != $("#initialOdometerRecordMileage").val()) {
$("#odometerRecordModal").off("hide.bs.modal");
if (parseInt(getRecordedOdometer()) != $("#initialOdometerRecordMileage").val()) {
$(".trip-save").removeClass('d-none');
}
}
@@ -320,12 +347,15 @@ function saveRecordedOdometer() {
//update current odometer value
$("#odometerRecordMileage").val(parseInt(getRecordedOdometer()).toString());
//save coordinates into a CSV file and upload
$.post('/Files/UploadCoordinates', { coordinates: tripCoordinates }, function (response) {
uploadedFiles.push(response);
$.post('/Vehicle/GetFilesPendingUpload', { uploadedFiles: uploadedFiles }, function (viewData) {
$("#filesPendingUpload").html(viewData);
if (tripCoordinates.length > 0) {
$.post('/Files/UploadCoordinates', { coordinates: tripCoordinates }, function (response) {
uploadedFiles.push(response);
$.post('/Vehicle/GetFilesPendingUpload', { uploadedFiles: uploadedFiles }, function (viewData) {
$("#filesPendingUpload").html(viewData);
tripCoordinates = [];
});
});
});
}
hideTripModal();
}
function toggleSubOdometer() {