Skip to content

Commit

Permalink
Fixes for #257 #244 #252 As well as various other bugs I didn't get a…
Browse files Browse the repository at this point in the history
… chance to put on the tracker.
  • Loading branch information
Elijahwalkerwest committed Mar 20, 2018
1 parent ef98359 commit 5ef6447
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ function setOtherActions() {
$('.Retrieval').find('[name="deploymentaction"]').parents('tr').addClass('form-required').show();
filterNonRetrievalFields($('.Retrieval'));
}
if (mainForm.hasClass('Instrument Deployment')) {
if ($('form').find('[name="action"]').val() !== 'update') {
var addResultButton = $("<tbody class='add-result-btn'><tr><td></td><td><a class='add-result-btn btn btn-default col-xs-12 col-sm-12' onclick='javascript:addResultForm(this)'>+ Add Result</a></td></tr></tbody>");
addResultButton.insertAfter(currentForm);
addResultForm(addResultButton, true);
}
}

$('form').find('[name="actionid"]').trigger('change');
}
Expand Down Expand Up @@ -123,9 +130,9 @@ function setFormFields(currentForm) {
function handleActionTypeChange(formType, currentForm) {
var requiredEquipmentClasses = ['Equipment maintenance', 'Equipment programming', 'Instrument retrieval',
'Instrument calibration', 'Equipment deployment', 'Instrument deployment', 'Equipment retrieval'];
var formClasses = $.map($(currentForm).find('select[name="actiontypecv"]').children(), function(option) {
var formClasses = $.map($(currentForm).find('select[name="actiontypecv"]').children(), function (option) {
return option.value;
}).reduce(function(map, actiontype) {
}).reduce(function (map, actiontype) {
map[actiontype] = actiontype.replace(' ', '');
return map;
}, {});
Expand All @@ -147,8 +154,9 @@ function handleActionTypeChange(formType, currentForm) {

// don't leave this here. or maybe do...
var methodOptions = methodSelect.find('option:not([disabled])');
var methods = $.map(methodOptions, function(option) { return option.value });

var methods = $.map(methodOptions, function (option) {
return option.value
});


if (methods.indexOf(methodSelect.val()) === -1) {
Expand Down Expand Up @@ -202,18 +210,20 @@ function handleActionTypeChange(formType, currentForm) {
equipmentSelect.select2();
}

if (formType == 'Instrument deployment') {
if ($('form').find('[name="action"]').val() !== 'update') {

if (formType !== 'Instrument deployment') {
$(currentForm).nextUntil('tbody.add-result-btn', '.results-set').remove();
$(currentForm).next('tbody.add-result-btn').remove();
}
if (formType === 'Instrument deployment') {
$(currentForm).find('[name="equipmentused"]').trigger('change');
if ($(currentForm).find('tr.form-required').first().html() !== $('form').find('tbody.action-fields tr.form-required').first().html()) {
var addResultButton = $("<tbody class='add-result-btn'><tr><td></td><td><a class='add-result-btn btn btn-default col-xs-12 col-sm-12' onclick='javascript:addResultForm(this)'>+ Add Result</a></td></tr></tbody>");
addResultButton.insertAfter(currentForm);
addResultForm(addResultButton, true);
}
} else {
$(currentForm).nextUntil('tbody.add-result-btn', '.results-set').remove();
$(currentForm).next('tbody.add-result-btn').remove();
}

if (formType == 'Instrument calibration') {
if (formType === 'Instrument calibration') {
$(currentForm).find('[name="instrumentoutputvariable"]').parents('tr').addClass('form-required');
} else {
$(currentForm).find('[name="instrumentoutputvariable"]').parents('tr').removeClass('form-required');
Expand Down Expand Up @@ -744,7 +754,9 @@ function handle_equ_used_filter_response(objects, equipmentUsedSelectElems) {

currentEquipmentSelect.children('option').each(function(index, element) {
if (equipments.indexOf(element.value) === -1) {

$(element).attr('disabled', 'disabled');
$(element).attr('hidden', true);
} else {
$(element).removeAttr('disabled');
}
Expand Down Expand Up @@ -789,16 +801,20 @@ $(document).ready(function () {
setDTPickerClose($('[name="begindatetime"]'));
setFormFields($('tbody'));
cacheUnfilteredSelects();
bindEquipmentUsedFiltering($('#id_equipmentused'));
var currentForm = $('form');
var allForms = currentForm.find('tbody').has('[name="actiontypecv"]');
for (i = 0 ; i < allForms.length ; i++){
bindEquipmentUsedFiltering($(allForms[i]).find('.select-two[name="equipmentused"]'));
}


var resultSelects = $('#results-form').find('.select-two');
if (resultSelects.length !== 0) {
$('#results-form').find('.select-two').select2('destroy');
$('#results-form').find(".select2-container").remove();
}

var currentForm = $('form');
var allForms = currentForm.find('tbody').has('[name="actiontypecv"]');

var filterEquipmentCheck = $('#id_equipment_by_site');
var siteVisitSelect = currentForm.find('[name="actionid"]');
console.log(allForms.length)
Expand Down
15 changes: 15 additions & 0 deletions src/sensordatainterface/templates/base-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ <h1 class="col-xs-12 col-sm-12 col-md-12">{{ action|capfirst }}
{% for render_form in render_forms %}
{{ render_form.as_table }}
{% endfor %}
<tbody class="action-fields">
{{ actions_form.as_table }}
</tbody>
{% if actions_form.results|length != 0 %}
{% for curr_result in actions_form.results %}
<tbody class="results-set">
{% if forloop.first %}
<tr class="results-row"><td colspan="2" class="results-label"><label>Results</label></td></tr>
{% else %}
<tr><th></th><td><a class="btn btn-remove-result btn-danger col-xs-2 col-sm-2" onclick="javascript:removeResultForm(this)">- Remove Result</a></td></tr>
{% endif %}
{{ curr_result.as_table }}
</tbody>
{% endfor %}
{% endif %}

<tbody>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<a class="btn btn-danger btn-block" id="danger-button" >Delete Action</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-3 pull-right">
<a class="btn btn-primary btn-block" href="{% url 'create_action' 'EquipmentDeployment' %}">Create New
<a class="btn btn-primary btn-block" href="{% url 'create_action' 'equipmentDeployment' %}">Create New
Deployment</a></div>
{% with retrieval=Deployment|get_deployment_retrieval %}
{% if not retrieval %}
Expand All @@ -23,7 +23,7 @@
{% endif %}
{% endwith %}
<div class="col-xs-12 col-sm-6 col-md-3 pull-right">
<a class="btn btn-primary btn-block" href="{% url 'create_action' 'EquipmentDeployment' Deployment.actionid %}">Edit Deployment Description</a></div>
<a class="btn btn-primary btn-block" href="{% url 'create_action' Deployment.actiontypecv|cut:" "|lower Deployment.actionid %}">Edit Deployment Description</a></div>
</div>

<!-- deployment details -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base-form.html" %}
{% block button_value %}{% block item_name %}
{% if action_type == 'EquipmentDeployment' %}
{% if action_type == 'EquipmentDeployment' or 'InstrumentDeployment'%}
Deployment
{% elif action_type == 'InstrumentCalibration' %}
Calibration
Expand Down
28 changes: 25 additions & 3 deletions src/sensordatainterface/views/edit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def get_forms_from_request(request, action_id=False):
calibration_reference_equipment_count = request.POST.getlist('calibrationreferenceequipmentnumber')[i - 1]

if action_type == 'Instrument deployment':
output_variable = outputvariables[i + results_counter] # get instrument output variable corresponding to the result
output_variable = outputvariables[i + results_counter] # get instrument output variable corresponding to the result
while output_variable != u'':
result = {
'instrument_output_variable': output_variable,
Expand Down Expand Up @@ -705,6 +705,12 @@ def get_forms_from_request(request, action_id=False):

if action_type != 'Generic' and not 'Instrument retrieval':
action_form[-1].fields['equipmentused'].required = True
elif action_type == 'Instrument deployment':
action_form[-1].fields['instrumentoutputvariable'].required = True
action_form[-1].fields['units'].required = True
elif action_type == 'Instrument calibration':
action_form[-1].fields['instrumentoutputvariable'].required = True


if action_id:
sampling_feature_form = FeatureActionForm(request.POST, instance=FeatureAction.objects.get(actionid=action_id))
Expand Down Expand Up @@ -1020,7 +1026,7 @@ def edit_site_visit(request, action_id):
'render_forms': [sampling_feature_form, site_visit_form, crew_form],
'mock_action_form': ActionForm(),
'mock_annotation_form': AnnotationForm(),
# 'mock_results_form': ResultsForm(),
'mock_results_form': ResultsForm(),
'actions_form': action_form,
'annotation_forms': annotation_forms,
'render_actions': render_actions,
Expand Down Expand Up @@ -1183,6 +1189,22 @@ def edit_action(request, action_type, action_id=None, visit_id=None, site_id=Non
instance=child_action,
initial={'equipmentused':[equ.equipmentid.equipmentid for equ in equipment_used]}
)
action_form.results = []

if action_type =='Instrumentdeployment':
for result in child_action.featureaction.get().result_set.all():
cur_equipment = EquipmentUsed.objects.get(actionid=child_action.actionid)
output_variable = InstrumentOutputVariable.objects.get(
variableid=result.variableid_id, modelid=cur_equipment.equipmentid.equipmentmodelid_id)

result_data = {
'instrumentoutputvariable': output_variable.instrumentoutputvariableid,
'unitsid': result.unitsid_id,
'processing_level_id': result.processinglevelid_id,
'sampledmediumcv': result.sampledmediumcv_id
}
action_form.results.append(ResultsForm(result_data))


if action_type == 'InstrumentCalibration':
action_form.initial['calibrationstandard'] = [cal_std for cal_std in ReferenceMaterial.objects.filter(calibrationstandard__actionid=action_id)]
Expand Down Expand Up @@ -1216,7 +1238,7 @@ def edit_action(request, action_type, action_id=None, visit_id=None, site_id=Non
return render(
request,
'site-visits/field-activities/other-action-form.html',
{'render_forms': [site_visit_form, action_form], 'mock_results_form': ResultsForm(), 'action': action,
{'render_forms': [site_visit_form], 'actions_form': action_form, 'mock_results_form': ResultsForm(), 'action': action,
'item_id': action_id, 'site_id': site_id,
'action_type': action_type}
)
Expand Down

0 comments on commit 5ef6447

Please sign in to comment.