adds budget's groups & headings to admin
This commit is contained in:
15
app/controllers/admin/budget_groups_controller.rb
Normal file
15
app/controllers/admin/budget_groups_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class Admin::BudgetGroupsController < Admin::BaseController
|
||||||
|
|
||||||
|
def create
|
||||||
|
@budget = Budget.find params[:budget_id]
|
||||||
|
@budget.groups.create(budget_group_params)
|
||||||
|
@groups = @budget.groups.includes(:headings)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def budget_group_params
|
||||||
|
params.require(:budget_group).permit(:name)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
16
app/controllers/admin/budget_headings_controller.rb
Normal file
16
app/controllers/admin/budget_headings_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class Admin::BudgetHeadingsController < Admin::BaseController
|
||||||
|
|
||||||
|
def create
|
||||||
|
@budget = Budget.find params[:budget_id]
|
||||||
|
@budget_group = @budget.groups.find params[:budget_group_id]
|
||||||
|
@budget_group.headings.create(budget_heading_params)
|
||||||
|
@headings = @budget_group.headings
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def budget_heading_params
|
||||||
|
params.require(:budget_heading).permit(:name, :price, :geozone_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -9,6 +9,7 @@ class Admin::BudgetsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@budget = Budget.includes(groups: :headings).find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ module Abilities
|
|||||||
|
|
||||||
can [:read, :update, :valuate, :destroy, :summary], SpendingProposal
|
can [:read, :update, :valuate, :destroy, :summary], SpendingProposal
|
||||||
|
|
||||||
can [:read, :create, :update], Budget
|
can [:index, :read, :new, :create, :update, :destroy], Budget
|
||||||
|
can [:read, :create, :update, :destroy], Budget::Group
|
||||||
|
can [:read, :create, :update, :destroy], Budget::Heading
|
||||||
can [:hide, :update], Budget::Investment
|
can [:hide, :update], Budget::Investment
|
||||||
can :valuate, Budget::Investment, budget: { valuating: true }
|
can :valuate, Budget::Investment, budget: { valuating: true }
|
||||||
can :create, Budget::ValuatorAssignment
|
can :create, Budget::ValuatorAssignment
|
||||||
|
|||||||
2
app/views/admin/budget_groups/create.js.erb
Normal file
2
app/views/admin/budget_groups/create.js.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
$("#<%= dom_id(@budget) %>_groups").html('<%= j render("admin/budgets/groups", groups: @groups) %>');
|
||||||
|
App.Forms.toggleLink();
|
||||||
2
app/views/admin/budget_headings/create.js.erb
Normal file
2
app/views/admin/budget_headings/create.js.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
$("#<%= dom_id(@budget_group) %>").html('<%= j render("admin/budgets/group", group: @budget_group, headings: @headings) %>');
|
||||||
|
App.Forms.toggleLink();
|
||||||
76
app/views/admin/budgets/_group.html.erb
Normal file
76
app/views/admin/budgets/_group.html.erb
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<div class="small-12 column">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="3" class="with-button">
|
||||||
|
<%= group.name %>
|
||||||
|
<%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% if headings.blank? %>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">
|
||||||
|
<div class="callout primary">
|
||||||
|
<%= t("admin.budgets.form.no_heading") %>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% else %>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.budgets.form.table_heading") %></th>
|
||||||
|
<th><%= t("admin.budgets.form.table_amount") %></th>
|
||||||
|
<th><%= t("admin.budgets.form.table_geozone") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!-- new heading form -->
|
||||||
|
<tr id="group-<%= group.id %>-new-heading-form" style="display:none">
|
||||||
|
<td colspan="3">
|
||||||
|
<%= form_for [:admin, @budget, group, Budget::Heading.new], remote: true do |f| %>
|
||||||
|
<label><%= t("admin.budgets.form.heading") %></label>
|
||||||
|
<%= f.text_field :name,
|
||||||
|
label: false,
|
||||||
|
maxlength: 50,
|
||||||
|
placeholder: t("admin.budgets.form.heading") %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<label><%= t("admin.budgets.form.amount") %></label>
|
||||||
|
<%= f.text_field :price,
|
||||||
|
label: false,
|
||||||
|
maxlength: 8,
|
||||||
|
placeholder: t("admin.budgets.form.amount") %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<label><%= t("admin.budgets.form.geozone") %></label>
|
||||||
|
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- /. new heading form -->
|
||||||
|
<!-- headings list -->
|
||||||
|
<% headings.each do |heading| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= heading.name %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= heading.price %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= geozone_name_from_id heading.geozone_id %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<!-- /. headings list -->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
34
app/views/admin/budgets/_groups.html.erb
Normal file
34
app/views/admin/budgets/_groups.html.erb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<div class="small-12 column">
|
||||||
|
<h3 class="inline-block"><%= t('admin.budgets.show.groups') %></h3>
|
||||||
|
<% if groups.blank? %>
|
||||||
|
<div class="callout primary">
|
||||||
|
<%= t("admin.budgets.form.no_groups") %>
|
||||||
|
<strong><%= link_to t("admin.budgets.form.add_group"), "#",
|
||||||
|
class: "js-toggle-link",
|
||||||
|
data: { "toggle-selector" => "#new-group-form" } %></strong>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t("admin.budgets.form.add_group"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#new-group-form" } %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= form_for [:admin, @budget, Budget::Group.new], html: {id: "new-group-form", style: "display:none"}, remote: true do |f| %>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-label">
|
||||||
|
<label><%= f.label :name,t("admin.budgets.form.group") %></label>
|
||||||
|
</span>
|
||||||
|
<%= f.text_field :name,
|
||||||
|
label: false,
|
||||||
|
maxlength: 50,
|
||||||
|
placeholder: t("admin.budgets.form.group") %>
|
||||||
|
<div class="input-group-button">
|
||||||
|
<%= f.submit t("admin.budgets.form.create_group"), class: "button success" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% groups.each do |group| %>
|
||||||
|
<div class="row" id="<%= dom_id(group) %>">
|
||||||
|
<%= render "admin/budgets/group", group: group, headings: group.headings %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<%= f.select :currency_symbol, budget_currency_symbol_select_options, {label: false} %>
|
<%= f.select :currency_symbol, budget_currency_symbol_select_options, {label: false} %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" value="<%= t("admin.budgets.new.create") %>" class="button success">
|
<%= f.submit t("admin.budgets.new.create"), class: "button success" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -9,4 +9,8 @@
|
|||||||
<strong><%= t('admin.budgets.show.currency') %>:</strong> <%= @budget.currency_symbol %>
|
<strong><%= t('admin.budgets.show.currency') %>:</strong> <%= @budget.currency_symbol %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="<%= dom_id @budget %>_groups" class="row">
|
||||||
|
<%= render "groups", groups: @budget.groups %>
|
||||||
</div>
|
</div>
|
||||||
@@ -74,7 +74,13 @@ en:
|
|||||||
description: Description
|
description: Description
|
||||||
phase: Phase
|
phase: Phase
|
||||||
currency: Currency
|
currency: Currency
|
||||||
|
show:
|
||||||
|
phase: Current phase
|
||||||
|
currency: Currency
|
||||||
|
groups: Groups of budget headings
|
||||||
|
form:
|
||||||
group: Group's name
|
group: Group's name
|
||||||
|
no_groups: No groups created yet. Each user will be able to vote in only one heading per group.
|
||||||
add_group: Add new group
|
add_group: Add new group
|
||||||
create_group: Create group
|
create_group: Create group
|
||||||
heading: Heading's name
|
heading: Heading's name
|
||||||
@@ -87,9 +93,6 @@ en:
|
|||||||
table_heading: Heading
|
table_heading: Heading
|
||||||
table_amount: Amount
|
table_amount: Amount
|
||||||
table_geozone: Scope of operation
|
table_geozone: Scope of operation
|
||||||
show:
|
|
||||||
phase: Current phase
|
|
||||||
currency: Currency
|
|
||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
filter: Filter
|
filter: Filter
|
||||||
|
|||||||
@@ -74,7 +74,13 @@ es:
|
|||||||
description: Descripción
|
description: Descripción
|
||||||
phase: Fase
|
phase: Fase
|
||||||
currency: Divisa
|
currency: Divisa
|
||||||
|
show:
|
||||||
|
phase: Fase actual
|
||||||
|
currency: Divisa
|
||||||
|
groups: Grupos de partidas presupuestarias
|
||||||
|
form:
|
||||||
group: Nombre del grupo
|
group: Nombre del grupo
|
||||||
|
no_groups: No hay grupos creados todavía. Cada usuario podrá votar en una sola partida de cada grupo.
|
||||||
add_group: Añadir nuevo grupo
|
add_group: Añadir nuevo grupo
|
||||||
create_group: Crear grupo
|
create_group: Crear grupo
|
||||||
heading: Nombre de la partida
|
heading: Nombre de la partida
|
||||||
@@ -87,9 +93,6 @@ es:
|
|||||||
table_heading: Partida
|
table_heading: Partida
|
||||||
table_amount: Cantidad
|
table_amount: Cantidad
|
||||||
table_geozone: Ámbito de actuación
|
table_geozone: Ámbito de actuación
|
||||||
show:
|
|
||||||
phase: Fase actual
|
|
||||||
currency: Divisa
|
|
||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
filter: Filtro
|
filter: Filtro
|
||||||
|
|||||||
@@ -101,4 +101,58 @@ feature 'Admin budgets' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'Manage groups and headings' do
|
||||||
|
|
||||||
|
scenario 'Create group', :js do
|
||||||
|
create(:budget, name: 'Yearly participatory budget')
|
||||||
|
|
||||||
|
visit admin_budgets_path
|
||||||
|
click_link 'Yearly participatory budget'
|
||||||
|
|
||||||
|
expect(page).to have_content 'No groups created yet.'
|
||||||
|
|
||||||
|
click_link 'Add new group'
|
||||||
|
|
||||||
|
fill_in 'budget_group_name', with: 'General improvments'
|
||||||
|
click_button 'Create group'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Yearly participatory budget'
|
||||||
|
expect(page).to_not have_content 'No groups created yet.'
|
||||||
|
|
||||||
|
visit admin_budgets_path
|
||||||
|
click_link 'Yearly participatory budget'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Yearly participatory budget'
|
||||||
|
expect(page).to_not have_content 'No groups created yet.'
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Create heading', :js do
|
||||||
|
budget = create(:budget, name: 'Yearly participatory budget')
|
||||||
|
group = create(:budget_group, budget: budget, name: 'Districts improvments')
|
||||||
|
|
||||||
|
visit admin_budget_path(budget)
|
||||||
|
|
||||||
|
within("#budget_group_#{group.id}") do
|
||||||
|
expect(page).to have_content 'This group has no assigned heading.'
|
||||||
|
click_link 'Add heading'
|
||||||
|
|
||||||
|
fill_in 'budget_heading_name', with: 'District 9 reconstruction'
|
||||||
|
fill_in 'budget_heading_price', with: '6785'
|
||||||
|
click_button 'Save heading'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_content 'This group has no assigned heading.'
|
||||||
|
|
||||||
|
visit admin_budget_path(budget)
|
||||||
|
within("#budget_group_#{group.id}") do
|
||||||
|
expect(page).to_not have_content 'This group has no assigned heading.'
|
||||||
|
|
||||||
|
expect(page).to have_content 'District 9 reconstruction'
|
||||||
|
expect(page).to have_content '6785'
|
||||||
|
expect(page).to have_content 'All city'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user