started working on budget manatement
This commit is contained in:
@@ -275,6 +275,7 @@
|
||||
|
||||
.debate-new, .debate-edit,
|
||||
.proposal-new, .proposal-edit,
|
||||
.budget-proposal-new, .budget-proposal-edit,
|
||||
.spending-proposal-new, .spending-proposal-edit {
|
||||
|
||||
.icon-debates {
|
||||
|
||||
78
app/controllers/management/budget_investments_controller.rb
Normal file
78
app/controllers/management/budget_investments_controller.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
class Management::BudgetInvestmentsController < Management::BaseController
|
||||
|
||||
before_action :only_verified_users, except: :print
|
||||
before_action :set_budget_investment, only: [:vote, :show]
|
||||
|
||||
def index
|
||||
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
|
||||
set_budget_investment_votes(@budget_investments)
|
||||
end
|
||||
|
||||
def new
|
||||
@investment = Budget::Investment.new
|
||||
end
|
||||
|
||||
def create
|
||||
@budget_investment = Budget::Investment.new(budget_investment_params)
|
||||
@budget_investment.author = managed_user
|
||||
|
||||
if @budget_investment.save
|
||||
redirect_to management_budget_investment_path(@budget_investment), notice: t('flash.actions.create.notice', resource_name: t("activerecord.models.budget_investment", count: 1))
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
set_budget_investment_votes(@budget_investment)
|
||||
end
|
||||
|
||||
def vote
|
||||
@budget_investment.register_vote(managed_user, 'yes')
|
||||
set_budget_investment_votes(@budget_investment)
|
||||
end
|
||||
|
||||
def print
|
||||
params[:geozone] ||= 'all'
|
||||
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15)
|
||||
set_budget_investment_votes(@budget_investments)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_budget_investment
|
||||
@budget_investment = Budget::Investment.find(params[:id])
|
||||
end
|
||||
|
||||
def budget_investment_params
|
||||
params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :terms_of_service)
|
||||
end
|
||||
|
||||
def only_verified_users
|
||||
check_verified_user t("management.budget_investments.alert.unverified_user")
|
||||
end
|
||||
|
||||
# This should not be necessary. Maybe we could create a specific show view for managers.
|
||||
def set_budget_investment_votes(budget_investments)
|
||||
@budget_investment_votes = managed_user ? managed_user.budget_investment_votes(budget_investments) : {}
|
||||
end
|
||||
|
||||
def set_geozone_name
|
||||
if params[:geozone] == 'all'
|
||||
@geozone_name = t('geozones.none')
|
||||
else
|
||||
@geozone_name = Geozone.find(params[:geozone]).name
|
||||
end
|
||||
end
|
||||
|
||||
def apply_filters_and_search(target)
|
||||
target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible
|
||||
if params[:geozone].present?
|
||||
target = target.by_geozone(params[:geozone])
|
||||
set_geozone_name
|
||||
end
|
||||
target = target.search(params[:search]) if params[:search].present?
|
||||
target
|
||||
end
|
||||
|
||||
end
|
||||
10
app/views/admin/shared/_budget_investment_search.html.erb
Normal file
10
app/views/admin/shared/_budget_investment_search.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<%= form_for(Budget::Investment.new, url: url, as: :budget_investment, method: :get) do |f| %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :search, "", placeholder: t("admin.shared.budget_investment_search.placeholder") %>
|
||||
</div>
|
||||
<div class="form-inline small-12 medium-3 column end">
|
||||
<%= f.submit t("admin.shared.budget_investment_search.button"), class: "button" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -44,6 +44,20 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "budget_investments" and action_name == "new" %>>
|
||||
<%= link_to new_management_budget_investment_path do %>
|
||||
<span class="icon-budget"></span>
|
||||
<%= t("management.menu.create_budget_investment") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "budget_investments" and action_name == "index" %>>
|
||||
<%= link_to management_budget_investments_path do %>
|
||||
<span class="icon-like"></span>
|
||||
<%= t("management.menu.support_budget_investments") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "proposals" and action_name == "print" %>>
|
||||
<%= link_to print_management_proposals_path do %>
|
||||
<span class="icon-print"></span>
|
||||
@@ -58,6 +72,14 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "budget_investments" and action_name == "print" %>>
|
||||
<%= link_to print_management_budget_investments_path do %>
|
||||
<span class="icon-print"></span>
|
||||
<%= t("management.menu.print_budget_investments") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<%= link_to new_management_user_invite_path do %>
|
||||
<span class="icon-letter"></span>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%= render partial: 'budgets/investments/investment', locals: {investment: budget_investment} %>
|
||||
2
app/views/management/budget_investments/_votes.html.erb
Normal file
2
app/views/management/budget_investments/_votes.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= render 'budgets/investments/votes',
|
||||
{ investment: budget_investment, vote_url: vote_management_budget_investment_path(budget_investment.budget, budget_investment, value: 'yes') } %>
|
||||
25
app/views/management/budget_investments/index.html.erb
Normal file
25
app/views/management/budget_investments/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<main>
|
||||
<span class="not-print">
|
||||
<%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path %>
|
||||
</span>
|
||||
|
||||
<div class="wrap row">
|
||||
<div id="investment-projects" class="investment-projects-list small-12 medium-9 column">
|
||||
|
||||
|
||||
<div class="small-12 search-results">
|
||||
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible")) if params[:unfeasible].present? %>
|
||||
<%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %>
|
||||
<% if params[:search].present? %>
|
||||
<h2>
|
||||
<%= page_entries_info @budget_investments %>
|
||||
<%= t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]) %>
|
||||
</h2>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= render @budget_investments %>
|
||||
<%= paginate @budget_investments %>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
12
app/views/management/budget_investments/new.html.erb
Normal file
12
app/views/management/budget_investments/new.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class="budget-investment-new">
|
||||
|
||||
<div class="clear float-right">
|
||||
<%= render '/shared/print' %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-9 column end">
|
||||
<h1 class=""><%= t("management.budget_investments.create") %></h1>
|
||||
<%= render "budgets/investments/form", form_url: management_budget_investments_url %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
34
app/views/management/budget_investments/print.html.erb
Normal file
34
app/views/management/budget_investments/print.html.erb
Normal file
@@ -0,0 +1,34 @@
|
||||
<main>
|
||||
<div class="row">
|
||||
<div id="investment-projects" class="investment-projects-list small-12 column">
|
||||
|
||||
<div class="not-print">
|
||||
<%= form_tag print_management_budget_investments_path, method: :get, enforce_utf8: false do %>
|
||||
<div class="small-12 medium-4 column float-left">
|
||||
<%= select_tag :geozone,
|
||||
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]),
|
||||
{ label: false,
|
||||
class: "js-submit-on-change" } %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<a id="print_link" href="javascript:window.print();" class="button warning float-right">
|
||||
<%= t('management.budget_investments.print.print_button') %>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="small-12 search-results">
|
||||
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible"), class: "inline-block") if params[:unfeasible].present? %>
|
||||
<%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name), class: "inline-block") if @geozone_name.present? %>
|
||||
<%= content_tag(:h2, t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]), class: "inline-block") if params[:search].present? %>
|
||||
</div>
|
||||
|
||||
<%= render @budget_investments %>
|
||||
|
||||
<div class="for-print-only">
|
||||
<p><strong><%= t("management.print.budget_investments_info") %></strong><br>
|
||||
<%= t("management.print.budget_investments_note") %></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
3
app/views/management/budget_investments/show.html.erb
Normal file
3
app/views/management/budget_investments/show.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= render '/shared/print' %>
|
||||
|
||||
<%= render template: 'budgets/investments/show' %>
|
||||
1
app/views/management/budget_investments/vote.js.erb
Normal file
1
app/views/management/budget_investments/vote.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render template: 'budgets/investments/vote' %>
|
||||
Reference in New Issue
Block a user