Fixes for GPX tracks display

This commit is contained in:
Vadim Likholetov 2023-11-15 22:06:32 +02:00
parent c586d907d6
commit 214aef1723
2 changed files with 23 additions and 6 deletions

View File

@ -92,12 +92,21 @@ def edit_sar(id):
@app.route('/sar_details/<int:id>')
def sar_details(id):
sar = SARCall.query.get_or_404(id) # Fetch the SARCall record or return 404
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
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
comments_with_gpx = []
# Assuming each comment has a relationship to GPXFile
print (gpx_files)
for comment in sar.comments:
gpx_tracks = GPSTrack.query.filter_by(comment_id=comment.id).all()
for track in gpx_tracks:
comments_with_gpx.append({
"id": track.id,
"comment_id": comment.id,
"name": track.file_name,
"comment": track.gpx_name
})
return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files)
return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files, comments_with_gpx=comments_with_gpx)
@app.route('/delete_sar/<int:id>')
@ -169,9 +178,8 @@ def upload_gpx():
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')
return Response(gpx_file.gpx_data, mimetype='application/gpx+xml')

View File

@ -60,6 +60,15 @@
</div>
<div class="comment-text"><p id="comment-text-{{ comment.id }}">{{ comment.text }}</p></div>
{% for gpx_track in comments_with_gpx %}
{% if gpx_track.comment_id == comment.id %}
<li>
<a href="{{ url_for('get_gpx', gpx_id=gpx_track.id) }}">{{ gpx_track.name }}</a>: {{gpx_track.comment}}
</li>
{% endif %}
{% endfor %}
{% 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 }}"
data-comment-text="{{ comment.text }}">Edit