From 0e06c44fb74bd2ce78b86231c74aaf6a12803e95 Mon Sep 17 00:00:00 2001 From: martintomas Date: Wed, 22 Nov 2023 13:41:28 +0100 Subject: [PATCH 1/2] feat: Enhancing project export at Backoffice --- .../backoffice/projects_controller.rb | 1 + .../backoffice/csv/open_call_exporter.rb | 6 +- .../backoffice/csv/project_exporter.rb | 44 +++++++++++-- .../views/backoffice/projects/index.html.erb | 4 +- backend/config/locales/zu.yml | 6 ++ .../backoffice/csv/open_call_exporter_spec.rb | 2 +- .../backoffice/csv/project_exporter_spec.rb | 62 ++++++++++++++++--- 7 files changed, 108 insertions(+), 17 deletions(-) diff --git a/backend/app/controllers/backoffice/projects_controller.rb b/backend/app/controllers/backoffice/projects_controller.rb index 0a87f3ce2..601e5a267 100644 --- a/backend/app/controllers/backoffice/projects_controller.rb +++ b/backend/app/controllers/backoffice/projects_controller.rb @@ -19,6 +19,7 @@ def index @pagy_object, @projects = pagy @projects, pagy_defaults end format.csv do + @projects = @projects.includes(:involved_project_developers, :country, :department, :municipality) send_data Backoffice::CSV::ProjectExporter.new(@projects).call, filename: "projects.csv", type: "text/csv; charset=utf-8" diff --git a/backend/app/services/backoffice/csv/open_call_exporter.rb b/backend/app/services/backoffice/csv/open_call_exporter.rb index 67d00529a..13cdf20de 100644 --- a/backend/app/services/backoffice/csv/open_call_exporter.rb +++ b/backend/app/services/backoffice/csv/open_call_exporter.rb @@ -9,11 +9,11 @@ def call column(I18n.t("backoffice.open_calls.index.applications")) { |r| r.open_call_applications_count } column(I18n.t("backoffice.common.status")) { |r| if r.launched? - I18n.t("enum.open_call_status.launched") + I18n.t("enums.open_call_status.launched.name") elsif r.closed? - I18n.t("enum.open_call_status.closed") + I18n.t("enums.open_call_status.closed.name") else - I18n.t("enum.open_call_status.draft") + I18n.t("enums.open_call_status.draft.name") end } column(I18n.t("backoffice.common.verification")) { |r| diff --git a/backend/app/services/backoffice/csv/project_exporter.rb b/backend/app/services/backoffice/csv/project_exporter.rb index 113e35e87..c8f597243 100644 --- a/backend/app/services/backoffice/csv/project_exporter.rb +++ b/backend/app/services/backoffice/csv/project_exporter.rb @@ -4,15 +4,51 @@ class ProjectExporter < BaseExporter def call generate_csv do column(I18n.t("backoffice.common.project_name")) { |r| r.name } - column(I18n.t("backoffice.common.project_developer")) { |r| r.project_developer.name } - column(I18n.t("backoffice.common.category")) { |r| Category.find(r.category).name } - column(I18n.t("backoffice.projects.index.priority_landscape")) { |r| r.priority_landscape&.name } column(I18n.t("backoffice.common.status")) { |r| - r.published? ? I18n.t("enum.project_status.published") : I18n.t("enum.project_status.draft") + r.published? ? I18n.t("enums.project_status.published.name") : I18n.t("enums.project_status.draft.name") } column(I18n.t("backoffice.common.verification")) { |r| r.verified? ? I18n.t("backoffice.common.verified") : I18n.t("backoffice.common.unverified") } + column(I18n.t("simple_form.labels.project.country")) { |r| r.country.name } + column(I18n.t("simple_form.labels.project.department")) { |r| r.department.name } + column(I18n.t("simple_form.labels.project.municipality")) { |r| r.municipality.name } + column(I18n.t("backoffice.projects.index.priority_landscape")) { |r| r.priority_landscape&.name } + column(I18n.t("simple_form.labels.project.project_developer")) { |r| r.project_developer.name } + column(I18n.t("simple_form.labels.project.involved_project_developers")) do |r| + r.involved_project_developers.map(&:name).join(", ") + end + column(I18n.t("simple_form.labels.project.development_stage")) do |r| + ProjectDevelopmentStage.find(r.development_stage).name + end + column(I18n.t("simple_form.labels.project.estimated_duration_in_months")) { |r| r.estimated_duration_in_months } + column(I18n.t("backoffice.common.category")) { |r| Category.find(r.category).name } + column(I18n.t("simple_form.labels.project.problem")) { |r| r.problem } + column(I18n.t("simple_form.labels.project.solution")) { |r| r.solution } + column(I18n.t("simple_form.labels.project.target_groups")) do |r| + r.target_groups.map { |tg| ProjectTargetGroup.find(tg).name }.join(", ") + end + column(I18n.t("simple_form.labels.project.expected_impact")) { |r| r.expected_impact } + column(I18n.t("backoffice.projects.export.impact_areas")) do |r| + r.impact_areas.map { |ia| ImpactArea.find(ia).name }.join(", ") + end + column(I18n.t("backoffice.projects.export.sdgs")) do |r| + r.sdgs.map { |sdg| Sdg.find(sdg).name }.join(", ") + end + column(I18n.t("backoffice.projects.export.looking_for_funding")) { |r| I18n.t(r.looking_for_funding.to_s) } + column(I18n.t("backoffice.projects.export.ticket_size")) { |r| TicketSize.find(r.ticket_size).name } + column(I18n.t("backoffice.projects.export.instrument_types")) do |r| + r.instrument_types.map { |it| InstrumentType.find(it).name }.join(", ") + end + column(I18n.t("simple_form.labels.project.funding_plan")) { |r| r.funding_plan } + column(I18n.t("simple_form.labels.project.received_funding")) { |r| I18n.t(r.received_funding) } + column(I18n.t("simple_form.labels.project.received_funding_amount_usd")) { |r| r.received_funding_amount_usd } + column(I18n.t("simple_form.labels.project.received_funding_investor")) { |r| r.received_funding_investor } + column(I18n.t("simple_form.labels.project.replicability")) { |r| r.replicability } + column(I18n.t("simple_form.labels.project.sustainability")) { |r| r.sustainability } + column(I18n.t("simple_form.labels.project.progress_impact_tracking")) { |r| r.progress_impact_tracking } + column(I18n.t("simple_form.labels.project.description")) { |r| r.description } + column(I18n.t("simple_form.labels.project.relevant_links")) { |r| r.relevant_links } end end end diff --git a/backend/app/views/backoffice/projects/index.html.erb b/backend/app/views/backoffice/projects/index.html.erb index 6fddf34cd..c04b35587 100644 --- a/backend/app/views/backoffice/projects/index.html.erb +++ b/backend/app/views/backoffice/projects/index.html.erb @@ -39,8 +39,8 @@ <%= Category.find(p.category).name %> <%= p.priority_landscape&.name %> - <%= status_tag :published, t('enum.project_status.published') if p.published? %> - <%= status_tag :draft, t('enum.project_status.draft') unless p.published? %> + <%= status_tag :published, t('enums.project_status.published.name') if p.published? %> + <%= status_tag :draft, t('enums.project_status.draft.name') unless p.published? %> <%= status_tag :verified, t('backoffice.common.verified') if p.verified? %> diff --git a/backend/config/locales/zu.yml b/backend/config/locales/zu.yml index b749752f9..1328a58da 100644 --- a/backend/config/locales/zu.yml +++ b/backend/config/locales/zu.yml @@ -275,6 +275,12 @@ zu: not_valid_kml: This .kml/.kmz file does not have a valid XML syntax. Please try to validate it and resolve the issues. not_supported: This file is not supported. Please try uploading a different format. unable_to_parse: Unable to parse the file. Please try uploading a different format. + export: + impact_areas: Impact areas + sdgs: SDGs + looking_for_funding: Project currently looking for funding? + ticket_size: Amount of money that project needs + instrument_types: Instrument types open_calls: information: Information status: Verification status diff --git a/backend/spec/services/backoffice/csv/open_call_exporter_spec.rb b/backend/spec/services/backoffice/csv/open_call_exporter_spec.rb index f2b7a5a9c..6afccbd2f 100644 --- a/backend/spec/services/backoffice/csv/open_call_exporter_spec.rb +++ b/backend/spec/services/backoffice/csv/open_call_exporter_spec.rb @@ -25,7 +25,7 @@ query.first.investor.name, [query.first.municipality&.name, query.first.department&.name, query.first.country&.name].compact.join(", "), query.first.open_call_applications_count.to_s, - I18n.t("enum.open_call_status.launched"), + I18n.t("enums.open_call_status.launched.name"), I18n.t("backoffice.common.verified") ]) end diff --git a/backend/spec/services/backoffice/csv/project_exporter_spec.rb b/backend/spec/services/backoffice/csv/project_exporter_spec.rb index a1e677792..adfd2b6fe 100644 --- a/backend/spec/services/backoffice/csv/project_exporter_spec.rb +++ b/backend/spec/services/backoffice/csv/project_exporter_spec.rb @@ -10,11 +10,35 @@ it "has correct headers at csv" do expect(parsed_csv.first).to eq([ I18n.t("backoffice.common.project_name"), - I18n.t("backoffice.common.project_developer"), - I18n.t("backoffice.common.category"), - I18n.t("backoffice.projects.index.priority_landscape"), I18n.t("backoffice.common.status"), - I18n.t("backoffice.common.verification") + I18n.t("backoffice.common.verification"), + I18n.t("simple_form.labels.project.country"), + I18n.t("simple_form.labels.project.department"), + I18n.t("simple_form.labels.project.municipality"), + I18n.t("backoffice.projects.index.priority_landscape"), + I18n.t("simple_form.labels.project.project_developer"), + I18n.t("simple_form.labels.project.involved_project_developers"), + I18n.t("simple_form.labels.project.development_stage"), + I18n.t("simple_form.labels.project.estimated_duration_in_months"), + I18n.t("backoffice.common.category"), + I18n.t("simple_form.labels.project.problem"), + I18n.t("simple_form.labels.project.solution"), + I18n.t("simple_form.labels.project.target_groups"), + I18n.t("simple_form.labels.project.expected_impact"), + I18n.t("backoffice.projects.export.impact_areas"), + I18n.t("backoffice.projects.export.sdgs"), + I18n.t("backoffice.projects.export.looking_for_funding"), + I18n.t("backoffice.projects.export.ticket_size"), + I18n.t("backoffice.projects.export.instrument_types"), + I18n.t("simple_form.labels.project.funding_plan"), + I18n.t("simple_form.labels.project.received_funding"), + I18n.t("simple_form.labels.project.received_funding_amount_usd"), + I18n.t("simple_form.labels.project.received_funding_investor"), + I18n.t("simple_form.labels.project.replicability"), + I18n.t("simple_form.labels.project.sustainability"), + I18n.t("simple_form.labels.project.progress_impact_tracking"), + I18n.t("simple_form.labels.project.description"), + I18n.t("simple_form.labels.project.relevant_links") ]) end @@ -22,11 +46,35 @@ expect(parsed_csv.size).to eq(query.count + 1) expect(parsed_csv.second).to eq([ query.first.name, + I18n.t("enums.project_status.published.name"), + I18n.t("backoffice.common.verified"), + query.first.country.name, + query.first.department.name, + query.first.municipality.name, + query.first.priority_landscape&.name, query.first.project_developer.name, + query.first.involved_project_developers.map(&:name).join(", "), + ProjectDevelopmentStage.find(query.first.development_stage).name, + query.first.estimated_duration_in_months.to_s, Category.find(query.first.category).name, - query.first.priority_landscape&.name, - I18n.t("enum.project_status.published"), - I18n.t("backoffice.common.verified") + query.first.problem, + query.first.solution, + query.first.target_groups.map { |tg| ProjectTargetGroup.find(tg).name }.join(", "), + query.first.expected_impact, + query.first.impact_areas.map { |ia| ImpactArea.find(ia).name }.join(", "), + query.first.sdgs.map { |sdg| Sdg.find(sdg).name }.join(", "), + I18n.t(query.first.looking_for_funding.to_s), + TicketSize.find(query.first.ticket_size).name, + query.first.instrument_types.map { |it| InstrumentType.find(it).name }.join(", "), + query.first.funding_plan, + I18n.t(query.first.received_funding), + query.first.received_funding_amount_usd.to_s, + query.first.received_funding_investor, + query.first.replicability, + query.first.sustainability, + query.first.progress_impact_tracking, + query.first.description, + query.first.relevant_links ]) end end From 40de28770a81c6ae1ef8c777715f4c90a062e3bc Mon Sep 17 00:00:00 2001 From: martintomas Date: Thu, 23 Nov 2023 12:33:06 +0100 Subject: [PATCH 2/2] refactoring: Adding additional project fields to Project exporter --- backend/app/services/backoffice/csv/project_exporter.rb | 6 ++++++ backend/db/seeds.rb | 5 +++++ .../spec/services/backoffice/csv/project_exporter_spec.rb | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/backend/app/services/backoffice/csv/project_exporter.rb b/backend/app/services/backoffice/csv/project_exporter.rb index c8f597243..da1578cbe 100644 --- a/backend/app/services/backoffice/csv/project_exporter.rb +++ b/backend/app/services/backoffice/csv/project_exporter.rb @@ -44,6 +44,12 @@ def call column(I18n.t("simple_form.labels.project.received_funding")) { |r| I18n.t(r.received_funding) } column(I18n.t("simple_form.labels.project.received_funding_amount_usd")) { |r| r.received_funding_amount_usd } column(I18n.t("simple_form.labels.project.received_funding_investor")) { |r| r.received_funding_investor } + column(I18n.t("simple_form.labels.project.positive_financial_returns")) { |r| r.positive_financial_returns } + column(I18n.t("simple_form.labels.project.last_year_sales_revenue")) { |r| r.last_year_sales_revenue } + column(I18n.t("simple_form.labels.project.climate_change_risks_identified")) do |r| + I18n.t(r.climate_change_risks_identified) + end + column(I18n.t("simple_form.labels.project.climate_change_risks_details")) { |r| r.climate_change_risks_details } column(I18n.t("simple_form.labels.project.replicability")) { |r| r.replicability } column(I18n.t("simple_form.labels.project.sustainability")) { |r| r.sustainability } column(I18n.t("simple_form.labels.project.progress_impact_tracking")) { |r| r.progress_impact_tracking } diff --git a/backend/db/seeds.rb b/backend/db/seeds.rb index 448775eff..68b87963e 100644 --- a/backend/db/seeds.rb +++ b/backend/db/seeds.rb @@ -8,6 +8,11 @@ Location.delete_all Admin.delete_all + Investor.reset_column_information + ProjectDeveloper.reset_column_information + OpenCall.reset_column_information + Project.reset_column_information + Admin.create!(first_name: "Admin", last_name: "Example", password: "SuperSecret1234", email: "admin@example.com", ui_language: "en") Rake::Task["import_geojsons:colombia"].invoke diff --git a/backend/spec/services/backoffice/csv/project_exporter_spec.rb b/backend/spec/services/backoffice/csv/project_exporter_spec.rb index adfd2b6fe..ed413dcfc 100644 --- a/backend/spec/services/backoffice/csv/project_exporter_spec.rb +++ b/backend/spec/services/backoffice/csv/project_exporter_spec.rb @@ -34,6 +34,10 @@ I18n.t("simple_form.labels.project.received_funding"), I18n.t("simple_form.labels.project.received_funding_amount_usd"), I18n.t("simple_form.labels.project.received_funding_investor"), + I18n.t("simple_form.labels.project.positive_financial_returns"), + I18n.t("simple_form.labels.project.last_year_sales_revenue"), + I18n.t("simple_form.labels.project.climate_change_risks_identified"), + I18n.t("simple_form.labels.project.climate_change_risks_details"), I18n.t("simple_form.labels.project.replicability"), I18n.t("simple_form.labels.project.sustainability"), I18n.t("simple_form.labels.project.progress_impact_tracking"), @@ -70,6 +74,10 @@ I18n.t(query.first.received_funding), query.first.received_funding_amount_usd.to_s, query.first.received_funding_investor, + query.first.positive_financial_returns, + query.first.last_year_sales_revenue.to_s, + I18n.t(query.first.climate_change_risks_identified), + query.first.climate_change_risks_details, query.first.replicability, query.first.sustainability, query.first.progress_impact_tracking,