Create component to render goal stats
This commit is contained in:
14
app/components/admin/stats/sdg/goal_component.html.erb
Normal file
14
app/components/admin/stats/sdg/goal_component.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<div class="sdg-goal-stats">
|
||||
|
||||
<h3><%= goal.code_and_title %></h3>
|
||||
|
||||
<div class="stats-numbers">
|
||||
<% stats.each do |text, amount, options = {}| %>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= tag.p(options) do %>
|
||||
<%= text %> <br><span class="number"><%= amount %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
30
app/components/admin/stats/sdg/goal_component.rb
Normal file
30
app/components/admin/stats/sdg/goal_component.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class Admin::Stats::SDG::GoalComponent < ApplicationComponent
|
||||
with_collection_parameter :goal
|
||||
|
||||
attr_reader :goal
|
||||
|
||||
def initialize(goal:)
|
||||
@goal = goal
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stats
|
||||
[
|
||||
[t("admin.stats.sdg.polls"), goal.polls.count],
|
||||
[t("admin.stats.sdg.proposals"), goal.proposals.count],
|
||||
[t("admin.stats.sdg.debates"), goal.debates.count],
|
||||
[t("admin.stats.sdg.budget_investments.sent"), goal.budget_investments.count],
|
||||
[t("admin.stats.sdg.budget_investments.winners"), goal.budget_investments.winners.count, featured],
|
||||
[t("admin.stats.sdg.budget_investments.amount"), amount, featured]
|
||||
]
|
||||
end
|
||||
|
||||
def amount
|
||||
number_to_currency(goal.budget_investments.winners.sum(:price), precision: 0)
|
||||
end
|
||||
|
||||
def featured
|
||||
{ class: "featured" }
|
||||
end
|
||||
end
|
||||
@@ -1415,6 +1415,14 @@ en:
|
||||
question_name: Question
|
||||
origin_web: Web participants
|
||||
origin_total: Total participants
|
||||
sdg:
|
||||
budget_investments:
|
||||
amount: "Approved amount"
|
||||
winners: "Winner investment projects"
|
||||
sent: "Investment projects sent"
|
||||
debates: "Debates"
|
||||
polls: "Polls"
|
||||
proposals: "Proposals"
|
||||
tags:
|
||||
create: Create topic
|
||||
destroy: Delete topic
|
||||
|
||||
@@ -1414,6 +1414,14 @@ es:
|
||||
question_name: Pregunta
|
||||
origin_web: Participantes en Web
|
||||
origin_total: Participantes Totales
|
||||
sdg:
|
||||
budget_investments:
|
||||
amount: "Presupuesto aprobado"
|
||||
winners: "Proyectos de inversión ganadores"
|
||||
sent: "Proyectos de inversión enviados"
|
||||
debates: "Debates"
|
||||
polls: "Votaciones"
|
||||
proposals: "Propuestas"
|
||||
tags:
|
||||
create: Crear tema
|
||||
destroy: Eliminar tema
|
||||
|
||||
23
spec/components/admin/stats/sdg/goal_component_spec.rb
Normal file
23
spec/components/admin/stats/sdg/goal_component_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::Stats::SDG::GoalComponent, type: :component do
|
||||
let(:component) { Admin::Stats::SDG::GoalComponent.new(goal: goal) }
|
||||
let(:goal) { SDG::Goal.sample }
|
||||
|
||||
it "shows goal stats" do
|
||||
create_list(:poll, 2, sdg_goals: [goal])
|
||||
create_list(:proposal, 3, sdg_goals: [goal])
|
||||
create_list(:debate, 1, sdg_goals: [goal])
|
||||
create_list(:budget_investment, 2, :winner, sdg_goals: [goal], price: 1000)
|
||||
create_list(:budget_investment, 2, sdg_goals: [goal], price: 1000)
|
||||
|
||||
render_inline component
|
||||
|
||||
expect(page).to have_text "Proposals 3"
|
||||
expect(page).to have_text "Polls 2"
|
||||
expect(page).to have_text "Debates 1"
|
||||
expect(page).to have_text "Investment projects sent 4"
|
||||
expect(page).to have_text "Winner investment projects 2"
|
||||
expect(page).to have_text "Approved amount $2,000"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user