Skip to content

Commit

Permalink
feat: add number_of_national_desinitions to tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
yuelongh committed Dec 20, 2023
1 parent 9f9467e commit eea49c8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
&--content {
@include flex;
@include flex-column;
gap: 0.75rem;
gap: 1.5rem;
color: black;
font-weight: normal;
width: 16rem;
Expand Down
33 changes: 19 additions & 14 deletions app/controllers/country_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
require 'enumerator'

class CountryController < ApplicationController
after_action :enable_caching
Expand All @@ -12,13 +11,13 @@ class CountryController < ApplicationController
TABS_KEYS = %i[coverage message iucn governance sources designations growth sites].freeze

def show
# Components above tabs
@download_options = helpers.download_options(['csv', 'shp', 'gdb', 'pdf'], 'general', @country.iso_3)
# Components above tabs
@download_options = helpers.download_options(%w[csv shp gdb pdf], 'general', @country.iso_3)

@flag_path = flag_path(@country.name)

# exclude transboundary PAs where the PAME evaluation is associated only with another country
@total_pame = @country.protected_areas.with_pame_evaluations.includes(pame_evaluations: :countries).where(pame_evaluations: {countries: {id: @country.id}}).count
@total_pame = @country.protected_areas.with_pame_evaluations.includes(pame_evaluations: :countries).where(pame_evaluations: { countries: { id: @country.id } }).count
@total_wdpa = @country.protected_areas.wdpas.count

@map = {
Expand Down Expand Up @@ -47,11 +46,12 @@ def show

def build_stats
@tabs = [{ id: 'wdpa', title: I18n.t('global.area-types.wdpa') }]
@stats_data = build_standard_hash
@stats_data = build_hash(:wdpa)
@number_of_national_desinitions = get_number_of_national_desinitions

if has_oecms
@stats_data.merge!(build_oecm_hash)
@tabs.push({ id: 'wdpa_oecm', title: I18n.t('global.area-types.wdpa_oecm') })
@tabs.push({ id: 'wdpa_oecm', title: I18n.t('global.area-types.wdpa_oecm') })
end
end

Expand All @@ -65,6 +65,17 @@ def protected_areas

private

def get_number_of_national_desinitions
number_of_national_desinitions = 0
designations_list = @stats_data[:wdpa][:designations][:designations]
designations_list.each do |designation|

total = designation[:total]
number_of_national_desinitions = total if designation[:type] == 'National' && total.is_a?(Integer)
end
number_of_national_desinitions
end

def has_oecms
@total_oecm = @country.protected_areas.oecms.count
@total_oecm.positive?
Expand All @@ -76,22 +87,18 @@ def build_hash(tab)
# What this does is call the corresponding method in tab presenter to build
# the value for each key, populating the hash
hash[tab] = TABS_KEYS.map do |key|
{ "#{key}": @tab_presenter.send("#{key}", oecms_tab: tab == :wdpa_oecm) }
{ "#{key}": @tab_presenter.send(key.to_s, oecms_tab: tab == :wdpa_oecm) }
end.reduce(&:merge)

hash
end

def build_standard_hash
build_hash(:wdpa)
end

def build_oecm_hash
build_hash(:wdpa_oecm)
end

def map_overlays
overlays(['oecm', 'marine_wdpa', 'terrestrial_wdpa'])
overlays(%w[oecm marine_wdpa terrestrial_wdpa])
end

def load_essential_vars
Expand All @@ -103,8 +110,6 @@ def load_essential_vars
@tab_presenter = TabPresenter.new(@country)
end

private

def flag_path(country_name)
character_replacements = {
' ' => '-',
Expand Down
11 changes: 3 additions & 8 deletions app/views/country/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
download_options: @download_options,
download_disabled: @total_wdpa == 0
} %>

<div class="page--country bg--grey-xlight spacer-small--top">
<div class="container">

<% if country_has_restricted_data %>
<section class="spacer-small--bottom">
<%= render partial: "partials/messages/message-country-restricted", locals: {
message: get_restricted_message
} %>
</section>
<% end %>

<section class="page__section--overview-map">
<%= render partial: "partials/stats/stats-overview", locals: {
flag: @flag_path,
Expand All @@ -23,16 +20,15 @@
total_oecm: @total_oecm,
total_pame: @total_pame,
total_wdpa: @total_wdpa,
number_of_national_desinitions: @number_of_national_desinitions
} %>

<div class="page__map map--country">
<%= render partial: "partials/maps/header", locals: {
map: @map,
map_options: @map_options
} %>
</div>
</section>

<section>
<region-country-pages
:data="<%= @stats_data.to_json %>"
Expand All @@ -48,10 +44,9 @@
<% end %>
</template>
</region-country-pages>
</section>

</section>
<section class="spacer-small--bottom">
<%= render partial: "partials/messages/message-citation", locals: { title: @country.name } %>
</section>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/partials/stats/_stats-overview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<span class="card__tooltip--designations">
<span><%= t('stats.tooltip.designations') %></span>
<span>=</span>
<span>xx</span>
<span><%= local_assigns[:number_of_national_desinitions] %></span>
</span>
</div>
</template>
Expand Down Expand Up @@ -111,7 +111,7 @@
<span class="card__tooltip--designations">
<span><%= t('stats.tooltip.designations') %></span>
<span>=</span>
<span>xx</span>
<span><%= local_assigns[:number_of_national_desinitions] %></span>
</span>
</div>
</template>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/stats/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ en:
arabic_version: Arabic Version
tooltip:
title: Other effective area-based conservation measures
description: Some geographic locations are designated more than once, e.g., as both a Watershed Management Area (a national designation) and a World Heritage Site (an international designation). In the WD-OECM, these designations are counted as separate OECMs, meaning this number might appear higher than expected. Number of national.
designations: designations
description: Some geographic locations are designated more than once, e.g., as both a Watershed Management Area (a national designation) and a World Heritage Site (an international designation). In the WD-OECM, these designations are counted as separate OECMs, meaning this number might appear higher than expected.
designations: Number of national designations

0 comments on commit eea49c8

Please sign in to comment.