uses geozones instead of district tags

This commit is contained in:
rgarcia
2016-01-25 20:48:53 +01:00
parent a86f6bc5b7
commit 21b9e31f11
20 changed files with 141 additions and 97 deletions

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -15,19 +15,11 @@
<div class="small-12 column">
<%= f.label :tag_list, t("debates.form.tags_label") %>
<p class="note"><%= t("debates.form.tags_instructions") %></p>
<span class="tags">
<%= f.label :tag_list, t("debates.form.tag_category_label") %>
<% @category_tags.each do |tag| %>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
<%= f.label :tag_list, t("debates.form.tag_district_label") %>
<% @district_select.each do |g| %>
<a class="js-add-tag-link"><%= g.name%></a>
<% end %>
</span>
<%= f.text_field :tag_list, value: @debate.tag_list.to_s, label: false, placeholder: t("debates.form.tags_placeholder"), class: 'js-tag-list' %>
</div>
<%= f.text_field :tag_list, value: @debate.tag_list.to_s,
label: false,
placeholder: t("debates.form.tags_placeholder") %>
</div>
<div class="small-12 column">
<% 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")) %>
</div>
</div>
<% end %>
<% end %>

View File

@@ -0,0 +1 @@
<%= render 'shared/map', new_url_path: new_debate_path %>

View File

@@ -0,0 +1,9 @@
<div class="sidebar-divider"></div>
<h3><%= t("shared.tags_cloud.categories") %></h3>
<br>
<ul id="categories" style="list-style-type: none;">
<% @categories.each do |category| %>
<li><%= link_to category.name, proposals_path(search: category.name) %></li>
<% end %>
</ul>

View File

@@ -39,22 +39,29 @@
<%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %>
</div>
<div class="small-12 column">
<%= f.label :geozone_id, t("spending_proposals.form.geozone") %>
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
</div>
<div class="small-12 column">
<%= f.label :tag_list, t("proposals.form.tags_label") %>
<p class="note"><%= t("proposals.form.tags_instructions") %></p>
<span class="tags">
<%= f.label :category_tag_list, t("proposals.form.tag_category_label") %>
<% @category_tags.each do |tag| %>
<div id="category_tags" class="tags">
<%= f.label :category_tag_list, t("proposals.form.tag_category_label") %>
<% @categories.each do |tag| %>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
<%= f.label :district_tag_list, t("proposals.form.tag_district_label") %>
<% @district_select.each do |g| %>
<a class="js-add-tag-link"><%= g.name %></a>
<% end %>
</span>
</div>
<br>
<%= 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' %>
</div>
<% if current_user.unverified? %>
<div class="small-12 column">
<%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %>

View File

@@ -0,0 +1,7 @@
<div class="sidebar-divider"></div>
<h3><%= t("shared.tags_cloud.districts") %></h3>
<br>
<%= link_to map_proposals_path, id: 'map' do %>
<%= image_tag("map.jpg") %>
<% end %>

View File

@@ -54,14 +54,10 @@
<aside class="sidebar" role="complementary">
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %>
<%= render "shared/tag_cloud", taggable: 'proposal' %>
<%= render 'categories' %>
<%= render 'geozones' %>
</aside>
</div>
<div class="small-12 medium-3 column">
<aside class="sidebar" role="complementary">
<%= link_to t("shared.tags_cloud.map"), map_path %>
</aside>
</div>
</div>
</section>

View File

@@ -0,0 +1 @@
<%= render 'shared/map', new_url_path: new_proposal_path %>

View File

@@ -64,6 +64,8 @@
<%= render 'shared/tags', taggable: @proposal %>
<%= render 'shared/geozone', geozonable: @proposal %>
<div class="js-moderator-proposal-actions margin">
<%= render 'proposals/actions', proposal: @proposal %>
</div>

View File

@@ -0,0 +1,3 @@
<span id="geozone">
<%= geozone_name(geozonable) %>
</span>

View File

@@ -0,0 +1,49 @@
<div id="proposals" class="proposals-list small-12 medium-9 column">
<h3><%= t("map.title") %></h3>
<%= image_tag("map.jpg", usemap: "#map") %>
<map name="map" id="html_map">
<% @geozones.each do |geozone| %>
<area shape="poly"
coords="<%= geozone.html_map_coordinates %>"
href="<%= polymorphic_url(@resource, search: geozone.name) %>"
title="<%= geozone.name %>"
alt="<%= geozone.name %>">
<% end %>
</map>
<br>
<div id="geozones">
<% @geozones.each do |geozone| %>
<div><%= link_to geozone.name, proposals_path(search: geozone.name) %></div>
<% end %>
</div>
</br>
<h3><%= t("map.proposal_for_district") %></h3>
<div>
<%= form_for(@resource, url: new_url_path, method: :get ) do |f| %>
<div class="small-12 column">
<%= f.label :geozone_id, t("map.select_district") %>
<%= f.select :geozone_id, geozone_select_options,
{include_blank: t("geozones.none"), label: false} %>
</div>
<div class="actions small-12 column">
<%= f.submit(class: "button radius", value: t("map.start_proposal")) %>
</div>
<% end %>
</div>
</div>
<div class="small-12 medium-3 column">
<aside class="sidebar" role="complementary">
<%= link_to t("map.start_proposal"),
new_proposal_path, class: 'button radius expand' %>
<%= render "shared/tag_cloud", taggable: 'proposal' %>
</aside>
</div>

View File

@@ -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

View File

@@ -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

View File

@@ -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