Skip to content

Commit

Permalink
Merge pull request #784 from Vizzuality/feat/LET-1380-enhance-project…
Browse files Browse the repository at this point in the history
…-export

feat: Enhancing project export at Backoffice
  • Loading branch information
martintomas authored Nov 23, 2023
2 parents c7d6d66 + 40de287 commit 38f7ed6
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 17 deletions.
1 change: 1 addition & 0 deletions backend/app/controllers/backoffice/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions backend/app/services/backoffice/csv/open_call_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
50 changes: 46 additions & 4 deletions backend/app/services/backoffice/csv/project_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,57 @@ 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.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 }
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
Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/backoffice/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<td><%= Category.find(p.category).name %></td>
<td><%= p.priority_landscape&.name %></td>
<td>
<%= 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? %>
</td>
<td>
<%= status_tag :verified, t('backoffice.common.verified') if p.verified? %>
Expand Down
6 changes: 6 additions & 0 deletions backend/config/locales/zu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,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
Expand Down
5 changes: 5 additions & 0 deletions backend/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", ui_language: "en")

Rake::Task["import_geojsons:colombia"].invoke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 63 additions & 7 deletions backend/spec/services/backoffice/csv/project_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,79 @@
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.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"),
I18n.t("simple_form.labels.project.description"),
I18n.t("simple_form.labels.project.relevant_links")
])
end

it "has correct data at csv" do
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.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,
query.first.description,
query.first.relevant_links
])
end
end
Expand Down

0 comments on commit 38f7ed6

Please sign in to comment.