Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vadim Likholetov 2023-11-15 16:24:56 +02:00
parent 275a8026f9
commit 448e524ea0
2 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,5 @@
from dateutil import parser from dateutil import parser
from flask import request, redirect, flash, render_template, url_for, jsonify from flask import request, redirect, flash, render_template, url_for, jsonify, Response
from flask_login import login_required, current_user from flask_login import login_required, current_user
from app import app, db from app import app, db
@ -92,8 +92,12 @@ def edit_sar(id):
@app.route('/sar_details/<int:id>') @app.route('/sar_details/<int:id>')
def sar_details(id): def sar_details(id):
sar = SARCall.query.get_or_404(id) # Fetch the SARCall record or return 404 sar = SARCall.query.get_or_404(id) # Fetch the SARCall record or return 404
gpx_files = GPSTrack.query.filter_by(sar_call_id=id).all() gpx_files = [id[0] for id in GPSTrack.query.with_entities(GPSTrack.id).filter_by(sar_call_id=id).all()] # Fetch all GPX files for this SARCall
return render_template('sar_details.html', sar=sar, gpx_files=gpx_files)
# Assuming each comment has a relationship to GPXFile
print (gpx_files)
return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files)
@app.route('/delete_sar/<int:id>') @app.route('/delete_sar/<int:id>')
@ -163,3 +167,11 @@ def upload_gpx():
db.session.commit() db.session.commit()
return jsonify({'message': 'GPX file uploaded successfully'}) return jsonify({'message': 'GPX file uploaded successfully'})
@app.route('/get_gpx/<int:gpx_id>')
@login_required
def get_gpx(gpx_id):
gpx_file = GPSTrack.query.get_or_404(gpx_id)
return Response(gpx_file.gpx_data, mimetype='application/gpx+xml')

View File

@ -60,9 +60,6 @@
</div> </div>
<div class="comment-text"><p id="comment-text-{{ comment.id }}">{{ comment.text }}</p></div> <div class="comment-text"><p id="comment-text-{{ comment.id }}">{{ comment.text }}</p></div>
{% if comment.gpx_data %}
<!-- Display the GPX data on the map -->
{% endif %}
{% if current_user.id == comment.user_id or current_user.id == 1 or current_user.id == sar.user_id %} {% if current_user.id == comment.user_id or current_user.id == 1 or current_user.id == sar.user_id %}
<button class="edit-comment-btn" data-comment-id="{{ comment.id }}" <button class="edit-comment-btn" data-comment-id="{{ comment.id }}"
data-comment-text="{{ comment.text }}">Edit data-comment-text="{{ comment.text }}">Edit
@ -157,7 +154,20 @@
<script> <script>
var gpxData = {{ gpx_files | tojson }};
// Load GPX file and add to map
function loadAndDisplayGPX(gpxId) {
fetch('/get_gpx/' + gpxId)
.then(response => response.text())
.then(gpxData => {
new L.GPX(gpxData, {async: true}).on('loaded', function (e) {
map.fitBounds(e.target.getBounds());
}).addTo(map);
})
.catch(error => console.error('Error loading GPX file:', error));
}
var gpxData = {{ gpx_ids | tojson }};
var map = L.map('map').setView([{{ sar.latitude }}, {{ sar.longitude }}], 13); var map = L.map('map').setView([{{ sar.latitude }}, {{ sar.longitude }}], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@ -166,11 +176,10 @@
}).addTo(map); }).addTo(map);
L.marker([{{ sar.latitude }}, {{ sar.longitude }}]).addTo(map); L.marker([{{ sar.latitude }}, {{ sar.longitude }}]).addTo(map);
gpxData.forEach(function (gpxFile) { gpxData.forEach(function (id) {
new L.GPX(gpxFile.gpx_data, {async: true}).on('loaded', function (e) { loadAndDisplayGPX(id);
map.fitBounds(e.target.getBounds());
}).addTo(map);
}); });
</script> </script>