Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatting for HTML templates #985

Merged
merged 18 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ loc: ## Generate lines of code report

lint: lint-py lint-js ## Check formatting issues

format: format-py format-js ## Fix formatting issues where possible
format: format-py format-js format-html ## Fix formatting issues where possible

lint-py: ## Check python formatting issues
@ruff format . --check && ruff .
Expand All @@ -76,6 +76,9 @@ lint-js: ## Check javascript formatting issues
format-js: ## Fix javascript formatting issues where possible
@npm --prefix ./frontend run format

format-html: ## Fix HTML formatting issues where possible
@djhtml . --tabwidth 2

test: ## Run python tests
@py.test

Expand Down
38 changes: 19 additions & 19 deletions hawc/apps/animal/templates/animal/animalgroup_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ <h2>{{object}}</h2>
<a class="dropdown-item" href="{% url 'animal:animal_group_delete' object.pk %}">Delete</a>

{% if object.dosing_regime and object == object.dosing_regime.dosed_animals %}
<div class="dropdown-divider"></div>
<span class="dropdown-header">Dose Regime Editing</span>
<a class="dropdown-item" href="{% url 'animal:dosing_regime_update' object.dosing_regime.pk %}">Update</a>
<a class="dropdown-item" href="{% audit_url object.dosing_regime %}">View change logs</a>
<div class="dropdown-divider"></div>
<span class="dropdown-header">Dose Regime Editing</span>
<a class="dropdown-item" href="{% url 'animal:dosing_regime_update' object.dosing_regime.pk %}">Update</a>
<a class="dropdown-item" href="{% audit_url object.dosing_regime %}">View change logs</a>
{% endif %}

<div class="dropdown-divider"></div>
Expand All @@ -26,27 +26,27 @@ <h2>{{object}}</h2>
</div>

{% if crud == "Read" %}
<div id="animalGroupTableMain"></div>
<div id="animalGroupTableMain"></div>
{% endif %}

{% endblock %}


{% block extrajs %}

{{ config|json_script:"config" }}
<script type="text/javascript">
window.app.startup("animalStartup", function(animal){
const data = window.app.getConfig();
animal.AnimalGroup.get_object(data.id, function(d){
inserts = [d.build_details_table()];
if (data.has_dosing_regime){
inserts.push($("<h3>Dosing regime</h3>"));
inserts.push(d.build_dr_details_table());
}
$('div#animal-group-header').after(inserts);
{{ config|json_script:"config" }}
<script type="text/javascript">
window.app.startup("animalStartup", function(animal){
const data = window.app.getConfig();
animal.AnimalGroup.get_object(data.id, function(d){
inserts = [d.build_details_table()];
if (data.has_dosing_regime){
inserts.push($("<h3>Dosing regime</h3>"));
inserts.push(d.build_dr_details_table());
}
$('div#animal-group-header').after(inserts);
});
animal.startupAnimalGroupTable(document.getElementById("animalGroupTableMain"), data);
});
animal.startupAnimalGroupTable(document.getElementById("animalGroupTableMain"), data);
});
</script>
</script>
{% endblock %}
200 changes: 100 additions & 100 deletions hawc/apps/animal/templates/animal/animalgroup_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<legend class='d-inline-block'>Dose-groups</legend>
<span class='float-right'>
<a class="btn btn-primary" id="new_dose_column" href="#">Add new representation</a>
<a class='btn btn-primary' href="{% url 'assessment:dose_units_create' assessment.pk %}" onclick="return window.app.HAWCUtils.newWindowPopupLink(this);" title="Add new dose-units">+</a>
<a class="btn btn-primary" id="new_dose_column" href="#">Add new representation</a>
<a class='btn btn-primary' href="{% url 'assessment:dose_units_create' assessment.pk %}" onclick="return window.app.HAWCUtils.newWindowPopupLink(this);" title="Add new dose-units">+</a>
</span>

{% if dose_groups_errors %}
Expand All @@ -31,114 +31,114 @@
{% endblock %}

{% block extrajs %}
<script type="text/javascript">
$(document).ready(function() {
var printf = window.app.HAWCUtils.printf,
animalGroupSetup = function(){
var onSpeciesChange = function(e, onStrainUpdateComplete){
<script type="text/javascript">
$(document).ready(function() {
var printf = window.app.HAWCUtils.printf,
animalGroupSetup = function(){
var onSpeciesChange = function(e, onStrainUpdateComplete){
// only show proper strains for a given species
var selected = $('#id_strain option:selected').val(),
update_strain_opts = function(d){
var opts = _.map(d, function(v, i){
return printf('<option value="{0}">{1}</option>', v.id, v.name);
}).join('');

$('#id_strain').html(opts);
$(printf('#id_strain option[value="{0}"]', selected))
.prop('selected', true);

if (onStrainUpdateComplete !== undefined) {
onStrainUpdateComplete();
}
}
$.get(
'{% url "assessment:api:strain-list" %}',
{species: $('#id_species').val()},
update_strain_opts
);
};

$('#id_species')
.change(onSpeciesChange)
.trigger('change');
var selected = $('#id_strain option:selected').val(),
update_strain_opts = function(d){
var opts = _.map(d, function(v, i){
return printf('<option value="{0}">{1}</option>', v.id, v.name);
}).join('');

$('#id_strain').html(opts);
$(printf('#id_strain option[value="{0}"]', selected))
.prop('selected', true);

if (onStrainUpdateComplete !== undefined) {
onStrainUpdateComplete();
}
}
$.get(
'{% url "assessment:api:strain-list" %}',
{species: $('#id_species').val()},
update_strain_opts
);
};

$('#id_species')
.change(onSpeciesChange)
.trigger('change');

// refresh species after "Add new strain" popup closes. Wait half a second
// to give the addition, if any, time to register.
$("a[title='Add new strain']").on(window.app.HAWCUtils.HAWC_NEW_WINDOW_POPUP_CLOSING, function(e) {
setTimeout(function() {
var numStrainsBefore = $("#id_strain option").length;
$("a[title='Add new strain']").on(window.app.HAWCUtils.HAWC_NEW_WINDOW_POPUP_CLOSING, function(e) {
setTimeout(function() {
var numStrainsBefore = $("#id_strain option").length;

// reload the species
onSpeciesChange(null, function() {
var strains = $("#id_strain option");
onSpeciesChange(null, function() {
var strains = $("#id_strain option");

if (strains.length > numStrainsBefore) {
if (strains.length > numStrainsBefore) {
// a new one was added; let's select it.
var highestId = -1;
strains.each(function() {
highestId = Math.max(Number($(this).val()), highestId);
});

$("#id_strain").val(highestId);
}
});
}, 500);
var highestId = -1;
strains.each(function() {
highestId = Math.max(Number($(this).val()), highestId);
});

$("#id_strain").val(highestId);
}
});
}, 500);
});
},
dosingRegimeSetup = function(){
var drc = $('#dosingRegimeContainer'),
drf = $('#dosing_regime'),
drInput = $('#id_dosing_regime'),
genInput = $('#id_generation'),
drcInsertLocation = $('.form-actions'),
dose_values = undefined,
dose_types = {{dose_types|safe}},
onDosingRegimeChange = function(){
var show = isNaN(parseInt(drInput.val()));
return (show) ?
drc.insertBefore(drcInsertLocation) :
drc.detach();
},
dosingRegimeSetup = function(){
var drc = $('#dosingRegimeContainer'),
drf = $('#dosing_regime'),
drInput = $('#id_dosing_regime'),
genInput = $('#id_generation'),
drcInsertLocation = $('.form-actions'),
dose_values = undefined,
dose_types = {{dose_types|safe}},
onDosingRegimeChange = function(){
var show = isNaN(parseInt(drInput.val()));
return (show) ?
drc.insertBefore(drcInsertLocation) :
drc.detach();
},
onGenerationChange = function(){
var drSelectorDiv = drInput.parent().parent(),
val = genInput.val();

if (val !== 'P0'){
drSelectorDiv.show();
} else {
drSelectorDiv.hide();
onDosingRegimeChange();
}
};
onGenerationChange = function(){
var drSelectorDiv = drInput.parent().parent(),
val = genInput.val();

if (val !== 'P0'){
drSelectorDiv.show();
} else {
drSelectorDiv.hide();
onDosingRegimeChange();
}
};

// reorganize forms
drc.prepend(drf.children());
drc.insertBefore(drcInsertLocation);
drf.remove();

{% if dose_groups_json %}
dose_values = {{dose_groups_json|safe}};
{% endif %}

genInput
.change(onGenerationChange)
.trigger('change');

drInput
.change(onDosingRegimeChange)
.trigger('change');

window.app.startup("animalStartup", function(animal){
new animal.DosingRegimeForm(
$("#animal_group"), dose_types, dose_values);
})
}

animalGroupSetup();
{% if crud == "Create" %}
dosingRegimeSetup();
{% endif %}
$('#id_name').focus();
});
</script>
drc.prepend(drf.children());
drc.insertBefore(drcInsertLocation);
drf.remove();

{% if dose_groups_json %}
dose_values = {{dose_groups_json|safe}};
{% endif %}

genInput
.change(onGenerationChange)
.trigger('change');

drInput
.change(onDosingRegimeChange)
.trigger('change');

window.app.startup("animalStartup", function(animal){
new animal.DosingRegimeForm(
$("#animal_group"), dose_types, dose_values);
})
}

animalGroupSetup();
{% if crud == "Create" %}
dosingRegimeSetup();
{% endif %}
$('#id_name').focus();
});
</script>
{% endblock extrajs %}
16 changes: 8 additions & 8 deletions hawc/apps/animal/templates/animal/dosingregime_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
{% block extrajs %}
<script type="text/javascript">
// reorganize forms
var actions = $('.form-actions');
$('#doseGroupsDiv').insertBefore($('.form-actions'))
var actions = $('.form-actions');
$('#doseGroupsDiv').insertBefore($('.form-actions'))

var dose_types = {{dose_types|safe}},
dose_values = {{dose_groups_json|safe}};
var dose_types = {{dose_types|safe}},
dose_values = {{dose_groups_json|safe}};

window.app.startup("animalStartup", function(animal){
new animal.DosingRegimeForm($("#dosing_regime"), dose_types, dose_values);
})
$('#id_route_of_exposure').focus();
window.app.startup("animalStartup", function(animal){
new animal.DosingRegimeForm($("#dosing_regime"), dose_types, dose_values);
})
$('#id_route_of_exposure').focus();
</script>
{% endblock extrajs %}
36 changes: 18 additions & 18 deletions hawc/apps/animal/templates/animal/endpoint_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
{% block content %}

{% if crud == "Read" %}
<div class="d-flex">
<h2>{{object}}</h2>
{% if obj_perms.edit %}
{% actions %}
<div class="d-flex">
<h2>{{object}}</h2>
{% if obj_perms.edit %}
{% actions %}
<span class="dropdown-header">Endpoint Editing</span>
<a class="dropdown-item" href="{{ object.get_update_url }}">Update endpoint</a>
<a class="dropdown-item" href="{% audit_url object %}">View change logs</a>
Expand All @@ -23,15 +23,15 @@ <h2>{{object}}</h2>
{% endif %}
{% endif %}
{% endif %}
{% endactions %}
{% elif assessment.enable_bmd and object.bmd_modeling_possible and bmd_session %}
{% actions %}
{% endactions %}
{% elif assessment.enable_bmd and object.bmd_modeling_possible and bmd_session %}
{% actions %}
<span class="dropdown-header">BMD Modeling</span>
<a class="dropdown-item" href="{{bmd_session.get_absolute_url}}">Latest session</a>
<a class="dropdown-item" href="{% url 'bmd:session_list' object.pk %}">All sessions</a>
{% endactions %}
{% endif %}
</div>
{% endactions %}
{% endif %}
</div>
{% endif %}

<!-- Endpoint details -->
Expand All @@ -55,13 +55,13 @@ <h3>Plot</h3>

{% block extrajs %}
<script type="text/javascript">
const data = {{object.get_json|safe}};
window.app.startup("animalStartup", function(app){
var endpoint = new app.Endpoint(data);
endpoint.build_details_table($('#endpoint-details-table'));
endpoint.build_endpoint_table($('#dr-tbl'));
endpoint.renderPlot($('#bmd_ds_plot'), {showBmd: true});
endpoint.build_general_notes($('#endpoint-general-notes'));
})
const data = {{object.get_json|safe}};
window.app.startup("animalStartup", function(app){
var endpoint = new app.Endpoint(data);
endpoint.build_details_table($('#endpoint-details-table'));
endpoint.build_endpoint_table($('#dr-tbl'));
endpoint.renderPlot($('#bmd_ds_plot'), {showBmd: true});
endpoint.build_general_notes($('#endpoint-general-notes'));
})
</script>
{% endblock %}
Loading
Loading