diff --git a/app/components/admin/stats/sdg_component.html.erb b/app/components/admin/stats/sdg_component.html.erb new file mode 100644 index 000000000..754380b4b --- /dev/null +++ b/app/components/admin/stats/sdg_component.html.erb @@ -0,0 +1,5 @@ +<%= back_link_to %> + +<%= header %> + +<%= render Admin::Stats::SDG::GoalComponent.with_collection(goals) %> diff --git a/app/components/admin/stats/sdg_component.rb b/app/components/admin/stats/sdg_component.rb new file mode 100644 index 000000000..9e0f3a23a --- /dev/null +++ b/app/components/admin/stats/sdg_component.rb @@ -0,0 +1,15 @@ +class Admin::Stats::SDGComponent < ApplicationComponent + include Header + + attr_reader :goals + + def initialize(goals) + @goals = goals + end + + private + + def title + t("admin.stats.sdg.title") + end +end diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 14a32c17e..577d90398 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -90,6 +90,10 @@ class Admin::StatsController < Admin::BaseController @participants = ::Poll::Voter.where(poll: @polls) end + def sdg + @goals = SDG::Goal.order(:code) + end + private def voters_in_heading(heading) diff --git a/app/views/admin/stats/sdg.html.erb b/app/views/admin/stats/sdg.html.erb new file mode 100644 index 000000000..52efe8cf4 --- /dev/null +++ b/app/views/admin/stats/sdg.html.erb @@ -0,0 +1 @@ +<%= render Admin::Stats::SDGComponent.new(@goals) %> diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 4f754fcb0..8a633637c 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -14,6 +14,8 @@ proposal_notifications_admin_stats_path, class: "button hollow" %> <%= link_to t("admin.stats.show.incomplete_verifications"), admin_verifications_path, class: "button hollow" %> + <%= link_to t("admin.stats.show.sdg"), + sdg_admin_stats_path, class: "button hollow" if feature?(:sdg) %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 4f1bd3c8b..27e289370 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1373,6 +1373,7 @@ en: proposal_notifications: Proposal notifications incomplete_verifications: Incomplete verifications polls: Polls + sdg: SDG graph: debate_created: Debates visit: Visits @@ -1423,6 +1424,7 @@ en: debates: "Debates" polls: "Polls" proposals: "Proposals" + title: "Sustainable Development Goals - Stats" tags: create: Create topic destroy: Delete topic diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b599face9..9cb6d311a 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1372,6 +1372,7 @@ es: proposal_notifications: Notificaciones de propuestas incomplete_verifications: Verificaciones incompletas polls: Votaciones + sdg: ODS graph: debate_created: Debates visit: Visitas @@ -1422,6 +1423,7 @@ es: debates: "Debates" polls: "Votaciones" proposals: "Propuestas" + title: "Objetivos de Desarrollo Sostenible - Estadísticas" tags: create: Crear tema destroy: Eliminar tema diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 197707c97..13fdc5935 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -204,6 +204,7 @@ namespace :admin do get :proposal_notifications, on: :collection get :direct_messages, on: :collection get :polls, on: :collection + get :sdg, on: :collection end namespace :legislation do diff --git a/spec/system/admin/stats_spec.rb b/spec/system/admin/stats_spec.rb index 6b68023f4..9e890b005 100644 --- a/spec/system/admin/stats_spec.rb +++ b/spec/system/admin/stats_spec.rb @@ -395,4 +395,29 @@ describe "Stats", :admin do end end end + + context "SDG", :js do + scenario "Shows SDG stats link when SDG feature is enabled" do + Setting["feature.sdg"] = true + + visit admin_stats_path + + expect(page).to have_link "SDG", href: sdg_admin_stats_path + end + + scenario "Does not show SDG stats link when SDG feature is disbled" do + Setting["feature.sdg"] = false + + visit admin_stats_path + + expect(page).not_to have_link "SDG" + end + + scenario "Renders all goals stats" do + visit sdg_admin_stats_path + + expect(page).to have_css "h3", count: SDG::Goal.count + expect(page).to have_css ".sdg-goal-stats", count: SDG::Goal.count + end + end end