Skip to content

Commit

Permalink
Merge pull request #628 from RickWangPerth/v2.1.5prod
Browse files Browse the repository at this point in the history
Fix search for existing turtles with new tags bug
  • Loading branch information
RickWangPerth authored Dec 6, 2024
2 parents 8d88f2d + eeb849d commit fd15902
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 112 deletions.
2 changes: 1 addition & 1 deletion kustomize/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ patches:
- path: service_patch.yaml
images:
- name: ghcr.io/dbca-wa/wastd
newTag: 2.1.4
newTag: 2.1.5

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[tool.poetry]
name = "wastd"
version = "2.1.4"

version = "2.1.5"

description = "Western Australian Sea Turtles Database"
authors = ["Florian Mayer <[email protected]>", "Ashley Felton <[email protected]>","Evan Hallein <[email protected]>", "Rick Wang <[email protected]>"]
Expand Down
14 changes: 13 additions & 1 deletion wamtram2/static/js/observation_management.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ function setTagInfo() {
const tagContainer = document.getElementById('tagContainer');
if (tagContainer && initialData.tag_info?.recorded_tags) {
tagContainer.innerHTML = '';

if (initialData.tag_info.recorded_tags.length === 0) {
tagContainer.innerHTML = '<p class="text-muted">No flipper tags found</p>';
return;
}

initialData.tag_info.recorded_tags.forEach(tag => {
const tagHtml = `
<div class="card mb-3 tag-card">
Expand Down Expand Up @@ -331,6 +337,12 @@ function setTagInfo() {
const pitTagContainer = document.getElementById('pitTagContainer');
if (pitTagContainer && initialData.tag_info?.recorded_pit_tags) {
pitTagContainer.innerHTML = '';

if (initialData.tag_info.recorded_pit_tags.length === 0) {
pitTagContainer.innerHTML = '<p class="text-muted">No PIT tags found</p>';
return;
}

initialData.tag_info.recorded_pit_tags.forEach(pitTag => {
const pitTagHtml = `
<div class="card mb-3 pit-tag-card">
Expand All @@ -344,7 +356,7 @@ function setTagInfo() {
</div>
<div class="col-md-4">
<div class="form-group">
<label>Side</label>
<label>Position</label>
<select class="form-control" name="pit_tag_position">
<option value="LF" ${pitTag.tag_position === 'LF' ? 'selected' : ''}>L</option>
<option value="RF" ${pitTag.tag_position === 'RF' ? 'selected' : ''}>R</option>
Expand Down
139 changes: 83 additions & 56 deletions wamtram2/templates/wamtram2/find_turtle.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ <h5 class="text-center mt-4">Create for a Tagged Turtle</h5>
{% csrf_token %}
<div class="form-group">
<label for="tag_id">Flipper/ PIT tag ID:</label>
<p style="color: red; font-size: 0.9em; margin-top: 5px;">
<strong> Note: </strong> For <strong> PIT tag </strong> search, please use the <strong> LEFT </strong> one.
If you have to use the <strong> RIGHT </strong> one, please <strong> change the auto filled PIT tag to right </strong> in the form manually.
</p>
<input type="text" class="form-control" id="tag_id" name="tag_id" required>
</div>
<input type="hidden" id="tag_type" name="tag_type" value="{{ tag_type }}">
Expand All @@ -103,69 +107,92 @@ <h5 class="text-center mt-4">Create for a Tagged Turtle</h5>
<button id="exactMatchYes" class="btn btn-primary">Yes, I have double checked</button>
<button id="exactMatchNo" class="btn btn-secondary">No, I will reenter</button>
</div>

{% if turtle %}
<div class="container border pb-3 mt-3">
<div class="mt-3 row justify-content-md-center">
<div class="col-md-auto"><strong>Tag ID:</strong> {{ tag_id }} </div>
<div class="col-md-auto">
<strong>ID:</strong>
{% if turtle and not existing_turtle_entry %}
<div class="container border pb-3 mt-3">
<div class="mt-3 row justify-content-md-center">
<div class="col-md-auto"><strong>Tag ID:</strong> {{ tag_id }} </div>
<div class="col-md-auto">
<strong>ID:</strong>
<a href="{% url 'wamtram2:turtle_detail' turtle.turtle_id %}" target="_blank">{{ turtle.turtle_id }}</a>
</div>
<div class="col-md-auto"><strong>Sex:</strong> {{ turtle.sex }}</div>
<div class="col-md-auto"><strong>Species:</strong> {{ turtle.species_code }}</div>
{% if first_observation_date %}
<div class="col-md-auto"><strong>First Observed:</strong> {{ first_observation_date|perth_time|date:"Y-m-d" }}</div>
{% endif %}
{% if latest_site %}
<div class="col-md-auto"><strong>Latest Site:</strong> {{ latest_site }}</div>
{% endif %}
</div>
</div>
<div class="text-center mt-4">
<p>Does the species and sex match the data sheet?</p>
<a id="createForExistingTurtle" href="{% url 'wamtram2:existingtrtdataentry' batch_id=form.batch_id.value turtle_id=turtle.turtle_id %}" class="btn btn-primary mt-2 ml-md-2">Yes, create a record for this turtle</a>
<form method="post" style="display: inline;">
{% csrf_token %}
<input type="hidden" name="tag_id" value="{{ tag_id}}">
<input type="hidden" name="tag_type" value="{{ tag_type }}">
<input type="hidden" name="tag_side" value="{{ tag_side }}">
<input type="hidden" name="create_and_review" value="true">
<input type="hidden" id="set_do_not_process" name="set_do_not_process" value="false">
<input type="hidden" id="no_turtle_found" value="{{ no_turtle_found }}">
<input type="hidden" id="batch_id" name="batch_id" value="{{ form.batch_id.value }}">
{% comment %} <button type="submit" name="create_and_review_later" id="createAndReviewLater" value="true" class="btn btn-secondary mt-2 ml-md-2">No, create the record and review later</button> {% endcomment %}
<a href="{% url 'wamtram2:existingtrtdataentry' batch_id=form.batch_id.value turtle_id=turtle.turtle_id %}"
id="createAndReviewLater"
class="btn btn-secondary mt-2 ml-md-2">
No, create the record and review later
</a>
</form>
</div>
{% elif existing_turtle_entry %}
<div class="alert alert-info mt-3">
<p>You are searching for a new tag given to an existing turtle this season. Here is the turtle information:</p>
</div>
<div class="container border pb-3 mt-3">
<div class="mt-3 row justify-content-md-center">
<div class="col-md-auto"><strong>Tag ID:</strong> {{ tag_id }}</div>
<div class="col-md-auto">
<strong>ID:</strong>
<a href="{% url 'wamtram2:turtle_detail' turtle.turtle_id %}" target="_blank">{{ turtle.turtle_id }}</a>
</div>
<div class="col-md-auto"><strong>Sex:</strong> {{ turtle.sex }}</div>
<div class="col-md-auto"><strong>Species:</strong> {{ turtle.species_code }}</div>
<div class="col-md-auto"><strong>Tag Added Date:</strong> {{ existing_turtle_entry.entry_batch.entry_date|date:"Y-m-d" }}</div>
<div class="col-md-auto"><strong>Location:</strong> {{ existing_turtle_entry.place_code.place_name }}</div>
</div>
<div class="col-md-auto"><strong>Sex:</strong> {{ turtle.sex }}</div>
<div class="col-md-auto"><strong>Species:</strong> {{ turtle.species_code }}</div>
{% if first_observation_date %}
<div class="col-md-auto"><strong>First Observed:</strong> {{ first_observation_date|perth_time|date:"Y-m-d" }}</div>
{% endif %}
{% if latest_site %}
<div class="col-md-auto"><strong>Latest Site:</strong> {{ latest_site }}</div>
{% endif %}
</div>
</div>
<div class="text-center mt-4">
<p>Does the species and sex match the data sheet?</p>
<a id="createForExistingTurtle" href="{% url 'wamtram2:existingtrtdataentry' batch_id=form.batch_id.value turtle_id=turtle.turtle_id %}" class="btn btn-primary mt-2 ml-md-2">Yes, create a record for this turtle</a>
<form method="post" style="display: inline;">
{% csrf_token %}
<input type="hidden" name="tag_id" value="{{ tag_id}}">
<input type="hidden" name="tag_type" value="{{ tag_type }}">
<input type="hidden" name="tag_side" value="{{ tag_side }}">
<input type="hidden" name="create_and_review" value="true">
<input type="hidden" id="set_do_not_process" name="set_do_not_process" value="false">
<input type="hidden" id="no_turtle_found" value="{{ no_turtle_found }}">
<input type="hidden" id="batch_id" name="batch_id" value="{{ form.batch_id.value }}">
{% comment %} <button type="submit" name="create_and_review_later" id="createAndReviewLater" value="true" class="btn btn-secondary mt-2 ml-md-2">No, create the record and review later</button> {% endcomment %}
<div class="text-center mt-4">
<p>Is this the turtle you are looking for?</p>
<a href="{% url 'wamtram2:existingtrtdataentry' batch_id=form.batch_id.value turtle_id=turtle.turtle_id %}"
id="createAndReviewLater"
class="btn btn-secondary mt-2 ml-md-2">
class="btn btn-primary mt-2">Yes, create a record for this turtle</a>
<a href="{% url 'wamtram2:newtrtdataentry' batch_id=form.batch_id.value %}"
class="btn btn-secondary mt-2 ml-2">No, create new record</a>
</div>
{% elif new_tag_entry %}
<div class="alert alert-info mt-3">
<p>No existing turtle found with this tag in the database, but an entry with this tag was found within this season:</p>
</div>
<div class="container border pb-3 mt-3">
<div class="mt-3 row justify-content-md-center">
<div class="col-md-auto"><strong>Tag ID:</strong> {{ tag_id }}</div>
<div class="col-md-auto"><strong>Entry ID:</strong> {{ new_tag_entry.data_entry_id }}</div>
<div class="col-md-auto"><strong>Observation Date:</strong> {{ new_tag_entry.entry_batch.entry_date|date:"Y-m-d" }}</div>
<div class="col-md-auto"><strong>Place:</strong> {{ new_tag_entry.place_code.place_name }}</div>
<div class="col-md-auto"><strong>Species:</strong> {{ new_tag_entry.species_code.common_name }}</div>
<div class="col-md-auto"><strong>Sex:</strong> {{ new_tag_entry.sex }}</div>
</div>
</div>
<div class="text-center mt-4">
<p class="mt-3">This may be a recapture of a new turtle from this season</p>
<a href="{% url 'wamtram2:newtrtdataentry' batch_id=form.batch_id.value %}" class="btn btn-primary mt-2">Yes, Create New Data Entry</a>
<a
href="{% url 'wamtram2:newtrtdataentry' batch_id=form.batch_id.value %}"
id="createAndReviewLaterUnprocessedTurtle"
class="btn btn-secondary mt-2">
No, create the record and review later
</a>
</form>
</div>
{% elif new_tag_entry %}
<div class="alert alert-info mt-3">
<p>No existing turtle found with this tag in the database, but an entry with this tag was found within this season:</p>
</div>
<div class="container border pb-3 mt-3">
<div class="mt-3 row justify-content-md-center">
<div class="col-md-auto"><strong>Tag ID:</strong> {{ tag_id }}</div>
<div class="col-md-auto"><strong>Entry ID:</strong> {{ new_tag_entry.data_entry_id }}</div>
<div class="col-md-auto"><strong>Observation Date:</strong> {{ new_tag_entry.entry_batch.entry_date|date:"Y-m-d" }}</div>
<div class="col-md-auto"><strong>Place:</strong> {{ new_tag_entry.place_code.place_name }}</div>
<div class="col-md-auto"><strong>Species:</strong> {{ new_tag_entry.species_code.common_name }}</div>
<div class="col-md-auto"><strong>Sex:</strong> {{ new_tag_entry.sex }}</div>
</div>
</div>
<div class="text-center mt-4">
<p class="mt-3">This may be a recapture of a new turtle from this season</p>
<a href="{% url 'wamtram2:newtrtdataentry' batch_id=form.batch_id.value %}" class="btn btn-primary mt-2">Yes, Create New Data Entry</a>
<a
href="{% url 'wamtram2:newtrtdataentry' batch_id=form.batch_id.value %}"
id="createAndReviewLaterUnprocessedTurtle"
class="btn btn-secondary mt-2">
No, create the record and review later
</a>
</div>
{% endif %}
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions wamtram2/templates/wamtram2/observation_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ <h4>Other Information</h4>
{% else %}
const initialData = null;
{% endif %}

const tagStateChoices = {{ tag_states_choices|safe }};
const pitTagStateChoices = {{ pit_tag_state_choices|safe }};
const measurementTypeChoices = {{ measurement_type_choices|safe }};
</script>
<script src="{% static 'js/observation_management.js' %}"></script>
{% endblock %}
48 changes: 32 additions & 16 deletions wamtram2/templates/wamtram2/trtdataentry_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ <h5><span style="color: red; font-weight: bold">NEW</span> Flipper Tag(s)</h5>
<!-- Recapture PIT Tags -->
<div id="recapturePIT">
<h5><span style="color: blue; font-weight: bold">OLD</span> PIT Tag(s)</h5>
<p style="color: red; font-style: italic; margin-bottom: 15px;">
Note: If you searched using a <strong>RIGHT</strong> PIT tag, please manually copy it to the right PIT tag field.
</p>
<div class="row mt-2">
<div class="col-md-6">
<div class="row">
Expand Down Expand Up @@ -1139,12 +1142,14 @@ <h5 class="modal-title" id="summaryModalLabel">Summary of Your Inputs</h5>

// Handle form changes to track dirty state
form.addEventListener('input', function() {
isFormDirty = true;
if (!isSubmitting) {
isFormDirty = true;
}
});

// Prompt the user if they try to leave the page with unsaved changes
window.addEventListener('beforeunload', function(event) {
if (isFormDirty) {
if (isFormDirty && !isSubmitting) {
event.preventDefault();
event.returnValue = '';
return '';
Expand All @@ -1154,15 +1159,28 @@ <h5 class="modal-title" id="summaryModalLabel">Summary of Your Inputs</h5>
// Handle form submission
form.addEventListener('submit', function(event) {
if (form.checkValidity()) {
showLoadingOverlay();
isFormDirty = false;
isSubmitting = true;
isFormDirty = false;
showLoadingOverlay();

} else {
event.preventDefault();
showLoadingOverlay();
scrollToErrors();
event.preventDefault();
showLoadingOverlay();
scrollToErrors();
}
});


// Handle page reload on back navigation
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
window.location.reload();
isFormDirty = false;
isSubmitting = false;
}
});


function scrollToErrors() {
const errorDiv = document.querySelector('.is-invalid');
if (errorDiv) {
Expand All @@ -1178,13 +1196,6 @@ <h5 class="modal-title" id="summaryModalLabel">Summary of Your Inputs</h5>
if (overlay) overlay.style.display = 'block';
if (spinner) spinner.style.display = 'block';
}

// Handle page reload on back navigation
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
window.location.reload();
}
});
});
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('dataEntryForm');
Expand Down Expand Up @@ -1216,6 +1227,8 @@ <h5 class="modal-title" id="summaryModalLabel">Summary of Your Inputs</h5>
const confirmSaveButton = document.getElementById('confirmSaveButton');
const observationDateInput = document.querySelector('input[name="observation_date"]');
const dateErrorMessage = document.getElementById('date-error-message');
let isFormDirty = false;
let isSubmitting = false;

const labelMapping = {
"search_entered_by": "Enterer",
Expand Down Expand Up @@ -1378,9 +1391,12 @@ <h5 class="modal-title" id="summaryModalLabel">Summary of Your Inputs</h5>

if (confirmSaveButton) {
confirmSaveButton.addEventListener('click', function() {
$(summaryModal).modal('hide');
isSubmitting = true;
isFormDirty = false;
form.submit();
$(summaryModal).modal('hide');
setTimeout(() => {
form.submit();
}, 100);
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions wamtram2/templates/wamtram2/trtentrybatch_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@
<div class="row">
<div class="col-md-8">
{% if request.user.is_superuser or request.user|has_group:"WAMTRAM2_STAFF" or request.user|has_group:"WAMTRAM2_TEAM_LEADER"%}
<a id="validateBtn" href="{% url 'wamtram2:validate_data_entry_batch' batch_id=batch.entry_batch_id %}?return_to=curation" class="btn btn-primary mr-2">Validate this Batch</a>
<a id="validateBtn" href="{% url 'wamtram2:validate_data_entry_batch' batch_id=batch.entry_batch_id %}" class="btn btn-primary mr-2">Validate this Batch</a>
{% endif %}
{% if request.user.is_superuser %}
<a id="processBtn" href="{% url 'wamtram2:process_data_entry_batch' batch_id=batch.entry_batch_id %}?return_to=curation" class="btn btn-primary">Add this batch to the database</a>
<a id="processBtn" href="{% url 'wamtram2:process_data_entry_batch' batch_id=batch.entry_batch_id %}" class="btn btn-primary">Add this batch to the database</a>
{% endif %}
</div>
<div class="col-md-4">
Expand Down
Loading

0 comments on commit fd15902

Please sign in to comment.