admins can tag spending proposals

This commit is contained in:
rgarcia
2016-03-07 18:09:49 +01:00
committed by kikito
parent 9b9bc25aa6
commit 951505ce7d
11 changed files with 93 additions and 5 deletions

View File

@@ -15,6 +15,20 @@ class Admin::SpendingProposalsController < Admin::BaseController
@valuators = Valuator.includes(:user).all.order("users.username ASC")
end
def edit
@spending_proposal = SpendingProposal.find(params[:id])
@tags = ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings)
end
def update
@spending_proposal = SpendingProposal.find(params[:id])
if @spending_proposal.update(spending_proposal_params)
redirect_to admin_spending_proposal_path(@spending_proposal), notice: t("flash.actions.update.spending_proposal")
else
render :edit
end
end
def assign_admin
@spending_proposal.update(params.require(:spending_proposal).permit(:administrator_id))
render nothing: true
@@ -26,4 +40,10 @@ class Admin::SpendingProposalsController < Admin::BaseController
@spending_proposal.update(params.require(:spending_proposal).permit(valuator_ids: []))
end
private
def spending_proposal_params
params.require(:spending_proposal).permit(:tag_list)
end
end

View File

@@ -1,6 +1,7 @@
class SpendingProposal < ActiveRecord::Base
include Measurable
include Sanitizable
include Taggable
apply_simple_captcha

View File

@@ -0,0 +1,24 @@
<%= form_for @spending_proposal, url: admin_spending_proposal_path(@spending_proposal) do |f| %>
<div class="small-12 column">
<%= f.label :tag_list, t("proposals.form.tags_label") %>
<p class="note"><%= t("proposals.form.tags_instructions") %></p>
<div id="category_tags" class="tags">
<%= f.label :category_tag_list, t("proposals.form.tag_category_label") %>
<% @tags.each do |tag| %>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
</div>
<br>
<%= f.text_field :tag_list, value: @spending_proposal.tag_list.to_s,
label: false,
placeholder: t("proposals.form.tags_placeholder"),
class: 'js-tag-list' %>
</div>
<div class="actions small-12 column">
<%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %>
</div>
<% end %>

View File

@@ -36,6 +36,9 @@
<% end %>
</p>
<%= render 'shared/tags', taggable: @spending_proposal %>
<p><strong><%= t("admin.spending_proposals.show.assigned_valuators") %>:</strong></p>
<div id="assigned_valuators">
<%= render "assigned_valuators" %>

View File

@@ -3,12 +3,12 @@
<% if taggable.tags.any? %>
<span id="tags" class='tags'>
<% taggable.tag_list_with_limit(limit).each do |tag| %>
<%= link_to sanitize(tag.name), send("#{taggable.class.to_s.downcase.pluralize}_path", tag: tag.name) %>
<%= link_to sanitize(tag.name), send("#{taggable.class.name.underscore.pluralize}_path", tag: tag.name) %>
<% end %>
<% if taggable.tags_count_out_of_limit(limit) > 0 %>
<%= link_to "#{taggable.tags_count_out_of_limit(limit)}+",
send("#{taggable.class.to_s.downcase}_path", taggable) %>
send("#{taggable.class.name.underscore}_path", taggable) %>
<% end %>
</span>
<% end %>

View File

@@ -186,6 +186,8 @@ en:
assign_valuators: Assign valuators
no_valuators: There is not any valuator user
assign: Assign
edit:
submit_button: Update
stats:
show:
stats_title: Stats

View File

@@ -186,6 +186,8 @@ es:
assign_valuators: Asignar evaluadores
no_valuators: No hay ningún usuario evaluador
assign: Asignar
edit:
submit_button: Actualizar
stats:
show:
stats_title: Estadísticas

View File

@@ -12,4 +12,5 @@ en:
update:
notice: "%{resource_name} updated successfully."
debate: "Debate updated successfully."
proposal: "Proposal updated successfully."
proposal: "Proposal updated successfully."
spending_proposal: "Investment project updated succesfully."

View File

@@ -12,4 +12,5 @@ es:
update:
notice: "%{resource_name} actualizado correctamente."
debate: "Debate actualizado correctamente."
proposal: "Propuesta actualizada correctamente."
proposal: "Propuesta actualizada correctamente."
spending_proposal: "Propuesta de inversión actualizada correctamente."

View File

@@ -130,7 +130,7 @@ Rails.application.routes.draw do
end
end
resources :spending_proposals, only: [:index, :show] do
resources :spending_proposals, only: [:index, :show, :edit, :update] do
member do
patch :assign_admin
patch :assign_valuators

View File

@@ -251,4 +251,38 @@ feature 'Admin spending proposals' do
end
end
scenario "Adds existing tags", :js do
create(:spending_proposal, tag_list: 'Education, Health')
spending_proposal = create(:spending_proposal)
visit edit_admin_spending_proposal_path(spending_proposal)
find('.js-add-tag-link', text: 'Education').click
click_button 'Update'
expect(page).to have_content 'Investment project updated succesfully.'
within "#tags" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario "Adds non existent tags" do
spending_proposal = create(:spending_proposal)
visit edit_admin_spending_proposal_path(spending_proposal)
fill_in 'spending_proposal_tag_list', with: 'Refugees, Solidarity'
click_button 'Update'
expect(page).to have_content 'Investment project updated succesfully.'
within "#tags" do
expect(page).to have_content 'Refugees'
expect(page).to have_content 'Solidarity'
end
end
end