Skip to content

Commit

Permalink
Merge branch 'refresh' of https://github.com/unepwcmc/ProtectedPlanet
Browse files Browse the repository at this point in the history
…into refresh
  • Loading branch information
stanleypliu committed Jul 18, 2020
2 parents 305fcdf + d559491 commit 7d9d3ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/region_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ def show

@governance_types = @region.protected_areas_per_governance

@designations = @presenter.designations

# For the stacked row chart percentages
@designation_percentages = @designations.map do |designation|
{ percent: designation[:percent] }
end.to_json

@sources = [
{
title: 'Source name',
Expand Down
16 changes: 16 additions & 0 deletions app/models/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ def protected_areas_per_designation(jurisdiction=nil)
""")
end

def protected_areas_per_jurisdiction
ActiveRecord::Base.connection.execute("""
SELECT jurisdictions.name, COUNT(*)
FROM jurisdictions
INNER JOIN designations ON jurisdictions.id = designations.jurisdiction_id
INNER JOIN (
SELECT protected_areas.designation_id
FROM protected_areas
INNER JOIN countries_protected_areas
ON protected_areas.id = countries_protected_areas.protected_area_id
AND countries_protected_areas.country_id IN (#{self.countries.pluck(:id).join(",")})
) AS pas_for_country ON pas_for_country.designation_id = designations.id
GROUP BY jurisdictions.name
""")
end

def countries_and_territories
countries = self.countries
all_countries_and_territories = []
Expand Down
2 changes: 1 addition & 1 deletion app/views/region/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

<%= render partial: "partials/stats/stats-sources", locals: { sources: @sources } %>

<%= render partial: "partials/stats/stats-designations", locals: { designations: @presenter.designations } %>
<%= render partial: "partials/stats/stats-designations", locals: { designations: @designations } %>

<%= render partial: "partials/cards/sites", locals: { cards: @wdpa } %>

Expand Down

0 comments on commit 7d9d3ba

Please sign in to comment.