diff --git a/app/assets/stylesheets/print.css b/app/assets/stylesheets/print.css
index ef76f607e..5297826c8 100644
--- a/app/assets/stylesheets/print.css
+++ b/app/assets/stylesheets/print.css
@@ -28,6 +28,8 @@ img.left { display: none !important; }
li.name { display: none !important; }
+li.kind { display: none !important; }
+
p.proposal-info span:nth-child(3) { display: none !important; }
.top-links { display: none !important; }
diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb
index 5655b0f8a..e3530876d 100644
--- a/app/controllers/admin/tags_controller.rb
+++ b/app/controllers/admin/tags_controller.rb
@@ -4,13 +4,23 @@ class Admin::TagsController < Admin::BaseController
respond_to :html, :js
def index
- @tags = ActsAsTaggableOn::Tag.order(featured: :desc).page(params[:page])
+ @tags = ActsAsTaggableOn::Tag.order(kind: :asc, id: :asc).page(params[:page])
@tag = ActsAsTaggableOn::Tag.new
end
def create
- ActsAsTaggableOn::Tag.create(tag_params)
- redirect_to admin_tags_path
+ @paramTag = params[:tag]
+ if @paramTag[:name] == ""
+ redirect_to admin_tags_path, notice: t("admin.tags.message")
+ else
+ search_tag
+ if @tag.present?
+ redirect_to admin_tags_path, notice: t("admin.tags.message_find")
+ else
+ ActsAsTaggableOn::Tag.create(tag_params)
+ redirect_to admin_tags_path
+ end
+ end
end
def update
@@ -26,11 +36,16 @@ class Admin::TagsController < Admin::BaseController
private
def tag_params
- params.require(:tag).permit(:featured, :name)
+ params.require(:tag).permit(:featured, :name, :kind)
end
def find_tag
@tag = ActsAsTaggableOn::Tag.find(params[:id])
end
-
+ def search_tag
+ # @tag = ActsAsTaggableOn::Tag.where("name = '#{@paramTag[:name]}' and
+ # kind = '#{@paramTag[:kind]}'")
+
+ @tag = ActsAsTaggableOn::Tag.where("upper(name) = upper('#{@paramTag[:name]}')")
+ end
end
diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb
index fef6ab554..42a7396de 100644
--- a/app/controllers/concerns/commentable_actions.rb
+++ b/app/controllers/concerns/commentable_actions.rb
@@ -27,6 +27,8 @@ module CommentableActions
@resource = resource_model.new
set_resource_instance
load_featured_tags
+ load_category_tags
+ load_district_select
end
def create
@@ -34,18 +36,24 @@ module CommentableActions
@resource.author = current_user
if @resource.save_with_captcha
- track_event
+ track_event
+ load_category_tags
+ load_district_select
redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id)
redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}")
else
load_featured_tags
+ load_category_tags
+ load_district_select
set_resource_instance
render :new
end
end
def edit
- load_featured_tags
+ load_featured_tags
+ load_category_tags
+ load_district_select
end
def update
@@ -53,7 +61,9 @@ module CommentableActions
if resource.save_with_captcha
redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}")
else
- load_featured_tags
+ load_featured_tags
+ load_category_tags
+ load_district_select
set_resource_instance
render :edit
end
@@ -72,6 +82,15 @@ module CommentableActions
def load_featured_tags
@featured_tags = ActsAsTaggableOn::Tag.where(featured: true)
end
+ def load_category_tags
+ @category_tags = ActsAsTaggableOn::Tag.select("tags.*").
+ where("kind = 'category' and tags.featured = true").
+ order(kind: :asc, id: :asc)
+ end
+ def load_district_select
+ @district_select = Geozone.select("geozones.name, geozones.id").
+ order(id: :asc)
+ end
def parse_tag_filter
if params[:tag].present?
diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb
index c60d7cc43..15d0edefa 100644
--- a/app/controllers/proposals_controller.rb
+++ b/app/controllers/proposals_controller.rb
@@ -35,7 +35,7 @@ class ProposalsController < ApplicationController
private
def proposal_params
- params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key)
+ params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key, :geozone_id)
end
def resource_model
diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb
index da64cba15..bb3c71e0a 100644
--- a/app/views/admin/dashboard/index.html.erb
+++ b/app/views/admin/dashboard/index.html.erb
@@ -3,7 +3,7 @@
Desde aquí puedes administrar el sistema, a través de las siguientes acciones:
- Temas de debate
+ Temas de debate o propuesta
Los temas (también llamadas tags, o etiquetas) de debate son palabras que definen los usuarios al crear debates, para catalogarlos (ej: sanidad, movilidad, arganzuela, ...). Aquí se pueden eliminar temas inapropiados, o marcarlos para ser propuestos al crear debates (cada usuario puede definir los que quiera, pero se le sugieren algunos que nos parecen útiles como catalogación por defecto; aquí se puede cambiar cuáles se sugieren)
Propuestas/Debates/Comentarios ocultos
diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb
index 576dd4ce6..c64ab988d 100644
--- a/app/views/admin/tags/index.html.erb
+++ b/app/views/admin/tags/index.html.erb
@@ -7,25 +7,34 @@
<%= f.label :name, t("admin.tags.name.placeholder") %>
<%= f.text_field :name, placeholder: t("admin.tags.name.placeholder"), label: false %>
-
+
+ <%= f.label :kind, t("admin.tags.kind.placeholder") %>
+ <%= f.text_field :kind, placeholder: t("admin.tags.kind.placeholder"), label: false %>
+
<%= f.label :featured do %>
<%= f.check_box :featured, label: false %>
<%= t("admin.tags.mark_as_featured") %>
<% end %>
+
+ <%= f.submit(t("admin.tags.create"), class: "button radius success") %>
+
-
- <%= f.submit(t("admin.tags.create"), class: "button radius success") %>
-
<% end %>
-
+
+
<%= t("admin.tags.index.title") %>: <%= page_entries_info @tags %>
<% @tags.each do |tag| %>
-
- <%= tag.name %>
+
+ <%= tag.name %>
+
+
+ <%= tag.kind %>
+
<%= form_for(tag,
url: admin_tag_path(tag),
diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb
index adf7c432d..21fc4891f 100644
--- a/app/views/debates/_form.html.erb
+++ b/app/views/debates/_form.html.erb
@@ -16,9 +16,14 @@
<%= f.label :tag_list, t("debates.form.tags_label") %>
<%= t("debates.form.tags_instructions") %>
- <% @featured_tags.each do |tag| %>
+ <%= f.label :tag_list, t("debates.form.tag_category_label") %>
+ <% @category_tags.each do |tag| %>
<%= tag.name %>
<% end %>
+ <%= f.label :tag_list, t("debates.form.tag_district_label") %>
+ <% @district_select.each do |g| %>
+ <%= g.name%>
+ <% end %>
<%= f.text_field :tag_list, value: @debate.tag_list.to_s, label: false, placeholder: t("debates.form.tags_placeholder"), class: 'js-tag-list' %>
diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb
index 97e1ecb6b..78a41295a 100644
--- a/app/views/proposals/_form.html.erb
+++ b/app/views/proposals/_form.html.erb
@@ -43,13 +43,18 @@
<%= f.label :tag_list, t("proposals.form.tags_label") %>
<%= t("proposals.form.tags_instructions") %>
- <% @featured_tags.each do |tag| %>
+ <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %>
+ <% @category_tags.each do |tag| %>
<%= tag.name %>
<% end %>
+ <%= f.label :district_tag_list, t("proposals.form.tag_district_label") %>
+ <% @district_select.each do |g| %>
+ <%= g.name %>
+ <% end %>
+
<%= f.text_field :tag_list, value: @proposal.tag_list.to_s, label: false, placeholder: t("proposals.form.tags_placeholder"), class: 'js-tag-list' %>
-
<% if current_user.unverified? %>
<%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %>
@@ -79,4 +84,4 @@
<%= f.submit(class: "button radius", value: t("proposals.#{action_name}.form.submit_button")) %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index c20393d06..b9ccc977c 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -233,3 +233,38 @@ puts "Confirming hiding in debates, comments & proposals"
Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide)
Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
+
+
+puts "Creating Tags Categories"
+
+ActsAsTaggableOn::Tag.create!(name: "Asociaciones", featured: true, kind: "category")
+puts " Asociaciones"
+ActsAsTaggableOn::Tag.create!(name: "Cultura", featured: true, kind: "category")
+puts " Cultura"
+ActsAsTaggableOn::Tag.create!(name: "Deportes", featured: true, kind: "category")
+puts " Deportes"
+ActsAsTaggableOn::Tag.create!(name: "Derechos SMedio Ambienteociales", featured: true, kind: "category")
+puts " Derechos Sociales"
+ActsAsTaggableOn::Tag.create!(name: "Economía", featured: true, kind: "category")
+puts " Economía"
+ActsAsTaggableOn::Tag.create!(name: "Empleo", featured: true, kind: "category")
+puts " Empleo"
+ActsAsTaggableOn::Tag.create!(name: "Equidad", featured: true, kind: "category")
+puts " Equidad"
+ActsAsTaggableOn::Tag.create!(name: "Sostenibilidad", featured: true, kind: "category")
+puts " Sostenibilidad"
+ActsAsTaggableOn::Tag.create!(name: "Participación", featured: true, kind: "category")
+puts " Participación"
+ActsAsTaggableOn::Tag.create!(name: "Movilidad", featured: true, kind: "category")
+puts " Movilidad"
+ActsAsTaggableOn::Tag.create!(name: "Medios", featured: true, kind: "category")
+puts " Medios"
+ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true , kind: "category")
+puts " Salud"
+ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "category")
+puts " Transparencia"
+ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category")
+puts " Seguridad y Emergencias"
+ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category")
+puts " Medio Ambiente"
+
diff --git a/db/migrate/20160108101736_add_kind_to_tags.rb b/db/migrate/20160108101736_add_kind_to_tags.rb
new file mode 100644
index 000000000..661099fd2
--- /dev/null
+++ b/db/migrate/20160108101736_add_kind_to_tags.rb
@@ -0,0 +1,5 @@
+class AddKindToTags < ActiveRecord::Migration
+ def change
+ add_column :tags, :kind, :string, limit: 40
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2facd1874..a58c9c06c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -199,7 +199,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do
create_table "locks", force: :cascade do |t|
t.integer "user_id"
t.integer "tries", default: 0
- t.datetime "locked_until", default: '2000-01-01 00:01:01', null: false
+ t.datetime "locked_until", default: '2000-01-01 07:01:01', null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
@@ -315,6 +315,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do
t.boolean "featured", default: false
t.integer "debates_count", default: 0
t.integer "proposals_count", default: 0
+ t.string "kind", limit: 40
t.integer "spending_proposals_count", default: 0
end
diff --git a/spec/factories.rb b/spec/factories.rb
index 70ed26a1d..1791b2b6e 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -267,6 +267,7 @@ FactoryGirl.define do
factory :tag, class: 'ActsAsTaggableOn::Tag' do
sequence(:name) { |n| "Tag #{n} name" }
+ kind 'category'
trait :featured do
featured true
diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb
index 74579c1b8..6689aad03 100644
--- a/spec/features/admin/tags_spec.rb
+++ b/spec/features/admin/tags_spec.rb
@@ -17,7 +17,6 @@ feature 'Admin tags' do
scenario 'Create' do
visit admin_tags_path
-
expect(page).to_not have_content 'important issues'
within("form.new_tag") do
@@ -26,7 +25,6 @@ feature 'Admin tags' do
end
visit admin_tags_path
-
expect(page).to have_content 'important issues'
end
@@ -81,4 +79,48 @@ feature 'Admin tags' do
expect(page).to_not have_content tag2.name
end
+ scenario 'validate add new tags' do
+ visit admin_tags_path
+ expect(page).to_not have_content 'important issues'
+
+ within("form.new_tag") do
+ fill_in "tag_name", with: 'important issues'
+ click_button 'Create Topic'
+ end
+
+ visit admin_tags_path
+
+ within("form.new_tag") do
+ fill_in "tag_name", with: 'important issues'
+ click_button 'Create Topic'
+ end
+ expect(page).to have_content 'name of the topic already exists'
+ end
+
+ scenario 'validate uppercase name add new tags' do
+ visit admin_tags_path
+ expect(page).to_not have_content 'important issues'
+
+ within("form.new_tag") do
+ fill_in "tag_name", with: 'important issues'
+ click_button 'Create Topic'
+ end
+
+ visit admin_tags_path
+
+ within("form.new_tag") do
+ fill_in "tag_name", with: 'IMPORTANT ISSUES'
+ click_button 'Create Topic'
+ end
+ expect(page).to have_content 'name of the topic already exists'
+ end
+
+scenario 'validate name new tags' do
+ visit admin_tags_path
+
+ within("form.new_tag") do
+ click_button 'Create Topic'
+ end
+ expect(page).to have_content 'The name of the topic is mandatory filling'
+ end
end
\ No newline at end of file
diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb
index 95527ae9a..44fac3821 100644
--- a/spec/features/debates_spec.rb
+++ b/spec/features/debates_spec.rb
@@ -204,9 +204,13 @@ feature 'Debates' do
login_as(author)
end
- scenario 'using featured tags', :js do
+ scenario 'using featured tags and geozone district', :js do
['Medio Ambiente', 'Ciencia'].each do |tag_name|
- create(:tag, :featured, name: tag_name)
+ create(:tag, :featured, name: tag_name, kind: "category")
+ end
+
+ ['Distrito A', 'Distrito B'].each do |geozone_name|
+ create(:geozone, name: geozone_name)
end
visit new_debate_path
@@ -220,12 +224,19 @@ feature 'Debates' do
find('.js-add-tag-link', text: tag_name).click
end
+ ['Distrito A', 'Distrito B'].each do |geozone_name|
+ find('.js-add-tag-link', text: geozone_name).click
+ end
+
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
['Medio Ambiente', 'Ciencia'].each do |tag_name|
expect(page).to have_content tag_name
end
+ ['Distrito A', 'Distrito B'].each do |tag_name|
+ expect(page).to have_content tag_name
+ end
end
scenario 'using dangerous strings' do
diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb
index 0ef313704..1e5ba8f70 100644
--- a/spec/features/proposals_spec.rb
+++ b/spec/features/proposals_spec.rb
@@ -271,18 +271,22 @@ feature 'Proposals' do
expect(page.html).to_not include ""
end
- context 'Tagging proposals' do
+ context 'Tagging proposals ' do
let(:author) { create(:user) }
background do
login_as(author)
end
- scenario 'using featured tags', :js do
+ scenario 'using featured tags and geozone district', :js do
['Medio Ambiente', 'Ciencia'].each do |tag_name|
create(:tag, :featured, name: tag_name)
end
+ ['Distrito A', 'Distrito B'].each do |geozone_name|
+ create(:geozone, name: geozone_name)
+ end
+
visit new_proposal_path
fill_in 'proposal_title', with: 'A test with enough characters'
@@ -298,12 +302,20 @@ feature 'Proposals' do
find('.js-add-tag-link', text: tag_name).click
end
+ ['Distrito A', 'Distrito B'].each do |geozone_name|
+ find('.js-add-tag-link', text: geozone_name).click
+ end
+
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
['Medio Ambiente', 'Ciencia'].each do |tag_name|
expect(page).to have_content tag_name
end
+
+ ['Distrito A', 'Distrito B'].each do |tag_name|
+ expect(page).to have_content tag_name
+ end
end
scenario 'using dangerous strings' do