diff --git a/app/assets/images/Distritos_Madrid.jpg b/app/assets/images/map.jpg similarity index 100% rename from app/assets/images/Distritos_Madrid.jpg rename to app/assets/images/map.jpg diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 5352afa6f..e46ba7da4 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -11,8 +11,6 @@ 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 @@ -27,6 +25,7 @@ module CommentableActions def new @resource = resource_model.new + set_geozone set_resource_instance end @@ -36,23 +35,17 @@ module CommentableActions if @resource.save_with_captcha 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 + load_categories + load_geozones set_resource_instance render :new end end def edit - load_featured_tags - load_category_tags - load_district_select end def update @@ -60,19 +53,17 @@ module CommentableActions if resource.save_with_captcha redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}") else - load_featured_tags - load_category_tags - load_district_select + load_categories + load_geozones set_resource_instance render :edit end end - def map_district + def map + @resource = resource_model.new @tag_cloud = tag_cloud - @district_cloud = load_district_tags - @category_cloud = load_category_tags end private @@ -85,53 +76,22 @@ 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 + def load_geozones + @geozones = Geozone.all.order(name: :asc) end - def load_featured_tags - @featured_tags = ActsAsTaggableOn::Tag.where(featured: true) + def set_geozone + @resource.geozone = Geozone.find(params[resource_name.to_sym].try(:[], :geozone_id)) if params[resource_name.to_sym].try(:[], :geozone_id).present? 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) + + def load_categories + @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name) 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 @@ -167,10 +127,6 @@ module CommentableActions end end - def method_name - - end - def search_finish_date params[:advanced_search][:date_max].try(:to_date) || Date.today end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 00c67a368..ae8aa6f2a 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, :map_district] + before_action :authenticate_user!, except: [:index, :show, :map] feature_flag :debates diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index d001570de..1ee319b93 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -6,7 +6,9 @@ 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, :map_district] + before_action :load_categories, only: [:index, :new, :edit, :map] + before_action :load_geozones, only: [:edit, :map] + before_action :authenticate_user!, except: [:index, :show, :map] 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 1be052163..4de272b8c 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -3,15 +3,13 @@ module Abilities include CanCan::Ability def initialize(user) - can :read, Debate - can :read, Proposal + can [:read, :map], Debate + can [:read, :map], Proposal can :read, Comment can :read, SpendingProposal 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/models/debate.rb b/app/models/debate.rb index 6e8392443..11617319b 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -14,6 +14,7 @@ class Debate < ActiveRecord::Base include ActsAsParanoidAliases belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :geozone has_many :comments, as: :commentable validates :title, presence: true diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 2d052cfad..99253e56f 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -14,6 +14,7 @@ class Proposal < ActiveRecord::Base include ActsAsParanoidAliases belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :geozone has_many :comments, as: :commentable validates :title, presence: true @@ -42,7 +43,7 @@ class Proposal < ActiveRecord::Base scope :sort_by_relevance , -> { all } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :last_week, -> { where("created_at >= ?", 7.days.ago)} - + pg_search_scope :pg_search, { against: { title: 'A', @@ -70,6 +71,7 @@ class Proposal < ActiveRecord::Base } tag_list.each{ |tag| values[tag] = 'D' } values[author.username] = 'D' + values[geozone.name] = 'D' if geozone.present? values end diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 21fc4891f..b26ac555b 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -15,19 +15,11 @@
<%= f.label :tag_list, t("debates.form.tags_label") %>

<%= t("debates.form.tags_instructions") %>

- - <%= 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' %> -
+ <%= f.text_field :tag_list, value: @debate.tag_list.to_s, + label: false, + placeholder: t("debates.form.tags_placeholder") %> +
<% if @debate.new_record? %> <%= f.label :terms_of_service do %> @@ -49,6 +41,4 @@ <%= f.submit(class: "button radius", value: t("debates.#{action_name}.form.submit_button")) %>
-<% end %> - - +<% end %> \ No newline at end of file diff --git a/app/views/debates/map.html.erb b/app/views/debates/map.html.erb new file mode 100644 index 000000000..4c8e7807a --- /dev/null +++ b/app/views/debates/map.html.erb @@ -0,0 +1 @@ +<%= render 'shared/map', new_url_path: new_debate_path %> \ No newline at end of file diff --git a/app/views/proposals/_categories.html.erb b/app/views/proposals/_categories.html.erb new file mode 100644 index 000000000..61ee995df --- /dev/null +++ b/app/views/proposals/_categories.html.erb @@ -0,0 +1,9 @@ + +

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

+
+ + \ No newline at end of file diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 78a41295a..9eb8dcce7 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -39,22 +39,29 @@ <%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %> +
+ <%= f.label :geozone_id, t("spending_proposals.form.geozone") %> + <%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %> +
+
<%= f.label :tag_list, t("proposals.form.tags_label") %>

<%= t("proposals.form.tags_instructions") %>

- - <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %> - <% @category_tags.each do |tag| %> + +
+ <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %> + <% @categories.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' %> + <%= 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") %> diff --git a/app/views/proposals/_geozones.html.erb b/app/views/proposals/_geozones.html.erb new file mode 100644 index 000000000..cf2eb37db --- /dev/null +++ b/app/views/proposals/_geozones.html.erb @@ -0,0 +1,7 @@ + +

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

+
+ +<%= link_to map_proposals_path, id: 'map' do %> + <%= image_tag("map.jpg") %> +<% end %> \ No newline at end of file diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index 6e3a7c2dd..71cdb54a5 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -54,14 +54,10 @@
-
- -
- diff --git a/app/views/proposals/map.html.erb b/app/views/proposals/map.html.erb new file mode 100644 index 000000000..9609c2eb5 --- /dev/null +++ b/app/views/proposals/map.html.erb @@ -0,0 +1 @@ +<%= render 'shared/map', new_url_path: new_proposal_path %> \ No newline at end of file diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index b4ed62531..d298327f9 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -64,6 +64,8 @@ <%= render 'shared/tags', taggable: @proposal %> + <%= render 'shared/geozone', geozonable: @proposal %> +
<%= render 'proposals/actions', proposal: @proposal %>
diff --git a/app/views/shared/_geozone.html.erb b/app/views/shared/_geozone.html.erb new file mode 100644 index 000000000..491cec031 --- /dev/null +++ b/app/views/shared/_geozone.html.erb @@ -0,0 +1,3 @@ + + <%= geozone_name(geozonable) %> + diff --git a/app/views/shared/_map.html.erb b/app/views/shared/_map.html.erb new file mode 100644 index 000000000..359266751 --- /dev/null +++ b/app/views/shared/_map.html.erb @@ -0,0 +1,49 @@ +
+ +

<%= t("map.title") %>

+ + <%= image_tag("map.jpg", usemap: "#map") %> + + + <% @geozones.each do |geozone| %> + <%= geozone.name %> + <% end %> + +
+ +
+ <% @geozones.each do |geozone| %> +
<%= link_to geozone.name, proposals_path(search: geozone.name) %>
+ <% end %> +
+
+ +

<%= t("map.proposal_for_district") %>

+ +
+ <%= form_for(@resource, url: new_url_path, method: :get ) do |f| %> +
+ <%= f.label :geozone_id, t("map.select_district") %> + <%= f.select :geozone_id, geozone_select_options, + {include_blank: t("geozones.none"), label: false} %> +
+ +
+ <%= f.submit(class: "button radius", value: t("map.start_proposal")) %> +
+ <% end %> +
+ +
+ +
+ +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1982895ae..f2d81ec8b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,6 +42,10 @@ Rails.application.routes.draw do put :flag put :unflag end + + collection do + get :map + end end resources :proposals do @@ -51,6 +55,10 @@ Rails.application.routes.draw do put :flag put :unflag end + + collection do + get :map + end end resources :comments, only: [:create, :show], shallow: true do diff --git a/db/migrate/20160122124847_add_geozone_to_proposals_and_debates.rb b/db/migrate/20160122124847_add_geozone_to_proposals_and_debates.rb new file mode 100644 index 000000000..ad2b0cdff --- /dev/null +++ b/db/migrate/20160122124847_add_geozone_to_proposals_and_debates.rb @@ -0,0 +1,9 @@ +class AddGeozoneToProposalsAndDebates < ActiveRecord::Migration + def change + add_column :proposals, :geozone_id, :integer, default: nil + add_index :proposals, :geozone_id + + add_column :debates, :geozone_id, :integer, default: nil + add_index :debates, :geozone_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ac9a8018..df5bbc3a9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -118,6 +118,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do t.integer "cached_votes_score", default: 0 t.integer "hot_score", limit: 8, default: 0 t.integer "confidence_score", default: 0 + t.integer "geozone_id" end add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree @@ -127,6 +128,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree + add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree add_index "debates", ["title"], name: "index_debates_on_title", using: :btree @@ -252,12 +254,14 @@ ActiveRecord::Schema.define(version: 20160122153329) do t.string "video_url" t.integer "physical_votes", default: 0 t.tsvector "tsv" + t.integer "geozone_id" end add_index "proposals", ["author_id", "hidden_at"], name: "index_proposals_on_author_id_and_hidden_at", using: :btree add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree + add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree add_index "proposals", ["question"], name: "index_proposals_on_question", using: :btree @@ -315,9 +319,8 @@ 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 t.string "kind" + t.integer "spending_proposals_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree