Skip to content

Commit

Permalink
Fixes #1666 showing calculated areas with user measurement system (#1706
Browse files Browse the repository at this point in the history
)

* add filter user measurement system and display area in location datail page

* Updates to area calculation ui

* adapt to project area changes in master
  • Loading branch information
laura-barluzzi authored and amplifi committed Aug 22, 2017
1 parent ad96c19 commit 06f544f
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 20 deletions.
35 changes: 25 additions & 10 deletions cadasta/core/static/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ a > .glyphicon,
text-decoration: none;
}

.btn-sm > .glyphicon {
margin-left: 0;
margin-right: 0;
}

a:hover > .glyphicon,
.btn:hover > .glyphicon {
text-decoration: none;
Expand Down Expand Up @@ -529,6 +534,7 @@ table#select-list {
position: relative;
overflow: hidden;
padding: 10px;
min-height: 78px;
> .glyphicon {
font-size: 56px;
line-height: 70px;
Expand All @@ -549,8 +555,10 @@ table#select-list {
}
.tile-content {
span {
font-size: 14px;
font-size: 13px;
text-align: right;
display: block;
color: #fff;
opacity: .70;
-moz-opacity: .70;
.glyphicon {
Expand All @@ -559,6 +567,7 @@ table#select-list {
}
.num {
font-size: 35px;
line-height: 38px;
text-align: right;
opacity: 1;
-moz-opacity: 1;
Expand All @@ -580,7 +589,7 @@ table#select-list {
}
}

a.tile-box.btn,
a.tile-box.btn,
.tile-box-shortcut {
.tile-content-wrapper > .glyphicon {
-webkit-transition: all .2s ease-in-out;
Expand All @@ -591,7 +600,7 @@ a.tile-box.btn,
&:hover .tile-content-wrapper > .glyphicon {
opacity: .70;
-moz-opacity: .70;
}
}
}

.tile-box.bg-white { // for white backgrounds
Expand Down Expand Up @@ -648,7 +657,7 @@ a.tile-box.btn,
}
}
.overlay-wrapper.map {
padding: 15px;
padding: 15px;
position: absolute;
top: 0;
left: 0;
Expand All @@ -659,7 +668,7 @@ a.tile-box.btn,
background: rgba(255, 255, 255, 0.5);
height: 100%;
min-height: 100%;
padding: 40px 20% 0;
padding: 40px 20% 0;
margin-bottom: 0;
}
}
Expand Down Expand Up @@ -766,7 +775,7 @@ section {
}
.panel-heading {
@include clearfix;
.glyphicon-cog,
.glyphicon-cog,
.glyphicon-plus {
font-size: 18px;
margin-top: 4px;
Expand All @@ -776,14 +785,14 @@ section {
-moz-opacity: .50;
float: right;
}
a > .glyphicon-cog,
a > .glyphicon-cog,
a > .glyphicon-plus {
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
}
a:hover > .glyphicon-cog,
a:hover > .glyphicon-cog,
a:hover > .glyphicon-plus {
opacity: .90;
-moz-opacity: .90;
Expand Down Expand Up @@ -820,7 +829,7 @@ section {
}
.panel-title-bordered {
border-bottom: solid 1px $gray-light;
padding-bottom: 8px;
padding-bottom: 8px;
margin-bottom: 8px;
}
.panel-subtitle { // applied to h4
Expand Down Expand Up @@ -1030,7 +1039,7 @@ h1 .label {
font-size: 16px;
}

.entity { // small entity title above link
.entity, .area { // small entity title above link and area calculation following
font-size: 14px;
font-weight: normal;
color: $gray-medium;
Expand All @@ -1039,6 +1048,12 @@ h1 .label {
letter-spacing: 0;
}

.area { // small area
font-size: 13px;
display: inline-block;
text-transform: none;
}

.text-wrap .entity { // map popovers
font-size: 11px;
}
Expand Down
11 changes: 9 additions & 2 deletions cadasta/core/templatetags/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def set_parsley_sanitize(field):
return field


@register.filter(name='format_area_metric_units')
def set_format_area_metric_units(area):
area = float(area)
if area < 1000:
Expand All @@ -56,7 +55,6 @@ def set_format_area_metric_units(area):
return format(ha, '.2f') + ' ha'


@register.filter(name='format_area_imperial_units')
def set_format_area_imperial_units(area):
area = float(area)
area_ft2 = area * 10.764
Expand All @@ -65,3 +63,12 @@ def set_format_area_imperial_units(area):
else:
ac = area * 0.00024711
return format(ac, '.2f') + ' ac'


@register.filter(name='format_area')
def set_format_area_preferred(area, user_measurement):
"""Set preferred user format. If no preference, set metric"""
if user_measurement == 'imperial':
return set_format_area_imperial_units(area)
else:
return set_format_area_metric_units(area)
15 changes: 15 additions & 0 deletions cadasta/core/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,18 @@ def test_set_format_area_metric_units(self):
metric_units2 = filters.set_format_area_metric_units(area2)
assert metric_units1 == expected_value1
assert metric_units2 == expected_value2

def test_set_format_area_preferred(self):
area = '10004.494'
user_measurement1 = 'imperial'
user_measurement2 = 'metric'
user_measurement3 = None
expected_result1 = '2.47 ac'
expected_result2 = '1.00 ha'
expected_result3 = '1.00 ha'
result1 = filters.set_format_area_preferred(area, user_measurement1)
result2 = filters.set_format_area_preferred(area, user_measurement2)
result3 = filters.set_format_area_preferred(area, user_measurement3)
assert result1 == expected_result1
assert result2 == expected_result2
assert result3 == expected_result3
3 changes: 1 addition & 2 deletions cadasta/organization/tests/test_views_default_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ def test_get_with_overview_stats(self):
assert response.content == self.render_content(has_content=True,
num_locations=1,
num_parties=1,
num_resources=1,
total_area=642391915500)
num_resources=1)

def test_get_with_labels(self):
file = self.get_file(
Expand Down
1 change: 0 additions & 1 deletion cadasta/spatial/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def get_context_data(self, *args, **kwargs):
pass

location = context['location']
context['area'] = location.area
user = self.request.user
context['is_allowed_edit_location'] = user.has_perm('spatial.update',
location)
Expand Down
1 change: 0 additions & 1 deletion cadasta/templates/organization/project_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% load i18n %}
{% load leaflet_tags %}
{% load staticfiles %}
{% load filters %}

{% block extra_head %}
{% leaflet_css plugins="groupedlayercontrol"%}
Expand Down
7 changes: 6 additions & 1 deletion cadasta/templates/organization/project_dashboard_member.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load filters %}
{% load leaflet_tags %}

<!-- Project Dashboard for project members -->
Expand Down Expand Up @@ -54,7 +55,7 @@ <h4 class="media-heading"><a href="{% url 'organization:members' object.organiza
<hr class="border-btm">
{% blocktrans %}
<p>For additional assistance, refer to the <a href="https://docs.cadasta.org/" target="_blank">platform documentation</a> – the answer you need may be in there.</p>
{% endblocktrans %}
{% endblocktrans %}
</div>
</div>
</section>
Expand All @@ -71,6 +72,9 @@ <h4 class="media-heading"><a href="{% url 'organization:members' object.organiza
<i class="glyphicon glyphicon-map-marker"></i>
<div class="tile-content">
<span class="num">{{ num_locations }}</span>
{% if project.area %}
<span class="area">{{ project.area | format_area:user.measurement | safe }}</span>
{% endif %}
</div>
</div>
</a>
Expand Down Expand Up @@ -222,6 +226,7 @@ <h3 class="panel-title inline">{% trans "About this project" %}</h3>
{% endif %}
</div>
<div class="panel-body">

{% if is_administrator and not object.description and not object.urls.0 and not object.contacts %}
<div class="overlay-wrapper">
<div class="overlay">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load filters %}
{% load leaflet_tags %}

<!-- Project Overview for non-project members -->
Expand Down Expand Up @@ -39,7 +40,7 @@ <h3 class="panel-title panel-title-bordered">{% trans "Have an account?" %}</h3>
</div>
</div>
</section>

{% elif user.is_authenticated %}
<!-- Project restriction message -->
<div class="alert alert-info alert-full alert-dismissible" role="alert">
Expand All @@ -58,9 +59,10 @@ <h3 class="panel-title panel-title-bordered">{% trans "Have an account?" %}</h3>
<div class="tile-box bg-primary">
<div class="tile-header">{% trans "Locations" %}</div>
<div class="tile-content-wrapper">
<i class="glyphicon glyphicon-map"></i>
<i class="glyphicon glyphicon-map-marker"></i>
<div class="tile-content">
<span class="num">{{ num_locations }}</span>
{% if total_area %}<span class="area">{{ total_area | format_area:user.measurement | safe }}</span>{% endif %}
</div>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion cadasta/templates/spatial/location_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
<div class="col-md-4 detail">
<section>
<div class="page-title">
<h2 class="short"><span class="entity">{% trans "Location" %} </span>{{ location.name }}</h2>
<h2 class="short">
<span class="entity">{% trans "Location" %} </span>
{{ location.name }}
{% if location.area %}
<span class="area">{{ location.area | format_area:user.measurement | safe }} </span>
{% endif %}
</h2>
<div class="top-btn pull-right">
<!-- Action buttons -->
{% if is_allowed_edit_location %}
Expand Down

0 comments on commit 06f544f

Please sign in to comment.