diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index c26fa0a69..b47fd4e49 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -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 diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 823953084..12976de7d 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -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 diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 7d9faff34..e790312d6 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -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 diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index da7824622..36ba8d048 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -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 diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index aef3eabc4..a81308947 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -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 diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 9575e7ae7..5389825e5 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -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 diff --git a/app/models/tag_cloud.rb b/app/models/tag_cloud.rb index f3ea655f0..107ecbf1a 100644 --- a/app/models/tag_cloud.rb +++ b/app/models/tag_cloud.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index e98483772..17dd88665 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -45,7 +45,8 @@ <%= tag.name %> <% end %> - <%= 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' %> diff --git a/app/views/admin/budget_investments/show.html.erb b/app/views/admin/budget_investments/show.html.erb index 3ebfd4940..a58110c94 100644 --- a/app/views/admin/budget_investments/show.html.erb +++ b/app/views/admin/budget_investments/show.html.erb @@ -19,7 +19,7 @@

<%= t("admin.budget_investments.show.tags") %>: - <%= @investment.tags.pluck(:name).join(', ') %> + <%= @investment.tags_on(:valuation).pluck(:name).join(', ') %>

diff --git a/app/views/budgets/investments/_categories.html.erb b/app/views/budgets/investments/_categories.html.erb new file mode 100644 index 000000000..ad628b1b1 --- /dev/null +++ b/app/views/budgets/investments/_categories.html.erb @@ -0,0 +1,11 @@ +

+ +
+ + \ No newline at end of file diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 3627b398d..12f91f486 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -28,6 +28,25 @@ <%= f.text_field :organization_name %> +
+ <%= f.label :tag_list, t("budgets.investments.form.tags_label") %> +

<%= t("budgets.investments.form.tags_instructions") %>

+ +
+ <%= f.label :category_tag_list, t("budgets.investments.form.tag_category_label") %> + <% @categories.each do |tag| %> + <%= tag.name %> + <% end %> +
+ +
+ <%= f.text_field :tag_list, value: @investment.tag_list.to_s, + label: false, + placeholder: t("budgets.investments.form.tags_placeholder"), + class: 'js-tag-list' %> +
+ + <% unless current_user.manager? %>
diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index cf195e62e..c9c247784 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -38,6 +38,7 @@

<%= investment.description %>

+ <%= render "shared/tags", taggable: investment, limit: 5 %> <% end %> diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index dd1fd615f..8aae97c91 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -35,6 +35,8 @@

<% end %> + <%= render 'shared/tags', taggable: @investment %> + <%= safe_html_with_links investment.description.html_safe %> <% if investment.external_url.present? %> diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index fd395c92c..9430120bc 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -11,6 +11,11 @@ <% end %> <% end %> +<% if @budget.accepting? %> + <%= render "shared/tag_cloud", taggable: 'budget/investment' %> + <%= render 'categories' %> +<% end %> + <% if @heading && can?(:show, @ballot) %> diff --git a/app/views/shared/_tags.html.erb b/app/views/shared/_tags.html.erb index ddb6fc7f2..950b074b1 100644 --- a/app/views/shared/_tags.html.erb +++ b/app/views/shared/_tags.html.erb @@ -3,7 +3,10 @@ <% if taggable.tags.any? %>