Merge pull request #1635 from entantoencuanto/issue#1354-suggest_on_investments_creation

Issue#1354 suggest on investments creation
This commit is contained in:
Raimond Garcia
2017-06-12 13:09:09 +02:00
committed by GitHub
11 changed files with 91 additions and 5 deletions

View File

@@ -20,10 +20,11 @@ module Budgets
has_orders %w{most_voted newest oldest}, only: :show
has_orders ->(c) { c.instance_variable_get(:@budget).investments_orders }, only: :index
has_filters %w{not_unfeasible feasible unfeasible unselected selected}, only: [:index, :show]
has_filters %w{not_unfeasible feasible unfeasible unselected selected}, only: [:index, :show, :suggest]
invisible_captcha only: [:create, :update], honeypot: :subtitle, scope: :budget_investment
helper_method :resource_model, :resource_name
respond_to :html, :js
def index
@@ -70,8 +71,22 @@ module Budgets
end
end
def suggest
@resource_path_method = :namespaced_budget_investment_path
@resource_relation = resource_model.where(budget: @budget).apply_filters_and_search(@budget, params, @current_filter)
super
end
private
def resource_model
Budget::Investment
end
def resource_name
"budget_investment"
end
def load_investment_votes(investments)
@investment_votes = current_user ? current_user.budget_investment_votes(investments) : {}
end

View File

@@ -34,7 +34,7 @@ module CommentableActions
def suggest
@limit = 5
@resources = @search_terms.present? ? resource_model.search(@search_terms) : nil
@resources = @search_terms.present? ? resource_relation.search(@search_terms) : nil
end
def create

View File

@@ -10,6 +10,10 @@ module Polymorphic
@resource_name ||= resource_model.to_s.downcase
end
def resource_relation
@resource_relation ||= resource_model.all
end
def set_resource_instance
instance_variable_set("@#{resource_name}", @resource)
end

View File

@@ -46,6 +46,7 @@ module Abilities
can :create, SpendingProposal
can :create, Budget::Investment, budget: { phase: "accepting" }
can :suggest, Budget::Investment, budget: { phase: "accepting" }
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
can :vote, Budget::Investment, budget: { phase: "selecting" }
can [:show, :create], Budget::Ballot, budget: { phase: "balloting" }

View File

@@ -7,8 +7,9 @@
</div>
<div class="small-12 column">
<%= f.text_field :title, maxlength: SpendingProposal.title_max_length %>
<%= f.text_field :title, maxlength: SpendingProposal.title_max_length, data: { js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_budget_investments_path(@budget) }%>
</div>
<div id="js-suggest"></div>
<%= f.invisible_captcha :subtitle %>

View File

@@ -0,0 +1 @@
<%= render "shared/suggest" %>

View File

@@ -9,7 +9,7 @@
<ul>
<% @resources.limit(@limit).each do |resource| %>
<li><%= link_to resource.title, resource %></li>
<li><%= link_to resource.title, @resource_path_method.present? ? send(@resource_path_method, resource) : resource %></li>
<% end %>
</ul>