From fd28f6c2b3169e68e90b28f0516183a6c3ab050b Mon Sep 17 00:00:00 2001
From: rgarcia
Date: Sun, 8 Jan 2017 11:37:02 +0100
Subject: [PATCH] adds tags to investment
---
.../budgets/investments_controller.rb | 4 +
app/helpers/tags_helper.rb | 2 +
app/models/budget/investment.rb | 2 +
app/models/tag_cloud.rb | 2 +-
.../budgets/investments/_categories.html.erb | 11 +
.../budgets/investments/_investment.html.erb | 1 +
.../investments/_investment_show.html.erb | 2 +-
.../budgets/investments/_sidebar.html.erb | 2 +
app/views/shared/_tags.html.erb | 5 +-
config/locales/activerecord.en.yml | 4 +
config/locales/budgets.en.yml | 4 +
config/locales/budgets.es.yml | 4 +
config/locales/en.yml | 1 +
config/locales/es.yml | 1 +
spec/features/budgets/ballots_spec.rb | 6 +-
spec/features/budgets/investments_spec.rb | 86 +----
spec/features/debates_spec.rb | 119 -------
spec/features/proposals_spec.rb | 142 +--------
spec/features/tags/budget_investments_spec.rb | 235 ++++++++++++++
spec/features/tags/debates_spec.rb | 218 +++++++++++++
spec/features/tags/proposals_spec.rb | 294 ++++++++++++++++++
spec/models/budget/investment_spec.rb | 17 +
spec/models/tag_cloud_spec.rb | 9 +
23 files changed, 823 insertions(+), 348 deletions(-)
create mode 100644 app/views/budgets/investments/_categories.html.erb
create mode 100644 spec/features/tags/budget_investments_spec.rb
create mode 100644 spec/features/tags/debates_spec.rb
create mode 100644 spec/features/tags/proposals_spec.rb
diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb
index 969d3689d..bf8fd7574 100644
--- a/app/controllers/budgets/investments_controller.rb
+++ b/app/controllers/budgets/investments_controller.rb
@@ -28,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
@@ -101,6 +102,9 @@ module Budgets
@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/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/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/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 @@
+
+
+
+
+
+ <% @categories.each do |category| %>
+ -
+ <%= link_to category.name,
+ budget_investments_path(@budget, search: category.name) %>
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb
index 87c2f663e..e90801f17 100644
--- a/app/views/budgets/investments/_investment.html.erb
+++ b/app/views/budgets/investments/_investment.html.erb
@@ -38,6 +38,7 @@
<%= link_to investment.description, namespaced_budget_investment_path(investment) %>
+ <%= 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 c0816d534..7917889c4 100644
--- a/app/views/budgets/investments/_investment_show.html.erb
+++ b/app/views/budgets/investments/_investment_show.html.erb
@@ -35,7 +35,7 @@
<% end %>
- <%= render 'shared/tags', taggable: @investment, url: budget_investments_path(@budget) %>
+ <%= render 'shared/tags', taggable: @investment %>
<%= safe_html_with_links investment.description.html_safe %>
diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb
index 173132257..639106934 100644
--- a/app/views/budgets/investments/_sidebar.html.erb
+++ b/app/views/budgets/investments/_sidebar.html.erb
@@ -9,6 +9,8 @@
verify: link_to(t("budget.investments.index.sidebar.verify_account"), verification_path)).html_safe %>
<% end %>
+ <%= render "shared/tag_cloud", taggable: 'budget/investment' %>
+ <%= render 'categories' %>
<% end %>
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? %>