From 51d9d186af4760b91390fdb89c70b62efae2f7bd Mon Sep 17 00:00:00 2001 From: nachogomez Date: Fri, 8 Jan 2016 13:49:23 +0100 Subject: [PATCH 1/4] Add Thematic structure and Districts - Iss685 --- app/assets/stylesheets/print.css | 2 + app/controllers/admin/tags_controller.rb | 23 +++++++--- .../concerns/commentable_actions.rb | 27 ++++++++++-- app/views/admin/dashboard/index.html.erb | 2 +- app/views/admin/tags/index.html.erb | 21 +++++++--- app/views/debates/_form.html.erb | 9 +++- app/views/proposals/_form.html.erb | 8 +++- config/locales/admin.en.yml | 12 ++++-- config/locales/admin.es.yml | 10 +++-- config/locales/en.yml | 8 +++- config/locales/es.yml | 8 +++- db/dev_seeds.rb | 42 +++++++++++++++++++ db/migrate/20160108101736_add_kind_to_tags.rb | 5 +++ db/schema.rb | 3 +- spec/factories.rb | 1 + 15 files changed, 151 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20160108101736_add_kind_to_tags.rb 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..25258d2ab 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, featured: :desc).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,14 @@ 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]}'") + end end diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index df232069b..1df510eec 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -25,6 +25,8 @@ module CommentableActions @resource = resource_model.new set_resource_instance load_featured_tags + load_category_tags + load_district_tags end def create @@ -32,18 +34,24 @@ module CommentableActions @resource.author = current_user if @resource.save_with_captcha - track_event + track_event + load_category_tags + load_district_tags redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id) redirect_to redirect_path, notice: t('flash.actions.create.notice', resource_name: "#{resource_name.capitalize}") else load_featured_tags + load_category_tags + load_district_tags set_resource_instance render :new end end def edit - load_featured_tags + load_featured_tags + load_category_tags + load_district_tags end def update @@ -51,7 +59,9 @@ module CommentableActions if resource.save_with_captcha redirect_to resource, notice: t('flash.actions.update.notice', resource_name: "#{resource_name.capitalize}") else - load_featured_tags + load_featured_tags + load_category_tags + load_district_tags set_resource_instance render :edit end @@ -70,7 +80,16 @@ 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_tags + @district_tags = ActsAsTaggableOn::Tag.select("tags.*"). + where("kind = 'district' and tags.featured = true"). + order(kind: :asc, id: :asc) + end def parse_tag_filter if params[:tag].present? @tag_filter = params[:tag] if ActsAsTaggableOn::Tag.named(params[:tag]).exists? 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.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 %>