diff --git a/app/assets/images/Distritos_Madrid.jpg b/app/assets/images/Distritos_Madrid.jpg new file mode 100644 index 000000000..5f5fdc34f Binary files /dev/null and b/app/assets/images/Distritos_Madrid.jpg differ diff --git a/app/assets/javascripts/new_debate_map.js b/app/assets/javascripts/new_debate_map.js new file mode 100644 index 000000000..c71567783 --- /dev/null +++ b/app/assets/javascripts/new_debate_map.js @@ -0,0 +1,5 @@ +function call_function() +{ + + location.href = "/new_debate_map/" + $('#district-selector-participation').val() ; +} \ No newline at end of file diff --git a/app/assets/javascripts/new_proposal_map.js b/app/assets/javascripts/new_proposal_map.js new file mode 100644 index 000000000..e539c457c --- /dev/null +++ b/app/assets/javascripts/new_proposal_map.js @@ -0,0 +1,5 @@ +function call_function() +{ + + location.href = "/new_proposal_map/" + $('#district-selector-participation').val() ; +} \ No newline at end of file diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 42a7396de..5352afa6f 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -11,6 +11,8 @@ module CommentableActions index_customization if index_customization.present? @tag_cloud = tag_cloud + @district_cloud = load_district_tags + @category_cloud = load_category_tags set_resource_votes(@resources) set_resources_instance end @@ -26,9 +28,6 @@ module CommentableActions def new @resource = resource_model.new set_resource_instance - load_featured_tags - load_category_tags - load_district_select end def create @@ -36,7 +35,7 @@ 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) @@ -51,7 +50,7 @@ module CommentableActions end def edit - load_featured_tags + load_featured_tags load_category_tags load_district_select end @@ -61,7 +60,7 @@ 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 @@ -69,6 +68,13 @@ module CommentableActions end end + + def map_district + @tag_cloud = tag_cloud + @district_cloud = load_district_tags + @category_cloud = load_category_tags + end + private def track_event @@ -79,23 +85,53 @@ module CommentableActions resource_model.last_week.tag_counts.order("#{resource_name.pluralize}_count": :desc, name: :asc).limit(5) end + def load_category_tags + + if resource_model.to_s=="Proposal" + ActsAsTaggableOn::Tag.select("tags.*"). + where("kind = 'category' and proposals_count>0"). + order(proposals_count: :desc) + else + ActsAsTaggableOn::Tag.select("tags.*"). + where("kind = 'category' and debates_count>0"). + order(debates_count: :desc) + end + end + def load_district_tags + + if resource_model.to_s =="Proposal" + + ActsAsTaggableOn::Tag.select("tags.*"). + where("kind = 'district' and proposals_count>0"). + order(name: :asc) + else + ActsAsTaggableOn::Tag.select("tags.*"). + where("kind = 'district' and debates_count>0"). + order(name: :asc) + end + end + 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) + order(kind: :asc, id: :asc) end def load_district_select @district_select = Geozone.select("geozones.name, geozones.id"). order(id: :asc) - end + end def parse_tag_filter if params[:tag].present? @tag_filter = params[:tag] if ActsAsTaggableOn::Tag.named(params[:tag]).exists? end + + if params[:district].present? + @tag_filter = params[:district] if ActsAsTaggableOn::Disctrict.named(params[:district]).exists? + end end def parse_search_terms diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index a3e6e4a7f..00c67a368 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -7,7 +7,7 @@ class DebatesController < ApplicationController before_action :parse_advanced_search_terms, only: :index before_action :parse_tag_filter, only: :index before_action :set_search_order, only: :index - before_action :authenticate_user!, except: [:index, :show] + before_action :authenticate_user!, except: [:index, :show, :map_district] feature_flag :debates diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 15d0edefa..d001570de 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -6,7 +6,7 @@ class ProposalsController < ApplicationController before_action :parse_advanced_search_terms, only: :index before_action :parse_tag_filter, only: :index before_action :set_search_order, only: :index - before_action :authenticate_user!, except: [:index, :show] + before_action :authenticate_user!, except: [:index, :show, :map_district] has_orders %w{hot_score confidence_score created_at relevance}, only: :index has_orders %w{most_voted newest oldest}, only: :show diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 377ef7440..1be052163 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -10,6 +10,8 @@ module Abilities can :read, Legislation can :read, User can [:search, :read], Annotation + can :map_district, Proposal + can :map_district, Debate end end end diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index f1c12e1b7..c7aadef08 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -47,5 +47,12 @@ <%= render "shared/tag_cloud", taggable: 'debate' %> + +
+ +
+ diff --git a/app/views/debates/map_district.html.erb b/app/views/debates/map_district.html.erb new file mode 100644 index 000000000..98d720fbd --- /dev/null +++ b/app/views/debates/map_district.html.erb @@ -0,0 +1,74 @@ +<%= javascript_include_tag "new_debate_map" %> + +
+ +

<%= t("proposals.index.map_district") %>

+
+ <%= image_tag("Distritos_Madrid.jpg", :usemap => "#MadridMap") %> + + + Fuencarral - El Pardo + Moncloa - Aravaca + Tetuán + Chamberí + Centro + Latina + Carabanchel + Arganzuela + Usera + Villaverde + Chamartin + Salamanca + Retiro + Puente de Vallecas + Villa de Vallecas + Hortaleza + Barajas + Ciudad Lineal + Moratalaz + San Blas - Canillejas + Vicálvaro + + + +
+
+ <% tag_cloud @district_cloud, %w[s m l] do |tag, css_class| %> + <%= link_to tag.name, debates_path(tag: tag.name) %> +
+ <% end %> +
+ + +

<%= t("debates.new.start_new_district") %>

+
+ + + + + + + +
+ +
+ <%= link_to t("debates.index.start_debate"), "javascript:", :onclick => "call_function();" , class: 'button radius' %> +
+ +
+ + +
+ +
diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index 3469ecdb9..6e3a7c2dd 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -56,5 +56,12 @@ <%= render "shared/tag_cloud", taggable: 'proposal' %> + +
+ +
+ diff --git a/app/views/proposals/map_district.html.erb b/app/views/proposals/map_district.html.erb new file mode 100644 index 000000000..311045661 --- /dev/null +++ b/app/views/proposals/map_district.html.erb @@ -0,0 +1,81 @@ +<%= javascript_include_tag "new_proposal_map" %> + +
+ +

<%= t("proposals.index.map_district") %>

+
+ <%= image_tag("Distritos_Madrid.jpg", :usemap => "#MadridMap") %> + + + Fuencarral - El Pardo + Moncloa - Aravaca + Tetuán + Chamberí + Centro + Latina + Carabanchel + Arganzuela + Usera + Villaverde + Chamartin + Salamanca + Retiro + Puente de Vallecas + Villa de Vallecas + Hortaleza + Barajas + Ciudad Lineal + Moratalaz + San Blas - Canillejas + Vicálvaro + + + +
+ +
+ <% tag_cloud @district_cloud, %w[s m l] do |tag, css_class| %> + <%= link_to tag.name, proposals_path(tag: tag.name) %> +
+ <% end %> +
+ + +

<%= t("proposals.new.start_new_district") %>

+
+ + + + + + + +
+ +
+<%= link_to t("proposals.index.start_proposal"), "javascript:", :onclick => "call_function();" , class: 'button radius' %> +
+ +
+ + + + + +
+ +
+ + + diff --git a/app/views/shared/_tag_cloud.html.erb b/app/views/shared/_tag_cloud.html.erb index fe46b6263..62de5a758 100644 --- a/app/views/shared/_tag_cloud.html.erb +++ b/app/views/shared/_tag_cloud.html.erb @@ -8,4 +8,22 @@ (<%= tag.send(taggable_counter_field(taggable)) %>) <% end %> <% end %> + + +

<%= t("shared.tags_cloud.categorys") %>

+
+ <% tag_cloud @category_cloud, %w[s m l] do |tag, css_class| %> + <%= link_to taggable_path(taggable, tag.name), class: css_class do %> + <%= tag.name %> + <%= tag.send(taggable_counter_field(taggable)) %> + <% end %> + <% end %> + + + +

<%= t("shared.tags_cloud.districts") %>

+
+ + <%= image_tag("Distritos_Madrid.jpg") %> + diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index a13ed5320..650bfc786 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -13,3 +13,5 @@ Rails.application.config.assets.precompile += %w( ckeditor/* ) Rails.application.config.assets.precompile += %w( ie_lt9.js ) Rails.application.config.assets.precompile += %w( stat_graphs.js ) Rails.application.config.assets.precompile += %w( print.css ) +Rails.application.config.assets.precompile += %w( new_proposal_map.js ) +Rails.application.config.assets.precompile += %w( new_debate_map.js ) diff --git a/config/locales/en.yml b/config/locales/en.yml index c3f035fc8..efe49020d 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -105,6 +105,8 @@ en: search_results: one: " containing the term '%{search_term}'" other: " containing the term '%{search_term}'" + map_district: "Districts of Madrid" + select_district: "Select your district" select_order: Order by start_debate: Start a debate title: Debates @@ -121,6 +123,7 @@ en: recommendation_two: Any debate or comment suggesting illegal action will be deleted, as well as those intending to sabotage the debate spaces. Anything else is allowed. recommendations_title: Recommendations for creating a debate start_new: Start a debate + start_new_district: "Start a debate for your district" show: author_deleted: User deleted back_link: Go back @@ -294,6 +297,7 @@ en: recommendation_two: Any proposal or comment suggesting illegal action will be deleted, as well as those intending to sabotage the debate spaces. Anything else is allowed. recommendations_title: Recommendations for creating a proposal start_new: Create new proposal + start_new_district: "Start a proposal for your district" proposal: already_supported: You have already supported this proposal. Share it! comments: @@ -360,6 +364,9 @@ en: print_button: Print this info tags_cloud: tags: Trending + districts: "Districs" + categorys: "Categories" + map: "View map of districts" unflag: Unflag simple_captcha: label: Enter the text from the image in the box below diff --git a/config/locales/es.yml b/config/locales/es.yml index 87cabe85d..8fa10b1d8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -105,6 +105,8 @@ es: search_results: one: " que contiene '%{search_term}'" other: " que contienen '%{search_term}'" + map_district: "Distritos de Madrid" + select_district: "Selecciona tu distrito" select_order: Ordenar por start_debate: Empieza un debate title: Debates @@ -121,6 +123,7 @@ es: recommendation_two: Cualquier debate o comentario que implique una acción ilegal será eliminado, también los que tengan la intención de sabotear los espacios de debate, todo lo demás está permitido. recommendations_title: Recomendaciones para crear un debate start_new: Empezar un debate + start_new_district: "Empieza un debate para tu distrito" show: author_deleted: Usuario eliminado back_link: Volver @@ -294,6 +297,7 @@ es: recommendation_two: Cualquier propuesta o comentario que implique una acción ilegal será eliminada, también las que tengan la intención de sabotear los espacios de propuesta, todo lo demás está permitido. recommendations_title: Recomendaciones para crear una propuesta start_new: Crear una propuesta + start_new_district: "Crea una propuesta para tu distrito" proposal: already_supported: "¡Ya has apoyado esta propuesta, compártela!" comments: @@ -360,6 +364,9 @@ es: print_button: Imprimir esta información tags_cloud: tags: Tendencias + districts: "Distritos" + categorys: "Categorias" + map: "Ver mapa de distritos" unflag: Deshacer denuncia simple_captcha: label: Introduce el texto de la imagen en la siguiente caja diff --git a/config/routes.rb b/config/routes.rb index 9c7146dcf..1982895ae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -286,6 +286,11 @@ Rails.application.routes.draw do # static pages + get '/map', to: 'proposals#map_district' + get '/new_proposal_map/:district', to: 'proposals#new', as: 'new_proposal_map' + get '/mad', to: 'debates#map_district' + get '/new_debate_map/:district', to: 'debates#new', as: 'new_debate_map' get '/blog' => redirect("http://diario.madrid.es/participa/") resources :pages, path: '/', only: [:show] + end diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index b9ccc977c..6687ef526 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -71,10 +71,68 @@ end org_user_ids = User.organizations.pluck(:id) not_org_users = User.where(['users.id NOT IN(?)', org_user_ids]) +puts "Creating Tags Categories" +ActsAsTaggableOn::Tag.create!(name: "Asociaciones", featured: true, kind: "category") +ActsAsTaggableOn::Tag.create!(name: "Cultura", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Deportes", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Derechos Sociales", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Economía", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Empleo", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Equidad", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Sostenibilidad", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Participación", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Movilidad", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Medios", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true , kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category") + ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category") + + + puts "Creating Tags Districts" + + ActsAsTaggableOn::Tag.create!(name: "Centro", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Arganzuela", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Retiro" , featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Salamanca" , featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Chamartín" , featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Tetuán" , featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Chamberí" , featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Moncloa-Aravaca", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Latina", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Carabanchel", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Usera", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Puente de Vallecas", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Moratalaz", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Ciudad Lineal", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Hortaleza", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Villaverde", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Villa de Vallecas", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Vicalvaro", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "San Blas-Canillejas", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Barajas", featured: true, kind: "district") + ActsAsTaggableOn::Tag.create!(name: "Fuencarral-El Pardo", featured: true, kind: "district") + + puts "Creating Debates" tags = Faker::Lorem.words(25) +tags = ['Centro', 'Arganzuela', 'Retiro','Salamanca', 'Chamartín', 'Tetuán', 'Chamberí', 'Fuencarral-El Pardo', 'Moncloa-Aravaca', 'Latina', 'Carabanchel', 'Usera', 'Puente de Vallecas', 'Moratalaz', 'Ciudad Lineal', 'Hortaleza', 'Villaverde', 'Villa de Vallecas', 'Vicálvaro', 'San Blas', 'Barajas'] +(1..30).each do |i| + author = User.reorder("RANDOM()").first + description = "

#{Faker::Lorem.paragraphs.join('

')}

" + debate = Debate.create!(author: author, + title: Faker::Lorem.sentence(3).truncate(60), + created_at: rand((Time.now - 1.week) .. Time.now), + description: description, + tag_list: tags.sample(3).join(','), + terms_of_service: "1") + puts " #{debate.title}" +end + + +tags = ['Consumo y comercio', 'Cultura y ocio', 'Deportes', 'Economía', 'Educación', 'Emergencias y seguridad', 'Hacienda', 'Medio ambiente', 'Movilidad y transportes', 'Oposiciones y empleo', 'Salud', 'Servicios sociales', 'Urbanismo y vivienda'] (1..30).each do |i| author = User.reorder("RANDOM()").first @@ -88,10 +146,29 @@ tags = Faker::Lorem.words(25) puts " #{debate.title}" end + puts "Creating Proposals" tags = Faker::Lorem.words(25) +tags = ['Centro', 'Arganzuela', 'Retiro','Salamanca', 'Chamartín', 'Tetuán', 'Chamberí', 'Fuencarral-El Pardo', 'Moncloa-Aravaca', 'Latina', 'Carabanchel', 'Usera', 'Puente de Vallecas', 'Moratalaz', 'Ciudad Lineal', 'Hortaleza', 'Villaverde', 'Villa de Vallecas', 'Vicálvaro', 'San Blas', 'Barajas'] +(1..30).each do |i| + author = User.reorder("RANDOM()").first + description = "

#{Faker::Lorem.paragraphs.join('

')}

" + proposal = Proposal.create!(author: author, + title: Faker::Lorem.sentence(3).truncate(60), + question: Faker::Lorem.sentence(3), + summary: Faker::Lorem.sentence(3), + responsible_name: Faker::Name.name, + external_url: Faker::Internet.url, + description: description, + created_at: rand((Time.now - 1.week) .. Time.now), + tag_list: tags.sample(3).join(','), + terms_of_service: "1") + puts " #{proposal.title}" +end + +tags = ['Consumo y comercio', 'Cultura y ocio', 'Deportes', 'Economía', 'Educación', 'Emergencias y seguridad', 'Hacienda', 'Medio ambiente', 'Movilidad y transportes', 'Oposiciones y empleo', 'Salud', 'Servicios sociales', 'Urbanismo y vivienda'] (1..30).each do |i| author = User.reorder("RANDOM()").first description = "

#{Faker::Lorem.paragraphs.join('

')}

" diff --git a/db/migrate/20160119132601_add_kind_to_tags.rb b/db/migrate/20160119132601_add_kind_to_tags.rb new file mode 100644 index 000000000..a4d196517 --- /dev/null +++ b/db/migrate/20160119132601_add_kind_to_tags.rb @@ -0,0 +1,5 @@ +class AddKindToTags < ActiveRecord::Migration + def change + add_column :tags, :kind, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index a58c9c06c..2ac9a8018 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -317,6 +317,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do t.integer "proposals_count", default: 0 t.string "kind", limit: 40 t.integer "spending_proposals_count", default: 0 + t.string "kind" end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 44fac3821..d89387832 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -901,4 +901,28 @@ feature 'Debates' do visit debate_path(debate) expect(page).to have_content('User deleted') end + + + scenario "Filtered by district" do + tag1= ActsAsTaggableOn::Tag.create!(name: "Centro", featured: true, kind: "district") + tag2= ActsAsTaggableOn::Tag.create!(name: "Puente de Vallecas", featured: true, kind: "district") + tag3= ActsAsTaggableOn::Tag.create!(name: "Retiro", featured: true, kind: "district") + tag4= ActsAsTaggableOn::Tag.create!(name: "Salamanca", featured: true, kind: "district") + + debate1 = create(:debate, tag_list: tag1) + debate2 = create(:debate, tag_list: tag2) + debate3 = create(:debate, tag_list: tag3) + debate4 = create(:debate, tag_list: tag4) + visit debates_path + + click_link "View map of districts" + within("#districtslist") do + click_link "Puente de Vallecas" + end + within("#debates") do + expect(page).to have_css('.debate', count: 1) + expect(page).to have_content(debate2.title) + end + end + end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 1e5ba8f70..91e81f263 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1000,4 +1000,27 @@ feature 'Proposals' do visit proposals_path expect(page).to have_content('User deleted') end + + + scenario "Filtered by district" do + tag1= ActsAsTaggableOn::Tag.create!(name: "Centro", featured: true, kind: "district") + tag2= ActsAsTaggableOn::Tag.create!(name: "Puente de Vallecas", featured: true, kind: "district") + tag3= ActsAsTaggableOn::Tag.create!(name: "Retiro", featured: true, kind: "district") + tag4= ActsAsTaggableOn::Tag.create!(name: "Salamanca", featured: true, kind: "district") + + proposal1 = create(:proposal, tag_list: tag1) + proposal2 = create(:proposal, tag_list: tag2) + proposal3 = create(:proposal, tag_list: tag3) + proposal4 = create(:proposal, tag_list: tag4) + visit proposals_path + + click_link "View map of districts" + within("#districtslist") do + click_link "Puente de Vallecas" + end + within("#proposals") do + expect(page).to have_css('.proposal', count: 1) + expect(page).to have_content(proposal2.title) + end + end end