2023-11-12 20:06:15 +00:00
|
|
|
{% extends "base.html" %}
|
|
|
|
|
|
|
|
{% block title %}
|
|
|
|
SAR job details
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block content %}
|
|
|
|
|
2023-11-14 10:07:43 +00:00
|
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
|
2023-11-12 20:06:15 +00:00
|
|
|
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
2023-11-14 10:07:43 +00:00
|
|
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
2023-11-14 20:33:57 +00:00
|
|
|
|
|
|
|
<!-- Include leaflet-gpx plugin -->
|
2023-11-26 19:06:43 +00:00
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.7.0/gpx.min.js"></script>
|
2023-11-14 20:33:57 +00:00
|
|
|
|
2023-11-12 20:06:15 +00:00
|
|
|
<style>
|
2023-11-14 10:07:43 +00:00
|
|
|
#map {
|
|
|
|
height: 400px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button {
|
|
|
|
margin: 5px;
|
|
|
|
}
|
2023-11-14 20:33:57 +00:00
|
|
|
|
|
|
|
.comment-text {
|
|
|
|
white-space: pre-line;
|
|
|
|
}
|
2023-11-12 20:06:15 +00:00
|
|
|
</style>
|
|
|
|
|
2023-11-14 10:07:43 +00:00
|
|
|
<div class="container mt-4">
|
2023-11-19 21:08:19 +00:00
|
|
|
<h2 class="mb-4">#{{ sar.SARCall.id }} : {{ sar.SARCall.title }}</h2>
|
2023-11-14 10:07:43 +00:00
|
|
|
<div class="card mb-4">
|
|
|
|
<div class="card-body">
|
2023-11-17 06:50:24 +00:00
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<div class="card-mb5">
|
|
|
|
<div class="card-body">
|
|
|
|
<div>
|
2023-11-19 21:08:19 +00:00
|
|
|
<p>Created at: {{ sar.SARCall.created }}</p>
|
|
|
|
<p>Last updated: {{ sar.SARCall.updated }}</p>
|
2023-11-17 06:50:24 +00:00
|
|
|
</div>
|
2023-11-26 19:06:43 +00:00
|
|
|
<p><strong>Coordination
|
|
|
|
manager:</strong> {{ sar.SARCall.coordination_officer.full_name }}</p>
|
2023-11-19 21:08:19 +00:00
|
|
|
<p><strong>Search manager:</strong> {{ sar.SARCall.search_officer.full_name }}</p>
|
|
|
|
<p>Status: {{ sar.SARStatus.name }}</p>
|
|
|
|
{% if is_logged_in %}
|
2023-11-26 19:06:43 +00:00
|
|
|
<p>Category: {{ sar.SARCategory.name }}</p>
|
2023-11-19 21:08:19 +00:00
|
|
|
{% endif %}
|
|
|
|
<p><strong>Start Date:</strong> {{ sar.SARCall.start_date }}</p>
|
|
|
|
<p><strong>Finish Date:</strong> {{ sar.SARCall.finish_date }}</p>
|
|
|
|
<p>Result: {{ sar.SARResult.name }}</p>
|
2023-11-17 06:50:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<div class="card-mb5">
|
|
|
|
<div class="card-body">
|
2023-11-19 21:08:19 +00:00
|
|
|
<p>IPP longitude: {{ sar.SARCall.longitude }} </p>
|
|
|
|
<p>IPP latitude: {{ sar.SARCall.latitude }}</p>
|
|
|
|
<p>Longitude found: {{ sar.SARCall.longitude_found }}</p>
|
|
|
|
<p>Latitude found: {{ sar.SARCall.latitude_found }}</p>
|
|
|
|
<p>Description: {{ sar.SARCall.description }}</p>
|
|
|
|
{% if is_logged_in %}
|
2023-11-26 19:06:43 +00:00
|
|
|
<p>Description private: {{ sar.SARCall.description_hidden }}</p>
|
2023-11-19 21:08:19 +00:00
|
|
|
{% endif %}
|
2023-11-17 06:50:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<!-- Other SAR details -->
|
|
|
|
</tr>
|
|
|
|
</table>
|
2023-11-14 10:07:43 +00:00
|
|
|
</div>
|
2023-11-12 20:06:15 +00:00
|
|
|
</div>
|
2023-11-13 17:51:57 +00:00
|
|
|
|
2023-11-14 10:07:43 +00:00
|
|
|
<div>
|
2023-11-19 21:08:19 +00:00
|
|
|
{% if is_logged_in %}
|
2023-11-26 19:06:43 +00:00
|
|
|
<a href="{{ url_for('edit_sar', id=sar.SARCall.id) }}" class="btn btn-primary">Edit</a>
|
|
|
|
<a href="{{ url_for('delete_sar', id=sar.SARCall.id) }}" class="btn btn-danger">Delete</a>
|
2023-11-19 21:08:19 +00:00
|
|
|
{% endif %}
|
2023-11-14 10:07:43 +00:00
|
|
|
</div>
|
2023-11-13 17:51:57 +00:00
|
|
|
|
2023-11-14 10:07:43 +00:00
|
|
|
<div id="map" class="mb-4"></div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Display Comments -->
|
2023-11-19 21:08:19 +00:00
|
|
|
{% for comment in sar.SARCall.comments %}
|
2023-11-14 10:07:43 +00:00
|
|
|
<div class="comment">
|
2023-11-16 08:59:39 +00:00
|
|
|
<div class="card mb-4">
|
|
|
|
<div class="card-body">
|
2023-11-17 06:50:24 +00:00
|
|
|
<strong>{{ comment.user.full_name }}</strong>: at {{ comment.created }} ,
|
|
|
|
updated {{ comment.updated }}
|
2023-11-16 08:59:39 +00:00
|
|
|
<div class="card mb-5">
|
|
|
|
<div class="card-body">
|
2023-11-17 06:50:24 +00:00
|
|
|
<div class="comment-text"><p id="comment-text-{{ comment.id }}">{{ comment.text }}</p>
|
|
|
|
</div>
|
2023-11-16 08:59:39 +00:00
|
|
|
</div>
|
|
|
|
</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 %}
|
|
|
|
|
2023-11-19 21:08:19 +00:00
|
|
|
{% if is_logged_in %}
|
2023-11-26 19:06:43 +00:00
|
|
|
{% if current_user.id == comment.user_id or current_user.id == 1 or current_user.id == sar.SARCall.user_id %}
|
|
|
|
<button class="edit-comment-btn" data-comment-id="{{ comment.id }}"
|
|
|
|
data-comment-text="{{ comment.text }}">Edit
|
|
|
|
</button>
|
|
|
|
<!-- Button to Open GPX Upload Modal -->
|
|
|
|
<button type="button" class="gpx-upload-button" data-toggle="modal"
|
|
|
|
data-target="#uploadGPXModal"
|
|
|
|
data-comment-id="{{ comment.id }}">
|
|
|
|
Upload GPX File
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button type="button" class="delete-comment-btn">
|
|
|
|
<a href="{{ url_for('delete_comment', id=comment.id) }}">Delete</a>
|
|
|
|
</button>
|
2023-11-16 08:59:39 +00:00
|
|
|
|
2023-11-26 19:06:43 +00:00
|
|
|
{% endif %}
|
2023-11-16 08:59:39 +00:00
|
|
|
{% endif %}
|
|
|
|
</div>
|
2023-11-14 20:33:57 +00:00
|
|
|
</div>
|
2023-11-14 10:07:43 +00:00
|
|
|
</div>
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
<!-- Edit Comment Modal -->
|
|
|
|
<div class="modal fade" id="editCommentModal" tabindex="-1" aria-labelledby="editCommentModalLabel"
|
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="editCommentModalLabel">Edit Comment</h5>
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<form id="editCommentForm">
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="commentText" class="col-form-label">Comment:</label>
|
|
|
|
<textarea class="form-control" id="commentText"></textarea>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
|
|
<button type="button" class="btn btn-primary" id="saveComment">Save changes</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-13 17:51:57 +00:00
|
|
|
|
|
|
|
|
2023-11-14 10:07:43 +00:00
|
|
|
<!-- Add Comment Form -->
|
2023-11-26 19:06:43 +00:00
|
|
|
{% if is_logged_in %}
|
|
|
|
<form action="{{ url_for('add_comment', sar_call_id=sar.SARCall.id) }}" method="post"
|
|
|
|
enctype="multipart/form-data">
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="text">Comment:</label>
|
|
|
|
<textarea name="text" class="form-control"></textarea>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2023-11-14 20:33:57 +00:00
|
|
|
|
|
|
|
|
2023-11-26 19:06:43 +00:00
|
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Add Comment</button>
|
|
|
|
</form>
|
|
|
|
{% endif %}
|
2023-11-14 10:07:43 +00:00
|
|
|
</div>
|
2023-11-13 17:51:57 +00:00
|
|
|
|
2023-11-14 20:33:57 +00:00
|
|
|
<!-- GPX File Upload Modal -->
|
|
|
|
<div class="modal fade" id="uploadGPXModal" tabindex="-1" aria-labelledby="uploadGPXModalLabel" aria-hidden="true">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="uploadGPXModalLabel">Upload GPX File</h5>
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<form id="uploadGPXForm" method="post" enctype="multipart/form-data">
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="gpxFileName">Description: </label>
|
|
|
|
<input type="text" class="form-control" id="gpxFileName" name="gpxFileName" required>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="gpxFile">GPX File</label>
|
|
|
|
<input type="file" class="form-control" id="gpxFile" name="gpxFile" required>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<input type="hidden" id="commentIdForGPX" name="commentId">
|
2023-11-19 21:08:19 +00:00
|
|
|
<input type="hidden" id="sarIdForGPX" name="sarId" value="{{ sar.SARCall.id }}">
|
2023-11-14 20:33:57 +00:00
|
|
|
<div class="modal-footer">
|
|
|
|
<button type="submit" class="btn btn-primary">Upload</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
2023-11-12 20:06:15 +00:00
|
|
|
<script>
|
2023-11-15 14:24:56 +00:00
|
|
|
|
|
|
|
// Load GPX file and add to map
|
|
|
|
function loadAndDisplayGPX(gpxId) {
|
|
|
|
fetch('/get_gpx/' + gpxId)
|
|
|
|
.then(response => response.text())
|
|
|
|
.then(gpxData => {
|
2023-11-26 19:06:43 +00:00
|
|
|
new L.GPX(gpxData, {
|
|
|
|
async: true,
|
|
|
|
marker_options: {
|
|
|
|
startIconUrl: '/static/pin-icon-start.png',
|
|
|
|
endIconUrl: '/static/pin-icon-end.png',
|
|
|
|
shadowUrl: '/static/pin-shadow.png'
|
|
|
|
}
|
|
|
|
}).on('loaded', function (e) {
|
2023-11-15 14:24:56 +00:00
|
|
|
map.fitBounds(e.target.getBounds());
|
|
|
|
}).addTo(map);
|
|
|
|
})
|
|
|
|
.catch(error => console.error('Error loading GPX file:', error));
|
|
|
|
}
|
|
|
|
|
|
|
|
var gpxData = {{ gpx_ids | tojson }};
|
2023-11-14 20:33:57 +00:00
|
|
|
|
2023-11-19 21:08:19 +00:00
|
|
|
var map = L.map('map').setView([{{ sar.SARCall.latitude }}, {{ sar.SARCall.longitude }}], 13);
|
2023-11-12 20:06:15 +00:00
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
maxZoom: 19,
|
|
|
|
attribution: '© OpenStreetMap contributors'
|
|
|
|
}).addTo(map);
|
2023-11-19 21:08:19 +00:00
|
|
|
L.marker([{{ sar.SARCall.latitude }}, {{ sar.SARCall.longitude }}]).addTo(map);
|
2023-11-14 20:33:57 +00:00
|
|
|
|
2023-11-15 14:24:56 +00:00
|
|
|
gpxData.forEach(function (id) {
|
|
|
|
loadAndDisplayGPX(id);
|
2023-11-14 20:33:57 +00:00
|
|
|
});
|
2023-11-15 14:24:56 +00:00
|
|
|
|
2023-11-12 20:06:15 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
2023-11-14 10:07:43 +00:00
|
|
|
<script>
|
|
|
|
var commentId; // Declare this outside of the .edit-comment-btn click handler
|
|
|
|
var commentText; // Declare this outside of the .edit-comment-btn click handler
|
|
|
|
$(document).ready(function () {
|
|
|
|
$('.edit-comment-btn').on('click', function () {
|
|
|
|
// Get the comment data
|
|
|
|
commentId = $(this).data('comment-id');
|
|
|
|
commentText = $(this).data('comment-text');
|
|
|
|
|
|
|
|
// Set the comment data in the modal
|
|
|
|
$('#commentText').val(commentText);
|
|
|
|
$('#editCommentModal').modal('show');
|
|
|
|
|
|
|
|
// Save changes
|
|
|
|
$('#saveComment').on('click', function () {
|
|
|
|
$.ajax({
|
|
|
|
url: '/edit_comment/' + commentId,
|
|
|
|
method: 'POST',
|
|
|
|
data: {comment: $('#commentText').val()},
|
|
|
|
success: function (response) {
|
|
|
|
// Update the comment display on the page
|
2023-11-14 20:33:57 +00:00
|
|
|
$('#comment-text-' + commentId).text($('#commentText').val());
|
|
|
|
$('button.edit-comment-btn[data-comment-id="' + commentId + '"]').data('comment-text', $('#commentText').val());
|
2023-11-14 10:07:43 +00:00
|
|
|
$('#editCommentModal').modal('hide');
|
|
|
|
// Update the comment display on the page as needed
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
// Handle error
|
|
|
|
alert("Error updating comment");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
2023-11-14 20:33:57 +00:00
|
|
|
<script>
|
|
|
|
var commentId;
|
|
|
|
|
|
|
|
$('.gpx-upload-button').on('click', function () {
|
|
|
|
var commentId = $(this).data('comment-id');
|
|
|
|
$('#commentIdForGPX').val(commentId);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
{#commentId = $(this).data('comment-id');#}
|
|
|
|
{#console.log(commentId);#}
|
|
|
|
// Handle form submission
|
|
|
|
$('#uploadGPXForm').on('submit', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var formData = new FormData(this);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: '/upload_gpx', // Update with the correct route
|
|
|
|
type: 'POST',
|
|
|
|
data: formData,
|
|
|
|
contentType: false,
|
|
|
|
processData: false,
|
|
|
|
success: function (response) {
|
|
|
|
// Handle success - Close modal, Update the map with new GPX data
|
|
|
|
$('#uploadGPXModal').modal('hide');
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
// Handle error
|
|
|
|
alert("Error uploading GPX file");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-12 20:06:15 +00:00
|
|
|
{% endblock %}
|