Skip to content

Commit

Permalink
Merge branch 'dev' into feature/integration_point_buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
phycodurus authored Nov 28, 2023
2 parents 84e6412 + f0355ce commit 277b795
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<table class="table table-striped">
<thead><tr><th>Facility</th><th>Created</th><th>Status</th><th>Scheduled</th><th>Saved data</th><th>View</th></tr></thead>
<thead><tr><th>Facility</th><th>Observation ID</th><th>Created</th><th>Status</th><th>Scheduled</th><th>Saved data</th><th>View</th></tr></thead>
<tbody>
{% for observation in observations %}
<tr>
<td>{{ observation.facility }}</td>
{% if observation.url %}
<td><a href="{{ observation.url }}">{{ observation.observation_id }}</a></td>
{% else %}
<td>{{ observation.observation_id }}</td>
{% endif %}
<td>{{ observation.created }}</td>
<td>{{ observation.status }}</td>
<td>{{ observation.scheduled_start }}</td>
Expand Down
6 changes: 3 additions & 3 deletions tom_observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ def form_valid(self, form):
)
observation_id = form.cleaned_data['observation_id']
messages.success(self.request, f'Successfully associated observation record {observation_id}')
return redirect(reverse(
'tom_targets:detail', kwargs={'pk': form.cleaned_data['target_id']})
)
base_url = reverse('tom_targets:detail', kwargs={'pk': form.cleaned_data['target_id']})
query_params = urlencode({'tab': 'observations'})
return redirect(f'{base_url}?{query_params}')


class ObservationRecordDetailView(DetailView):
Expand Down
39 changes: 25 additions & 14 deletions tom_targets/templates/tom_targets/target_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@
{% endblock %}
{% block content %}
<script>
// This script maintains the selected tab upon reload
$(document).ready(function(){
// This is required due to the apparent redefinition of $ in another library: https://api.jquery.com/jquery.noconflict/
// Based on trial and error, the offending script appears to be JS9, which is used in dataproduct_list_for_target
$.noConflict();
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
localStorage.setItem('activeTab', $(e.target).attr('href'));
});
// Function to update the URL.
const updateUrlWithTab = (tabId) => {
const url = new URL(window.location.href);
url.searchParams.set('tab', tabId);
history.replaceState({}, document.title, url.toString());
};

document.addEventListener("DOMContentLoaded", function() {
// Listen for tab changes.
document.querySelectorAll('#tabs .nav-link').forEach(tab => {
tab.addEventListener('click', function() {
updateUrlWithTab(this.id.replace('-tab', ''));
});
});

var activeTab = localStorage.getItem('activeTab');
if(activeTab){
$('#tabs a[href="' + activeTab + '"]').tab('show');
}
});
// Initial tab selection from URL.
const tabQuery = new URL(window.location.href).searchParams.get('tab');
if (tabQuery) {
const activeTab = '#' + tabQuery;
const tabElement = document.querySelector(`a[href="${activeTab}"]`);
if (tabElement) {
tabElement.click();
}
}
});
</script>
<div class="row">
<div class="col-md-4">
Expand All @@ -39,7 +50,7 @@
{% if object.type == 'SIDEREAL' %}
{% aladin object %}
{% endif %}

</div>
</div>
<div class="col-md-8">
Expand Down
2 changes: 1 addition & 1 deletion tom_targets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def get(self, request, *args, **kwargs):
'Did you know updating observation statuses can be automated? Learn how in'
'<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
' the docs.</a>'))
return redirect(reverse('tom_targets:detail', args=(target_id,)))
return redirect(reverse('tom_targets:detail', args=(target_id,)) + '?tab=observations')

obs_template_form = ApplyObservationTemplateForm(request.GET)
if obs_template_form.is_valid():
Expand Down

0 comments on commit 277b795

Please sign in to comment.