Skip to content

Commit

Permalink
Merge pull request #3 from tzinckgraf/ui-fixes-for-demo-20200405
Browse files Browse the repository at this point in the history
ui-fixes-for-demo-20200405 - various UI fixes, which include
  • Loading branch information
tzinckgraf committed Apr 7, 2020
2 parents d528a27 + ff1db30 commit 23182ff
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 7 deletions.
12 changes: 9 additions & 3 deletions opentreemap/treemap/js/src/mapPage/addTreeMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ var $ = require('jquery'),
var activateMode = _.identity,
deactivateMode = _.identity,
STEP_LOCATE = 0,
STEP_DETAILS = 1,
STEP_FINAL = 2;
STEP_PHOTO = 1,
STEP_DETAILS = 2,
STEP_FINAL = 3;

function init(options) {
var $sidebar = $(options.sidebar),
$speciesTypeahead = U.$find('#add-tree-species-typeahead', $sidebar),
$summaryHead = U.$find('.summaryHead', $sidebar),
$isEmptySite = U.$find('#is-empty-site', $sidebar),
$summarySubhead = U.$find('.summarySubhead', $sidebar),
typeahead = otmTypeahead.create(options.typeahead),
clearEditControls = function() {
Expand Down Expand Up @@ -55,9 +57,13 @@ function init(options) {

function aTreeFieldIsSet() {
var data = manager.getFormData();
return _.some(data, function (value, key) {
var treeValueSet = _.some(data, function (value, key) {
return key && key.indexOf('tree') === 0 && value;
});

// either we have a tree value set, or we have not explicitly
// said this is an empty site
return treeValueSet || !$isEmptySite.is(":checked");
}

// In case we're adding another tree, make user move the marker
Expand Down
2 changes: 1 addition & 1 deletion opentreemap/treemap/js/src/mapPage/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function getSpeciesTypeaheadOptions(idPrefix) {
hidden: "#" + idPrefix + "-hidden",
reverse: "id",
forceMatch: true,
minLength: 1
minLength: 0
};
}

Expand Down
4 changes: 4 additions & 0 deletions opentreemap/treemap/templates/treemap/field/species_div.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ <h5>
<label>{% trans "Species" %}</label>
<div>
{% include "treemap/field/species_typeahead.html" %}

<input name="is_empty_site"
id="is-empty-site"
type="checkbox" /> <label for="is-empty-site">Is Empty Site</label>
</div>
<div class="alert alert-danger text-danger"
style="display: none;"
Expand Down
32 changes: 30 additions & 2 deletions opentreemap/treemap/templates/treemap/map-add-tree.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
{% load form_extras %}
{% load i18n %}

{% with nsteps=3 %}
{% with nsteps=4 %}
<div class="sidebar-inner">
<a href="javascript:;" class="close cancelBtn small hidden-xs">×</a>
<h3>{% trans "Add a Tree" %}</h3>
<div class="add-step-container" id="add-tree-container">
{% include "treemap/partials/step_set_location.html" with first=True feature_name="tree" %}

<div class="add-step">
<div class="add-step-header">
{% trans "Add tree photos" %}
<a href="javascript:;" class="close cancelBtn small visible-xs-block">×</a>
</div>
<div class="add-step-content">
<table class="table table-hover">
<tbody>
<tr>
<td>Add photo of tree shape</td>
<td><button class="btn">Upload</button></td>
</tr>
<tr>
<td>Add photo of tree leaf</td>
<td><button class="btn">Upload</button></td>
</tr>
<tr>
<td>Add photo of tree bark</td>
<td><button class="btn">Upload</button></td>
</tr>
</tbody>
</table>
</div>
{% include 'treemap/partials/step_controls.html' %}
</div>

<div class="add-step">
<div class="add-step-header">
{% trans "Add species and additional info" %}
Expand All @@ -16,12 +43,13 @@ <h3>{% trans "Add a Tree" %}</h3>
<form id="add-tree-form" onsubmit="return false;">
{# The "add-tree-species" label is used as an id prefix in "species_ul.html" #}
{% create "add-tree-species" from "Tree.species" in request.instance withtemplate "treemap/field/species_div.html" %}

{% trans "Trunk Diameter" as diameter %}
{% create diameter from "Tree.diameter" in request.instance withtemplate "treemap/field/diameter_div.html" %}

{% for group in field_groups %}
{% if group.model == "plot" %}
<h3>{% trans "Plot Information" %}</h3>
<h3>{% trans "Planting Site Information" %}</h3>
<table class="table table-hover">
<tbody>
{% for tuple in group.fields %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- Ecosystem Benefits -->
<div id="ecobenefits">
<h3>{% trans "Yearly Ecosystem Services" %}</h3>
<h3>{% trans "Annual Ecosystem Services" %}</h3>
{% if request.instance_supports_ecobenefits %}
{% include "treemap/partials/plot_eco.html" %}
{% else %}
Expand Down
18 changes: 18 additions & 0 deletions opentreemap/treemap/views/map_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ def save_and_return_errors(thing, user):
except ValidationError as e:
return package_field_errors(thing._model_name, e)

def check_if_species_is_set(request_dict):
# If we have a field that explicitly checks for empty site,
# called is_empty_site, and that is False, and either
# tree.species is empty or not set, then we have a problem
if 'is_empty_site' not in request_dict:
return

# if we don't remove it, we will get failures as OTM tries to find
# this field on the model
is_empty_site = request_dict.pop('is_empty_site')
if not is_empty_site and not request_dict.get('tree.species'):
raise ValidationError(
{'tree.species': 'Either set a species or set to an empty planting site'}
)

def skip_setting_value_on_tree(value, tree):
# If the tree is not None, we always set a value. If the tree
# is None (meaning that we would be creating a new Tree
Expand All @@ -261,6 +276,9 @@ def skip_setting_value_on_tree(value, tree):
tree = None
errors = {}

# validate species before checking any fields
check_if_species_is_set(request_dict)

rev_updates = ['universal_rev']
old_geom = feature.geom
for (identifier, value) in request_dict.iteritems():
Expand Down

0 comments on commit 23182ff

Please sign in to comment.