added csv download link to budget_investments (issue 1625)
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
|
||||
require 'csv'
|
||||
|
||||
include FeatureFlags
|
||||
feature_flag :budgets
|
||||
|
||||
@@ -12,6 +15,12 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
before_action :load_investments, only: [:index, :toggle_selection]
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.csv do
|
||||
send_data set_csv, filename: 'budget_investments.csv'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -43,6 +52,41 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
|
||||
private
|
||||
|
||||
def set_csv
|
||||
attributes = [t("admin.budget_investments.index.table_id"),
|
||||
t("admin.budget_investments.index.table_title"),
|
||||
t("admin.budget_investments.index.table_supports"),
|
||||
t("admin.budget_investments.index.table_admin"),
|
||||
t("admin.budget_investments.index.table_valuator"),
|
||||
t("admin.budget_investments.index.table_geozone"),
|
||||
t("admin.budget_investments.index.table_feasibility"),
|
||||
t("admin.budget_investments.index.table_valuation_finished"),
|
||||
t("admin.budget_investments.index.table_selection")]
|
||||
csv_string = CSV.generate(headers: true) do |csv|
|
||||
csv << attributes
|
||||
@investments.each do |investment|
|
||||
id = investment.id.to_s
|
||||
title = investment.title
|
||||
total_votes = investment.total_votes.to_s
|
||||
if investment.administrator.present?
|
||||
administrator = investment.administrator.name
|
||||
else
|
||||
administrator = t("admin.budget_investments.index.no_admin_assigned")
|
||||
end
|
||||
if investment.valuators.empty?
|
||||
valuators = t("admin.budget_investments.index.no_valuators_assigned")
|
||||
else
|
||||
valuators = investment.valuators.collect(&:description_or_name).join(', ')
|
||||
end
|
||||
heading_name = investment.heading.name
|
||||
price = t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.formatted_price)
|
||||
valuation_finished = investment.valuation_finished? ? t('shared.yes') : t('shared.no')
|
||||
csv << [id, title, total_votes, administrator, valuators, heading_name, price, valuation_finished]
|
||||
end
|
||||
end
|
||||
csv_string
|
||||
end
|
||||
|
||||
def load_investments
|
||||
@investments = Budget::Investment.scoped_filter(params, @current_filter)
|
||||
.order(cached_votes_up: :desc, created_at: :desc)
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
module BudgetsHelper
|
||||
|
||||
def csv_params
|
||||
csv_params = params.clone.merge(format: :csv)
|
||||
csv_params.delete(:page)
|
||||
csv_params
|
||||
end
|
||||
|
||||
def investment_selected_link_options(investment)
|
||||
if investment.selected?
|
||||
{link_class: "button small expanded",
|
||||
text: t("admin.budget_investments.index.selected") }
|
||||
elsif investment.feasible? && investment.valuation_finished?
|
||||
{link_class: "button small hollow expanded",
|
||||
text: t("admin.budget_investments.index.select")}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def budget_phases_select_options
|
||||
Budget::PHASES.map { |ph| [ t("budgets.phase.#{ph}"), ph ] }
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<h3><%= page_entries_info @investments %></h3>
|
||||
<div class='relative'>
|
||||
<%= link_to 'download current selecction',admin_budget_budget_investments_path(csv_params), class: 'advanced-search small' %>
|
||||
<h3><%= page_entries_info @investments %></h3>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
@@ -55,24 +58,9 @@
|
||||
<%= investment.valuation_finished? ? t('shared.yes'): t('shared.no') %>
|
||||
</td>
|
||||
<td class="small">
|
||||
<% if investment.selected? %>
|
||||
<%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.selected"),
|
||||
toggle_selection_admin_budget_budget_investment_path(@budget,
|
||||
investment,
|
||||
filter: params[:filter],
|
||||
page: params[:page]),
|
||||
method: :patch,
|
||||
remote: true,
|
||||
class: "button small expanded" %>
|
||||
<% elsif investment.feasible? && investment.valuation_finished? %>
|
||||
<%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.select"),
|
||||
toggle_selection_admin_budget_budget_investment_path(@budget,
|
||||
investment,
|
||||
filter: params[:filter],
|
||||
page: params[:page]),
|
||||
method: :patch,
|
||||
remote: true,
|
||||
class: "button small hollow expanded" %>
|
||||
<%= options = investment_selected_link_options(investment) %>
|
||||
<%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, investment, filter: params[:filter], page: params[:page]), method: :patch, remote: true, class: options[:link_class] do %>
|
||||
<%= options[:text] %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% if params[:filter] == 'selected' %>
|
||||
|
||||
Reference in New Issue
Block a user