Merge pull request #1331 from consul/budgets-tags
Adds tags to investments
This commit is contained in:
@@ -11,8 +11,6 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
before_action :load_ballot, only: [:show, :index]
|
||||
before_action :load_investments, only: [:index, :toggle_selection]
|
||||
|
||||
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -26,6 +24,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def update
|
||||
set_valuation_tags
|
||||
if @investment.update(budget_investment_params)
|
||||
redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)),
|
||||
notice: t("flash.actions.update.budget_investment")
|
||||
@@ -52,7 +51,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
|
||||
def budget_investment_params
|
||||
params.require(:budget_investment)
|
||||
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: [])
|
||||
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, valuator_ids: [])
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@@ -72,11 +71,16 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def load_tags
|
||||
@tags = ActsAsTaggableOn::Tag.budget_investment_tags
|
||||
@tags = Budget::Investment.tags_on(:valuation).order(:name).uniq
|
||||
end
|
||||
|
||||
def load_ballot
|
||||
query = Budget::Ballot.where(user: current_user, budget: @budget)
|
||||
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
|
||||
end
|
||||
|
||||
def set_valuation_tags
|
||||
@investment.set_tag_list_on(:valuation, budget_investment_params[:valuation_tag_list])
|
||||
params[:budget_investment] = params[:budget_investment].except(:valuation_tag_list)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ module Budgets
|
||||
before_action :load_ballot, only: [:index, :show]
|
||||
before_action :load_heading, only: [:index, :show]
|
||||
before_action :set_random_seed, only: :index
|
||||
before_action :load_categories, only: [:index, :new, :create]
|
||||
|
||||
feature_flag :budgets
|
||||
|
||||
@@ -27,6 +28,7 @@ module Budgets
|
||||
@investments = @investments.apply_filters_and_search(@budget, params).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
|
||||
@investment_ids = @investments.pluck(:id)
|
||||
load_investment_votes(@investments)
|
||||
@tag_cloud = tag_cloud
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -50,6 +52,7 @@ module Budgets
|
||||
flash: { html_safe: true },
|
||||
notice: t('flash.actions.create.budget_investment', activity: activity_link)
|
||||
else
|
||||
|
||||
render :new
|
||||
end
|
||||
end
|
||||
@@ -80,7 +83,7 @@ module Budgets
|
||||
end
|
||||
|
||||
def investment_params
|
||||
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :terms_of_service, :location, :organization_name)
|
||||
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, :organization_name, :location, :terms_of_service)
|
||||
end
|
||||
|
||||
def load_ballot
|
||||
@@ -95,6 +98,13 @@ module Budgets
|
||||
end
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name)
|
||||
end
|
||||
|
||||
def tag_cloud
|
||||
TagCloud.new(Budget::Investment, params[:search])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -12,6 +12,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
end
|
||||
|
||||
def new
|
||||
load_categories
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -58,4 +59,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
@heading = @budget.headings.find(params[:heading_id]) if params[:heading_id].present?
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,6 +6,8 @@ module TagsHelper
|
||||
debates_path(search: tag_name)
|
||||
when 'proposal'
|
||||
proposals_path(search: tag_name)
|
||||
when 'budget/investment'
|
||||
budget_investments_path(@budget, search: tag_name)
|
||||
else
|
||||
'#'
|
||||
end
|
||||
|
||||
@@ -8,10 +8,10 @@ class Budget
|
||||
validates :name, presence: true
|
||||
validates :price, presence: true
|
||||
|
||||
scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
|
||||
|
||||
delegate :budget, :budget_id, to: :group, allow_nil: true
|
||||
|
||||
scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
|
||||
|
||||
def name_scoped_by_group
|
||||
"#{group.name}: #{name}"
|
||||
end
|
||||
|
||||
@@ -46,6 +46,7 @@ class Budget
|
||||
scope :undecided, -> { where(feasibility: "undecided") }
|
||||
scope :with_supports, -> { where('cached_votes_up > 0') }
|
||||
scope :selected, -> { where(selected: true) }
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
|
||||
scope :by_group, -> (group_id) { where(group_id: group_id) }
|
||||
scope :by_heading, -> (heading_id) { where(heading_id: heading_id) }
|
||||
@@ -106,6 +107,7 @@ class Budget
|
||||
{ title => 'A',
|
||||
author.username => 'B',
|
||||
heading.try(:name) => 'B',
|
||||
tag_list.join(' ') => 'B',
|
||||
description => 'C'
|
||||
}
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ class TagCloud
|
||||
end
|
||||
|
||||
def table_name
|
||||
resource_model.to_s.downcase.pluralize
|
||||
resource_model.to_s.downcase.pluralize.gsub("::", "/")
|
||||
end
|
||||
|
||||
end
|
||||
@@ -45,7 +45,8 @@
|
||||
<a class="js-add-tag-link"><%= tag.name %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= f.text_field :tag_list, value: @investment.tag_list.to_s,
|
||||
<%= f.text_field :valuation_tag_list,
|
||||
value: @investment.tag_list_on(:valuation).sort.join(','),
|
||||
label: false,
|
||||
placeholder: t("admin.budget_investments.edit.tags_placeholder"),
|
||||
class: 'js-tag-list' %>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<p id="tags">
|
||||
<strong><%= t("admin.budget_investments.show.tags") %>:</strong>
|
||||
|
||||
<%= @investment.tags.pluck(:name).join(', ') %>
|
||||
<%= @investment.tags_on(:valuation).pluck(:name).join(', ') %>
|
||||
</p>
|
||||
|
||||
<p id="assigned_valuators">
|
||||
|
||||
11
app/views/budgets/investments/_categories.html.erb
Normal file
11
app/views/budgets/investments/_categories.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2 class="sidebar-title"><%= t("shared.tags_cloud.categories") %></h2>
|
||||
<br>
|
||||
|
||||
<ul id="categories" class="no-bullet categories">
|
||||
<% @categories.each do |category| %>
|
||||
<li class="inline-block">
|
||||
<%= link_to category.name,
|
||||
budget_investments_path(@budget, search: category.name) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
@@ -28,6 +28,25 @@
|
||||
<%= f.text_field :organization_name %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :tag_list, t("budgets.investments.form.tags_label") %>
|
||||
<p class="note"><%= t("budgets.investments.form.tags_instructions") %></p>
|
||||
|
||||
<div id="category_tags" class="tags">
|
||||
<%= f.label :category_tag_list, t("budgets.investments.form.tag_category_label") %>
|
||||
<% @categories.each do |tag| %>
|
||||
<a class="js-add-tag-link"><%= tag.name %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<%= f.text_field :tag_list, value: @investment.tag_list.to_s,
|
||||
label: false,
|
||||
placeholder: t("budgets.investments.form.tags_placeholder"),
|
||||
class: 'js-tag-list' %>
|
||||
</div>
|
||||
|
||||
|
||||
<% unless current_user.manager? %>
|
||||
|
||||
<div class="small-12 column">
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<p><%= investment.description %></p>
|
||||
<div class="truncate"></div>
|
||||
</div>
|
||||
<%= render "shared/tags", taggable: investment, limit: 5 %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= render 'shared/tags', taggable: @investment %>
|
||||
|
||||
<%= safe_html_with_links investment.description.html_safe %>
|
||||
|
||||
<% if investment.external_url.present? %>
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @budget.accepting? %>
|
||||
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
|
||||
<%= render 'categories' %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<% if @heading && can?(:show, @ballot) %>
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
<% if taggable.tags.any? %>
|
||||
<ul id="tags_<%= dom_id(taggable) %>" class="no-bullet tags">
|
||||
<% taggable.tag_list_with_limit(limit).each do |tag| %>
|
||||
<li class="inline-block"><%= link_to sanitize(tag.name), send("#{taggable.class.name.underscore.pluralize}_path", search: tag.name) %></li>
|
||||
<li class="inline-block">
|
||||
<%= link_to sanitize(tag.name),
|
||||
taggable_path(taggable.class.name.underscore, tag.name),
|
||||
search: tag.name %></li>
|
||||
<% end %>
|
||||
|
||||
<% if taggable.tags_count_out_of_limit(limit) > 0 %>
|
||||
|
||||
Reference in New Issue
Block a user