Skip to content

Commit

Permalink
feat: Render metrics for areas which don't have any indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Nov 8, 2023
1 parent d6f8535 commit be852f4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
44 changes: 4 additions & 40 deletions app/views/tpi/ascor/_assessment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,10 @@
</div>

<div class="country-assessment__indicators" for="<%= dom_id(area) %>">
<% ascor_sub_indicators_for(area, indicators).each do |indicator| %>
<div class="country-assessment__indicator-block">
<div class="country-assessment__indicator">
<div class="country-assessment__indicator__title country-assessment__icon country-assessment__icon--<%= ascor_icon_for(indicator, @assessment) %>">
<%= "#{indicator.code.split('.').last}. #{indicator.text}" %>
</div>
<% if ascor_assessment_result_for(indicator, @assessment).source.present? %>
<div class="country-assessment__indicator__source">
<%= link_to 'Source', ascor_assessment_result_for(indicator, @assessment).source %>
</div>
<% end %>
</div>

<% ascor_sub_indicators_for(indicator, metrics).each do |metric| %>
<% next if metric.code == 'EP.1.a.ii' # skipped because EP.1.a.i and EP.1.a.ii are rendered via same React component %>
<div class="country-assessment__metric-block">
<% if metric.code == 'EP.1.a.i' %>
<%= render 'tpi/ascor/metrics_ep1a', recent_emissions: @recent_emissions %>
<% else %>
<div class="country-assessment__metric">
<div class="country-assessment__metric__title">
<%= "#{metric.code.split('.').last}. #{metric.text}" %>
</div>
<% if ascor_assessment_result_for(metric, @assessment).source.present? %>
<div class="country-assessment__metric__source">
<%= link_to "Source (#{ascor_assessment_result_for(metric, @assessment).year})", ascor_assessment_result_for(metric, @assessment).source %>
</div>
<% end %>
<% if ascor_assessment_result_for(metric, @assessment).answer.present? %>
<div class="country-assessment__break"></div>
<div class="country-assessment__metric__text">
<%= ascor_assessment_result_for(metric, @assessment).answer %>
</div>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<% if ascor_sub_indicators_for(area, indicators).present? %>
<%= render 'tpi/ascor/assessment_indicators', area: area, indicators: ascor_sub_indicators_for(area, indicators), metrics: metrics %>
<% else %>
<%= render 'tpi/ascor/assessment_metrics', metrics: ascor_sub_indicators_for(area, metrics) %>
<% end %>
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions app/views/tpi/ascor/_assessment_indicators.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% indicators.each do |indicator| %>
<div class="country-assessment__indicator-block">
<div class="country-assessment__indicator">
<div class="country-assessment__indicator__title country-assessment__icon country-assessment__icon--<%= ascor_icon_for(indicator, @assessment) %>">
<%= "#{indicator.code.split('.').last}. #{indicator.text}" %>
</div>
<% if ascor_assessment_result_for(indicator, @assessment).source.present? %>
<div class="country-assessment__indicator__source">
<%= link_to 'Source', ascor_assessment_result_for(indicator, @assessment).source %>
</div>
<% end %>
</div>

<%= render 'tpi/ascor/assessment_metrics', metrics: ascor_sub_indicators_for(indicator, metrics) %>
</div>
<% end %>
26 changes: 26 additions & 0 deletions app/views/tpi/ascor/_assessment_metrics.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% metrics.each do |metric| %>
<% next if metric.code == 'EP.1.a.ii' # skipped because EP.1.a.i and EP.1.a.ii are rendered via same React component %>

<div class="country-assessment__metric-block">
<% if metric.code == 'EP.1.a.i' %>
<%= render 'tpi/ascor/metrics_ep1a', recent_emissions: @recent_emissions %>
<% else %>
<div class="country-assessment__metric">
<div class="country-assessment__metric__title">
<%= "#{metric.code.split('.').last}. #{metric.text}" %>
</div>
<% if ascor_assessment_result_for(metric, @assessment).source.present? %>
<div class="country-assessment__metric__source">
<%= link_to "Source (#{ascor_assessment_result_for(metric, @assessment).year})", ascor_assessment_result_for(metric, @assessment).source %>
</div>
<% end %>
<% if ascor_assessment_result_for(metric, @assessment).answer.present? %>
<div class="country-assessment__break"></div>
<div class="country-assessment__metric__text">
<%= ascor_assessment_result_for(metric, @assessment).answer %>
</div>
<% end %>
</div>
<% end %>
</div>
<% end %>

0 comments on commit be852f4

Please sign in to comment.