From 3b2ed08b54061de324e57b05674d124040b8849a Mon Sep 17 00:00:00 2001 From: Alessandro Cuoghi Date: Fri, 21 Jul 2017 16:36:42 +0200 Subject: [PATCH 001/765] Add recommended partials. --- app/views/welcome/_recommended.html.erb | 138 ++++++++++++++++++ .../welcome/_recommended_no_image.html.erb | 129 ++++++++++++++++ 2 files changed, 267 insertions(+) create mode 100644 app/views/welcome/_recommended.html.erb create mode 100644 app/views/welcome/_recommended_no_image.html.erb diff --git a/app/views/welcome/_recommended.html.erb b/app/views/welcome/_recommended.html.erb new file mode 100644 index 000000000..3c6e17294 --- /dev/null +++ b/app/views/welcome/_recommended.html.erb @@ -0,0 +1,138 @@ +
+

Recomendaciones que te pueden interesar

+
+
+

Debates recomendados

+
+
+
    +
  • +
    + +
    +
    Titulo debate 1
    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    +
    +
    +
  • + + + + +
+
+
+ + +
+
+
+
+ +
+ +
+

Propuestas recomendadas

+
+
+
    +
  • +
    + +
    +
    Titulo propuesta 1
    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    +
    +
    +
  • + + + +
+
+
+ + +
+
+
+
+ +
+ +
+

Presupuestos recomendados

+
+
+
    +
  • +
    + +
    +
    Titulo presupuesto 1
    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    +
    +
    +
  • + + + +
+
+
+ + +
+
+
+
+ +
diff --git a/app/views/welcome/_recommended_no_image.html.erb b/app/views/welcome/_recommended_no_image.html.erb new file mode 100644 index 000000000..8fc04488c --- /dev/null +++ b/app/views/welcome/_recommended_no_image.html.erb @@ -0,0 +1,129 @@ +
+

Recomendaciones que te pueden interesar

+
+
+

Debates recomendados

+
+
+
    +
  • +
    +
    +
    Titulo debate 1
    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    +
    +
    +
  • + + + + +
+
+
+ + +
+
+
+
+ +
+ +
+

Propuestas recomendadas

+
+
+
    +
  • +
    +
    +
    Titulo propuesta 1
    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    +
    +
    +
  • + + + +
+
+
+ + +
+
+
+
+ +
+ +
+

Presupuestos recomendados

+
+
+
    +
  • +
    +
    +
    Titulo presupuesto 1
    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    +
    +
    +
  • + + + +
+
+
+ + +
+
+
+
+ +
From ff6471982c1a8f58cb301bc8f48871a6017a024f Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 21 Jul 2017 20:06:33 +0200 Subject: [PATCH 002/765] Add recommended debates, proposals and investement to Home page. --- app/controllers/welcome_controller.rb | 3 - app/helpers/welcome_helper.rb | 11 ++ app/models/user.rb | 18 ++ app/views/proposals/index.html.erb | 14 +- .../welcome/_recommended_no_image.html.erb | 157 ++++++++---------- app/views/welcome/index.html.erb | 2 + config/locales/en/general.yml | 8 + config/locales/es/general.yml | 8 + 8 files changed, 122 insertions(+), 99 deletions(-) create mode 100644 app/helpers/welcome_helper.rb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index d0c650fa3..5aec4a456 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -4,9 +4,6 @@ class WelcomeController < ApplicationController layout "devise", only: [:welcome, :verification] def index - if current_user - redirect_to :proposals - end end def welcome diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 000000000..78c01b141 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,11 @@ +module WelcomeHelper + + def active_class(index) + "is-active is-in" if index == 0 + end + + def slide_display(index) + "display: none;" if index > 0 + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 60536195b..1a26030ea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -313,6 +313,24 @@ class User < ActiveRecord::Base follows.map{|follow| follow.followable.tags.map(&:name)}.flatten.compact.uniq end + def recommended_debates + Debate.tagged_with(interests, any: true). + where("author_id != ?", self). + order("cached_votes_total DESC").limit(3) + end + + def recommended_proposals + Proposal.tagged_with(interests, any: true). + where("author_id != ?", self). + order("cached_votes_up DESC").limit(3) + end + + def recommended_budget_investments + Budget::Investment.tagged_with(interests, any: true). + where("author_id != ?", self). + order("cached_votes_up DESC").limit(3) + end + private def clean_document_number diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index e1c04c607..5d51ad279 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -16,13 +16,13 @@
<% if @search_terms || @advanced_search_terms %> -

<%= t("shared.search_results") %>

-

- <%= page_entries_info @proposals %> - <% if !@advanced_search_terms %> - <%= t("proposals.index.search_results_html", count: @proposals.size, search_term: @search_terms) %> - <% end %> -

+

<%= t("shared.search_results") %>

+

+ <%= page_entries_info @proposals %> + <% if !@advanced_search_terms %> + <%= t("proposals.index.search_results_html", count: @proposals.size, search_term: @search_terms) %> + <% end %> +

<% elsif @tag_filter %>

<%= t("shared.search_results") %>

diff --git a/app/views/welcome/_recommended_no_image.html.erb b/app/views/welcome/_recommended_no_image.html.erb index 8fc04488c..495bccc5c 100644 --- a/app/views/welcome/_recommended_no_image.html.erb +++ b/app/views/welcome/_recommended_no_image.html.erb @@ -1,128 +1,107 @@

-

Recomendaciones que te pueden interesar

-
+

<%= t("welcome.recommended.title") %>

+ +
-

Debates recomendados

+ +

<%= t("welcome.recommended.debates.title") %>

+
+
    -
  • -
    -
    -
    Titulo debate 1
    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    -
    -
    -
  • + <% current_user.recommended_debates.each_with_index do |debate, index| %> -
  • +
    +
    +
    <%= debate.title %>
    +

    <%= debate.description %>

    + +
    -
- + - + <% end %> + +
+ +
+ +
-
- - -
-
- +
-

Propuestas recomendadas

+ +

<%= t("welcome.recommended.proposals.title") %>

+
-
    -
  • -
    -
    -
    Titulo propuesta 1
    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    -
    -
    -
  • - - + + + <% end %>
+
-
+ +
-
+
+
-
+
+
+ +

<%= t("welcome.recommended.budget_investments.title") %>

-
-

Presupuestos recomendados

-
    -
  • -
    -
    -
    Titulo presupuesto 1
    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua

    -
    -
    -
  • - - + + + <% end %>
+
-
+ +
-
-
+
+ +
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 727ec67b7..a9b2d455c 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -45,3 +45,5 @@
<% end %> + +<%= render "recommended_no_image" %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index aea5c65c8..28e294c03 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -713,6 +713,14 @@ en: proposal: description: Open space for citizen proposals about the kind of city we want to live in. title: You propose + recommended: + title: Recommendations that may interest you + debates: + title: Recommended debates + proposals: + title: Recommended proposals + budget_investments: + title: Recommended investments verification: i_dont_have_an_account: I don't have an account i_have_an_account: I already have an account diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 3f21ed55f..47aae4544 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -713,6 +713,14 @@ es: proposal: description: Espacio abierto para propuestas ciudadanas sobre el tipo de ciudad en el que queremos vivir. title: Propones + recommended: + title: Recomendaciones que te pueden interesar + debates: + title: Debates recomendados + proposals: + title: Propuestas recomendados + budget_investments: + title: Presupuestos recomendados verification: i_dont_have_an_account: No tengo cuenta, quiero crear una y verificarla i_have_an_account: Ya tengo una cuenta que quiero verificar From a4e12ea8018c1d286e176d99187cb2a77be41674 Mon Sep 17 00:00:00 2001 From: Alessandro Cuoghi Date: Sat, 22 Jul 2017 00:31:10 +0200 Subject: [PATCH 003/765] Added style to recommended section. Added orbit bullet. For each title of the recommended added truncate horizontal with css. Added link for each recommended. Adjusted for responsive. Passed scss-lint. --- app/assets/stylesheets/layout.scss | 101 +++++++++++ app/assets/stylesheets/mixins.scss | 28 +++ .../welcome/_recommended_no_image.html.erb | 170 +++++++++--------- db/schema.rb | 2 +- 4 files changed, 215 insertions(+), 86 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 7a5705f60..5c4dcb567 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -18,6 +18,7 @@ // 16. Flags // 17. Activity // 18. Banners +// 19. Recommended Section Home // // 01. Global styles @@ -319,6 +320,14 @@ a { background: $brand; } +.truncate-horizontal-text { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + -o-text-overflow: ellipsis; + -ms-text-overflow: ellipsis; +} + // 02. Header // ---------- @@ -2128,3 +2137,95 @@ table { text-decoration: none; } } + +// 19. Recommended Section Home +// ----------- +.section-recommended { + padding-top: $line-height * 2; + + h2 { + margin-bottom: $line-height * 2; + } + + .debates, + .proposals, + .budget-investments { + + @include breakpoint(medium) { + margin-bottom: 0; + } + + @include breakpoint(small) { + margin-bottom: $line-height; + } + } + + .card { + + .card-section { + padding: $line-height; + + p { + font-size: rem-calc(15); + } + } + + .orbit { + height: 300px; + + .orbit-wrapper { + max-height: 250px; + overflow: hidden; + position: relative; + } + + .orbit-bullets { + @include orbit-bullets; + width: 100%; + } + } + } + + .card .orbit .orbit-wrapper .truncate { + background: image-url('truncate.png'); + background-repeat: repeat-x; + bottom: 0; + height: 20px; + position: absolute; + width: 100%; + } + + .debates-inner { + border-top: 4px solid $debates; + } + + .proposals-inner { + border-top: 4px solid $proposals; + } + + .budget-investments-inner { + border-top: 4px solid $budget; + } + + .debates-inner, + .proposals-inner, + .budget-investments-inner { + background: #fff; + max-height: 350px; + + @include breakpoint(small) { + max-height: 400px; + } + + h4 { + margin-top: $line-height; + margin-bottom: 0; + font-size: rem-calc(18); + min-height: 50px; + } + + h5 { + font-size: rem-calc(14); + } + } +} diff --git a/app/assets/stylesheets/mixins.scss b/app/assets/stylesheets/mixins.scss index 401a2ec81..70f4c179d 100644 --- a/app/assets/stylesheets/mixins.scss +++ b/app/assets/stylesheets/mixins.scss @@ -1,6 +1,7 @@ // Table of Contents // // 01. Logo +// 02. Orbit bullets // // 01. Logo @@ -30,3 +31,30 @@ } } } + + +//02. Orbit bullet +@mixin orbit-bullets { + @include disable-mouse-outline; + position: relative; + margin-top: $orbit-bullet-margin-top; + margin-bottom: $orbit-bullet-margin-bottom; + text-align: center; + + button { + width: $orbit-bullet-diameter; + height: $orbit-bullet-diameter; + margin: $orbit-bullet-margin; + + border-radius: 50%; + background-color: $orbit-bullet-background; + + &:hover { + background-color: $orbit-bullet-background-active; + } + + &.is-active { + background-color: $orbit-bullet-background-active; + } + } +} diff --git a/app/views/welcome/_recommended_no_image.html.erb b/app/views/welcome/_recommended_no_image.html.erb index 495bccc5c..e151c06c0 100644 --- a/app/views/welcome/_recommended_no_image.html.erb +++ b/app/views/welcome/_recommended_no_image.html.erb @@ -1,108 +1,108 @@ -
-

<%= t("welcome.recommended.title") %>

+
diff --git a/app/views/legislation/proposals/share.html.erb b/app/views/legislation/proposals/share.html.erb index f86882401..5faa9d985 100644 --- a/app/views/legislation/proposals/share.html.erb +++ b/app/views/legislation/proposals/share.html.erb @@ -34,7 +34,7 @@ <% end %>
- <%= link_to t("proposals.proposal.share.view_proposal"), proposal_path(@proposal) %> + <%= link_to t("proposals.proposal.share.view_proposal"), legislation_process_proposal_path(@proposal.legislation_process_id, @proposal) %>
From d83bb9e31fcb5ee9e5a58ce154b9b4563e4bb5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:08:36 +0200 Subject: [PATCH 051/765] Legislation proposal controller adaptation --- app/controllers/application_controller.rb | 4 ++++ .../legislation/proposals_controller.rb | 20 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 495a25314..318777314 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -76,6 +76,10 @@ class ApplicationController < ActionController::Base @proposal_votes = current_user ? current_user.proposal_votes(proposals) : {} end + def set_legislation_proposal_votes(proposals) + @proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {} + end + def set_spending_proposal_votes(spending_proposals) @spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {} end diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index a275a061d..1eab07047 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -1,9 +1,9 @@ -class Legislation::ProposalsController < ApplicationController +class Legislation::ProposalsController < Legislation::BaseController include CommentableActions include FlagActions - load_and_authorize_resource :process - load_and_authorize_resource :proposal, through: :process + load_and_authorize_resource :process, class: "Legislation::Process" + load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process before_action :parse_tag_filter, only: :index before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] @@ -15,7 +15,6 @@ class Legislation::ProposalsController < ApplicationController has_orders %w{hot_score confidence_score created_at relevance archival_date}, only: :index has_orders %w{most_voted newest oldest}, only: :show - load_and_authorize_resource helper_method :resource_model, :resource_name respond_to :html, :js @@ -23,7 +22,8 @@ class Legislation::ProposalsController < ApplicationController super @notifications = @proposal.notifications @document = Document.new(documentable: @proposal) - redirect_to proposal_path(@proposal), status: :moved_permanently if request.path != proposal_path(@proposal) + redirect_to legislation_process_proposal_path(params[:process_id], @proposal), + status: :moved_permanently if request.path != legislation_process_proposal_path(params[:process_id], @proposal) end def create @@ -31,7 +31,7 @@ class Legislation::ProposalsController < ApplicationController recover_documents_from_cache(@proposal) if @proposal.save - redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal') + redirect_to share_legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t('flash.actions.create.proposal') else render :new end @@ -46,7 +46,7 @@ class Legislation::ProposalsController < ApplicationController def vote @proposal.register_vote(current_user, 'yes') - set_proposal_votes(@proposal) + set_legislation_proposal_votes(@proposal) end def retire @@ -98,7 +98,11 @@ class Legislation::ProposalsController < ApplicationController Legislation::Proposal end - def set_featured_proposal_votes(proposals) + def resource_name + 'proposal' + end + + def set_legislation_proposal_votes(proposals) @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} end From 08d1e96575467159f6e13185f8b39185d46682f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:09:43 +0200 Subject: [PATCH 052/765] Added migration to include `legislation/proposals_count` in tags table --- ...19_add_legislation_proposals_count_to_tags.rb | 6 ++++++ db/schema.rb | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb diff --git a/db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb b/db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb new file mode 100644 index 000000000..9ce6ace89 --- /dev/null +++ b/db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb @@ -0,0 +1,6 @@ +class AddLegislationProposalsCountToTags < ActiveRecord::Migration + def change + add_column :tags, "legislation/proposals_count", :integer, default: 0 + add_index :tags, "legislation/proposals_count" + end +end diff --git a/db/schema.rb b/db/schema.rb index 8a33adfc8..41952607e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170914102634) do +ActiveRecord::Schema.define(version: 20170915101519) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -927,16 +927,18 @@ ActiveRecord::Schema.define(version: 20170914102634) do add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "tags", force: :cascade do |t| - t.string "name", limit: 40 - t.integer "taggings_count", default: 0 - t.integer "debates_count", default: 0 - t.integer "proposals_count", default: 0 - t.integer "spending_proposals_count", default: 0 + t.string "name", limit: 40 + t.integer "taggings_count", default: 0 + t.integer "debates_count", default: 0 + t.integer "proposals_count", default: 0 + t.integer "spending_proposals_count", default: 0 t.string "kind" - t.integer "budget/investments_count", default: 0 + t.integer "budget/investments_count", default: 0 + t.integer "legislation/proposals_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree + add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree From c1672bdbf415c9ec4e94793b9eb6ee46dc945c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:10:10 +0200 Subject: [PATCH 053/765] Legislation proposals adaptation in some models and initializers --- app/models/legislation/proposal.rb | 4 ++-- app/models/user.rb | 6 ++++++ app/models/vote.rb | 6 ++++-- config/initializers/acts_as_taggable_on.rb | 5 +++-- config/initializers/vote_extensions.rb | 4 ++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 1eb82e70a..5f6706339 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -156,11 +156,11 @@ class Legislation::Proposal < ActiveRecord::Base end def after_hide - tags.each{ |t| t.decrement_custom_counter_for('Proposal') } + tags.each{ |t| t.decrement_custom_counter_for('LegislationProposal') } end def after_restore - tags.each{ |t| t.increment_custom_counter_for('Proposal') } + tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') } end def self.votes_needed_for_success diff --git a/app/models/user.rb b/app/models/user.rb index ef6ab7832..b34897688 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -97,6 +97,12 @@ class User < ActiveRecord::Base voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end + def legislation_proposal_votes(proposals) + voted = votes.for_proposals(proposals) + voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } + end + + def spending_proposal_votes(spending_proposals) voted = votes.for_spending_proposals(spending_proposals) voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } diff --git a/app/models/vote.rb b/app/models/vote.rb index 14b11a68d..4d4d07be0 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -5,10 +5,12 @@ class Vote < ActsAsVotable::Vote scope :public_for_api, -> do where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or (votes.votable_type = 'Proposal' and votes.votable_id in (?)) or - (votes.votable_type = 'Comment' and votes.votable_id in (?))}, + (votes.votable_type = 'Comment' and votes.votable_id in (?)) or + (votes.votable_type = 'LegislationProposal' and votes.votable_id in (?))}, Debate.public_for_api.pluck(:id), Proposal.public_for_api.pluck(:id), - Comment.public_for_api.pluck(:id)) + Comment.public_for_api.pluck(:id), + Legislation::Proposal.public_for_api.pluck(:id)) end end diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 57766c8c9..9db832bef 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -8,10 +8,11 @@ module ActsAsTaggableOn scope :public_for_api, -> do where(%{taggings.tag_id in (?) and (taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or - (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?))}, + (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?)) or taggings.taggable_type = 'LegislationProposal' and taggings.taggable_id in (?))}, Tag.where('kind IS NULL or kind = ?', 'category').pluck(:id), Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id)) + Proposal.public_for_api.pluck(:id), + Legislation::Proposal.public_for_api.pluck(:id)) end def touch_taggable diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 06d3dde5b..1b6ae7252 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -13,6 +13,10 @@ ActsAsVotable::Vote.class_eval do where(votable_type: 'SpendingProposal', votable_id: spending_proposals) end + def self.for_spending_proposals(spending_proposals) + where(votable_type: 'LegislationProposal', votable_id: legislation_proposals) + end + def self.for_budget_investments(budget_investments) where(votable_type: 'Budget::Investment', votable_id: budget_investments) end From 049967649e82ba6d5699c1e1a3f00d246490dc60 Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 19 Sep 2017 17:37:31 +0200 Subject: [PATCH 054/765] Selection of multiple tags separated by ',' works for hardcoded array of tags. --- app/assets/javascripts/application.js | 3 ++ .../javascripts/tag_autocomplete.js.coffee | 29 +++++++++++++ app/assets/stylesheets/application.scss | 2 + .../stylesheets/autocomplete_overrides.scss | 41 +++++++++++++++++++ app/views/debates/_form.html.erb | 3 +- config/routes.rb | 4 ++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/tag_autocomplete.js.coffee create mode 100644 app/assets/stylesheets/autocomplete_overrides.scss diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 2ff87100a..01c5dbaff 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,6 +14,7 @@ //= require jquery_ujs //= require jquery-ui/widgets/datepicker //= require jquery-ui/i18n/datepicker-es +//= require jquery-ui/widgets/autocomplete //= require jquery-fileupload/basic //= require foundation //= require turbolinks @@ -63,6 +64,7 @@ //= require documentable //= require tree_navigator //= require custom +//= require tag_autocomplete var initialize_modules = function() { App.Comments.initialize(); @@ -97,6 +99,7 @@ var initialize_modules = function() { App.WatchFormChanges.initialize(); App.TreeNavigator.initialize(); App.Documentable.initialize(); + App.TagAutocomplete.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/tag_autocomplete.js.coffee b/app/assets/javascripts/tag_autocomplete.js.coffee new file mode 100644 index 000000000..9e10c100e --- /dev/null +++ b/app/assets/javascripts/tag_autocomplete.js.coffee @@ -0,0 +1,29 @@ +App.TagAutocomplete = + + split: ( val ) -> + return (val.split( /,\s*/ )) + + extractLast: ( term ) -> + return (App.TagAutocomplete.split( term ).pop()) + + init_autocomplete: -> + $('.js-tag-list').autocomplete + source: (request, response) -> + response( $.ui.autocomplete.filter(["Arbol", "Becerro", "Caracol"], App.TagAutocomplete.extractLast( request.term ) ) ); + minLength: 0, + search: -> + console.log(this.value); + console.log(App.TagAutocomplete.extractLast( this.value )); + App.TagAutocomplete.extractLast( this.value ); + focus: -> + return false; + select: ( event, ui ) -> ( + terms = App.TagAutocomplete.split( this.value ); + terms.pop(); + terms.push( ui.item.value ); + terms.push( "" ); + this.value = terms.join( ", " ); + return false;); + + initialize: -> + App.TagAutocomplete.init_autocomplete(); \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 19c73de32..e4dd4ea1c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,4 +16,6 @@ @import 'annotator_overrides'; @import 'jquery-ui/datepicker'; @import 'datepicker_overrides'; +@import 'jquery-ui/autocomplete'; +@import 'autocomplete_overrides'; @import 'documentable'; diff --git a/app/assets/stylesheets/autocomplete_overrides.scss b/app/assets/stylesheets/autocomplete_overrides.scss new file mode 100644 index 000000000..68537fd8a --- /dev/null +++ b/app/assets/stylesheets/autocomplete_overrides.scss @@ -0,0 +1,41 @@ +// Overrides styles of jquery-ui/autocomplete +// + +/* Autocomplete +----------------------------------*/ +.ui-autocomplete { position: absolute; cursor: default; } +.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; } + +/* workarounds */ +* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */ + +/* Menu +----------------------------------*/ +.ui-menu { + list-style:none; + padding: 0px 5px; + margin: 0; + display:block; + /*width:227px;*/ + background: white; + border: 1px solid $border; +} +.ui-menu .ui-menu { + margin-top: -3px; +} +.ui-menu .ui-menu-item { + margin:0; + padding: 0; + width: 200px; +} +.ui-menu .ui-menu-item a { + /* text-decoration:none; + display:block;*/ + padding:.2em .4em; + /* line-height:1.5; + zoom:1;*/ +} +.ui-menu .ui-menu-item a.ui-state-hover, +.ui-menu .ui-menu-item a.ui-state-active { + margin: -1px; +} \ No newline at end of file diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 96a5337ca..28ef69804 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -22,7 +22,8 @@ <%= f.text_field :tag_list, value: @debate.tag_list.to_s, label: false, placeholder: t("debates.form.tags_placeholder"), - aria: {describedby: "tag-list-help-text"} %> + aria: {describedby: "tag-list-help-text"}, + data: {js_url: tags_search_path}%>
<% if @debate.new_record? %> diff --git a/config/routes.rb b/config/routes.rb index a02384ced..666285496 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -167,6 +167,10 @@ Rails.application.routes.draw do resource :email, controller: "email", only: [:new, :show, :create] resource :letter, controller: "letter", only: [:new, :create, :show, :edit, :update] end + + namespace :tags do + get :search + end namespace :admin do From 28a658319918fe62eb2cfb3e2d36c817871cf9ab Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 15 Sep 2017 13:04:14 +0200 Subject: [PATCH 055/765] removes untranslated texts on admin dashboard index --- app/views/admin/dashboard/index.html.erb | 87 ------------------------ 1 file changed, 87 deletions(-) diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 2a2ed1c56..3d56b1f14 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -10,90 +10,3 @@

<%= t("admin.dashboard.index.title") %>

-

Desde aquí puedes administrar el sistema, a través de las siguientes acciones:

- -
-
    - -
  • - Temas de debate -
    -

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

    Cuando un moderador o un administrador oculta una Propuesta/Debate/Comentario aparecerá en esta lista. De esta forma los administradores pueden revisar que se ha ocultado el elemento adecuado.

    - -
      -
    • Al pulsar Confirmar se acepta el que se haya ocultado, se considera que se ha hecho correctamente.
    • -
    • Al pulsar Volver a mostrar se revierte la acción de ocultar y vuelve a ser una Propuesta/Debate/Comentario visible, en el caso de que se considere - que ha sido una acción errónea el haberlo ocultado.
    • -
    - -

    Para facilitar la gestión, arriba encontramos un filtro con las secciones: "pendientes" (los elementos sobre los que todavía no se ha pulsado "confirmar" o "volver a mostrar", que deberían ser revisados todavía), "confirmados" y "todos".

    - -

    Es recomendable revisar regularmente la sección "pendientes".

    -
    -
  • - -
  • - Usuarios bloqueados -
    -

    Cuando un moderador o un administrador bloquea a un usuario aparecerá en esta lista. Al bloquear a un usuario, éste deja de poder utilizarlo para ninguna acción de la web. Los administradores pueden desbloquearlos pulsando el botón al lado del nombre del usuario en la lista.

    -
    -
  • - -
  • - Organizaciones -
    -

    En la web hay dos tipos de usuarios: individuales y organizaciones. Cualquier persona puede crear usuarios de un tipo o de otro en la propia web. Los usuarios de organizaciones pueden ser verificados por parte de los administradores, confirmando que quien gestiona el usuario efectivamente representa a esa organización. Una vez se haya realizado el proceso de verificación, por el proceso externo a la web que se haya definido para ello, se pulsa el botón "Verificar" para confimarlo; lo que hará que al lado del nombre de la organización aparezca una etiqueta señalando que es una organización verificada.

    - -

    En caso de que el proceso de verificación haya sido negativo, se pulsa el botón "Rechazar". Para editar alguno de los datos de la organización, se pulsa el botón "Editar".

    - -

    En caso de que el proceso de verificación haya sido negativo, se pulsa el botón "Rechazar". Para editar alguno de los datos de la organización, se pulsa el botón "Editar".

    - -

    Las organizaciones que no aparecen en la lista pueden ser encontradas para actuar sobre ellas por medio del buscador en la parte superior. Para facilitar la gestión, arriba - encontramos un filtro con las secciones: "pendientes" (las organizaciones que todavía no han sido verificadas o rechazadas), "verificadas", "rechazadas" y "todas".

    -

    Es recomendable revisar regularmente la sección "pendientes".

    -
    -
  • - -
  • - Cargos Públicos -
    -

    En la web, los usuarios individuales pueden ser usuarios normales, o cargos públicos. Estos últimos se diferencian de los primeros únicamente en que al lado de sus nombres aparece una etiqueta que les identifica, y cambia ligeramente el estilo de sus comentarios. Esto permite que los usuarios les identifiquen más fácilmente. Al lado de cada usuario vemos la identificación que aparece en su etiqueta, y su nivel (la manera que internamente usa la web para diferenciar entre un tipo de cargos y otros). Pulsando el botón "Editar" al lado del usuario, se puede modificar su información. Los cargos públicos que no aparecen en la lista pueden ser encontrados para actuar sobre ellos por medio del buscador en la parte superior.

    -
    -
  • - -
  • - Moderadores -
    -

    Mediante el buscador de la parte superior se pueden buscar usuarios, para activarlos o desactivarlos como moderadores de la web. Los moderadores al acceder a la web con su usuario ven en la parte superior una nueva sección llamada "Moderar"

    -
    -
  • - -
  • - Actividad de moderadores -
    -

    En esta sección se va guardando todas las acciones que realizan los moderadores o los administradores respecto a la moderación: ocultar/mostrar Propuestas/Debates/Comentarios y bloquear usuarios. En la columna "Acción" comprobamos si la acción corresponde con ocultar o con volver a mostrar (restaurar) elementos o con bloquear usuarios. En las demás columnas tenemos el tipo de elemento, el contenido del elemento y el moderador o administrador que ha realizado la acción. Esta sección permite que los administradores detecten comportamientos irregulares por parte de moderadores específicos y que por lo tanto puedan corregirlos.

    -
    -
  • - -
  • - Configuración Global -
    -

    Opciones generales de configuración del sistema.

    -
    -
  • - -
  • - Estadísticas -
    -

    Estadísticas generales del sistema.

    -
    -
  • -
-
From 8ed791e86023b14a12c0acbee25aecb01ee9306b Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 15 Sep 2017 13:04:52 +0200 Subject: [PATCH 056/765] includes description text on admin dashboard index --- app/views/admin/dashboard/index.html.erb | 6 ++++++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + 3 files changed, 8 insertions(+) diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 3d56b1f14..94f7c767b 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -7,6 +7,12 @@ <%= t("admin.menu.stats") %> <% end %> +
+ <%= link_to root_path do %> + <%= t("admin.dashboard.index.back") + " " + setting['org_name'] %> + <% end %> +

<%= t("admin.dashboard.index.title") %>

+

<%= t("admin.dashboard.index.description", org: setting['org_name']) %>

diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 91b493ffa..ca9a543e9 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -216,6 +216,7 @@ en: index: back: Go back to title: Administration + description: Welcome to the %{org} admin panel. debates: index: filter: Filter diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 2db094999..7d768e4d9 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -216,6 +216,7 @@ es: index: back: Volver a title: Administración + description: Bienvenido al panel de administración de %{org}. debates: index: filter: Filtro From 90f2b848562a1cc212f39a30967a2edc43c86036 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 15 Sep 2017 13:05:46 +0200 Subject: [PATCH 057/765] improves admin header layout --- app/views/layouts/_admin_header.html.erb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/views/layouts/_admin_header.html.erb b/app/views/layouts/_admin_header.html.erb index bd4f09074..c7dba228f 100644 --- a/app/views/layouts/_admin_header.html.erb +++ b/app/views/layouts/_admin_header.html.erb @@ -2,31 +2,27 @@
- <%= link_to setting['org_name'], namespaced_root_path, class: "logo show-for-small-only" %> - <%= t("application.menu")%> -
+

- <%= link_to namespaced_root_path, class: "hide-for-small-only" do %> - <%= image_tag(image_path_for('logo_header.png'), class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %> + <%= link_to namespaced_root_path do %> <%= setting['org_name'] %> -  | <%= namespaced_header_title %> +
<%= namespaced_header_title %> <% end %>

+
diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index b44c4d6cb..b294acf45 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -1,18 +1,6 @@
-
- - - <%= supports_percentage(proposal) %> / <%= t("proposals.proposal.total_percent") %> - -
- <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  - - "> - <%= t("proposals.proposal.supports_necessary", number: number_with_delimiter(Proposal.votes_needed_for_success)) %> - -
diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index b17464a04..f3692e3c7 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -22,12 +22,6 @@ class: 'button hollow float-right' %> <% end %> - <% if author_of?(@proposal, current_user) %> - <%= link_to t("proposals.show.send_notification"), - new_proposal_notification_path(proposal_id: @proposal.id), - class: 'button hollow float-right' %> - <% end %> - <% if current_user && @proposal.editable_by?(current_user) %> <%= link_to edit_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal), class: 'edit-proposal button hollow float-right' do %> <%= t("proposals.show.edit_proposal_link") %> @@ -35,14 +29,7 @@ <% end %>

<%= @proposal.title %>

- <% if @proposal.retired? %> -
- - <%= t("proposals.show.retired_warning") %>
- <%= link_to t("proposals.show.retired_warning_link_to_explanation"), "#retired_explanation" %> -
-
- <% elsif @proposal.conflictive? %> + <% if @proposal.conflictive? %>
<%= t("proposals.show.flag") %>
@@ -105,13 +92,6 @@

<%= @proposal.question %>

- <% if @proposal.retired? %> -
-

<%= t('proposals.show.retired') %>: <%= t("proposals.retire_options.#{@proposal.retired_reason}") unless @proposal.retired_reason == 'other' %>

- <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %> -
- <% end %> - <%= render 'shared/tags', taggable: @proposal %> <%= render 'shared/geozone', geozonable: @proposal %> @@ -125,30 +105,8 @@

<%= t("votes.supports") %>

- - <% if @proposal.successful? %> -

- <%= t("proposals.proposal.successful", - voting: link_to(t("proposals.proposal.voting"), polls_path)).html_safe %> -

- <% if can? :create, Poll::Question %> -

- <%= link_to t('poll_questions.create_question'), - new_admin_question_path(proposal_id: @proposal.id), - class: "button hollow expanded" %> -

- <% end %> - <% elsif @proposal.archived? %> -
-

- <%= t("proposals.proposal.supports", count: @proposal.total_votes) %> -

-

<%= t("proposals.proposal.archived") %>

-
- <% else %> - <%= render 'votes', - { proposal: @proposal, vote_url: vote_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal, value: 'yes') } %> - <% end %> + <%= render 'votes', + { proposal: @proposal, vote_url: vote_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal, value: 'yes') } %>
<%= render partial: 'shared/social_share', locals: { share_title: t("proposals.show.share"), @@ -168,11 +126,10 @@ <% end %>
- <%= render "proposals/filter_subnav" %> - <%= render "proposals/notifications" %> + <%= render "legislation/proposals/filter_subnav" %>
- <%= render "proposals/comments" %> + <%= render "legislation/proposals/comments" %>
diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 9db832bef..57766c8c9 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -8,11 +8,10 @@ module ActsAsTaggableOn scope :public_for_api, -> do where(%{taggings.tag_id in (?) and (taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or - (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?)) or taggings.taggable_type = 'LegislationProposal' and taggings.taggable_id in (?))}, + (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?))}, Tag.where('kind IS NULL or kind = ?', 'category').pluck(:id), Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id), - Legislation::Proposal.public_for_api.pluck(:id)) + Proposal.public_for_api.pluck(:id)) end def touch_taggable diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 1b6ae7252..effec12ea 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -9,12 +9,12 @@ ActsAsVotable::Vote.class_eval do where(votable_type: 'Proposal', votable_id: proposals) end - def self.for_spending_proposals(spending_proposals) - where(votable_type: 'SpendingProposal', votable_id: spending_proposals) + def self.for_legislation_proposals(proposals) + where(votable_type: 'Legislation::Proposal', votable_id: proposals) end def self.for_spending_proposals(spending_proposals) - where(votable_type: 'LegislationProposal', votable_id: legislation_proposals) + where(votable_type: 'SpendingProposal', votable_id: spending_proposals) end def self.for_budget_investments(budget_investments) diff --git a/config/routes.rb b/config/routes.rb index e2ccb51ed..851ff0cdf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -132,17 +132,13 @@ Rails.application.routes.draw do resources :proposals do member do post :vote - post :vote_featured put :flag put :unflag - get :retire_form get :share - patch :retire end collection do get :map get :suggest - get :summary end end resources :draft_versions, only: [:show] do From 6c1c71fcc9623ce7902e024060a123d697edaa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 16:18:08 +0200 Subject: [PATCH 070/765] Minor fixes Fixed subnavigation active links and button to create new proposal. --- app/helpers/tags_helper.rb | 2 ++ app/views/legislation/processes/proposals.html.erb | 4 +--- app/views/shared/_subnavigation.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 4cabae278..eb34a64f2 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -8,6 +8,8 @@ module TagsHelper proposals_path(search: tag_name) when 'budget/investment' budget_investments_path(@budget, search: tag_name) + when 'legislation/proposal' + legislation_process_proposals_path(@process, search: tag_name) else '#' end diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index 9e54ba46e..5883658b7 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -20,9 +20,7 @@
-
-

<%= t('.participate') %>

-
+

<%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

diff --git a/app/views/shared/_subnavigation.html.erb b/app/views/shared/_subnavigation.html.erb index dd9809dd3..fbcdfebf3 100644 --- a/app/views/shared/_subnavigation.html.erb +++ b/app/views/shared/_subnavigation.html.erb @@ -12,7 +12,7 @@
  • <%= layout_menu_link_to t("layouts.header.proposals"), proposals_path, - controller_name == 'proposals', + controller_name == 'proposals' && !controller.class.parent == Legislation, accesskey: "2", title: t("shared.go_to_page") + t("layouts.header.proposals") %>
  • From 5ae8cda0d5079ba559cf545005e9c7d009498ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 16:23:34 +0200 Subject: [PATCH 071/765] Fixed legislation proposal vote action --- app/models/legislation/proposal.rb | 2 +- app/views/legislation/proposals/vote.js.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index d1339cabc..5ced1529d 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -101,7 +101,7 @@ class Legislation::Proposal < ActiveRecord::Base end def register_vote(user, vote_value) - if votable_by?(user) && !archived? + if votable_by?(user) vote_by(voter: user, vote: vote_value) end end diff --git a/app/views/legislation/proposals/vote.js.erb b/app/views/legislation/proposals/vote.js.erb index 4a5ca6b6b..1a0d6d4ed 100644 --- a/app/views/legislation/proposals/vote.js.erb +++ b/app/views/legislation/proposals/vote.js.erb @@ -1 +1 @@ -$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/votes", proposal: @proposal) %>'); \ No newline at end of file +$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("legislation/proposals/votes", proposal: @proposal) %>'); From 57c48fe596e041a412a0c81c1eb663b470df95a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 17:13:12 +0200 Subject: [PATCH 072/765] Legislation proposals comments working --- app/models/comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 8b68e11ad..a0cb343d7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base include HasPublicAuthor include Graphqlable - COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic).freeze + COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic Legislation::Proposal).freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases From 536ee520e89d9338d4deec30cabe18768c29ebf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 17:13:22 +0200 Subject: [PATCH 073/765] Removed unnecessary views --- .../legislation/proposals/_retired.html.erb | 13 ----- .../proposals/retire_form.html.erb | 38 ------------- .../legislation/proposals/summary.html.erb | 53 ------------------- .../proposals/vote_featured.js.erb | 1 - 4 files changed, 105 deletions(-) delete mode 100644 app/views/legislation/proposals/_retired.html.erb delete mode 100644 app/views/legislation/proposals/retire_form.html.erb delete mode 100644 app/views/legislation/proposals/summary.html.erb delete mode 100644 app/views/legislation/proposals/vote_featured.js.erb diff --git a/app/views/legislation/proposals/_retired.html.erb b/app/views/legislation/proposals/_retired.html.erb deleted file mode 100644 index 2167b14af..000000000 --- a/app/views/legislation/proposals/_retired.html.erb +++ /dev/null @@ -1,13 +0,0 @@ - - - -<% if params[:retired].blank? %> -

    <%= link_to t("proposals.index.retired_proposals_link"), proposals_path(retired: 'all'), class: "small" %>

    -<% else %> - -<% end %> diff --git a/app/views/legislation/proposals/retire_form.html.erb b/app/views/legislation/proposals/retire_form.html.erb deleted file mode 100644 index d56277cb3..000000000 --- a/app/views/legislation/proposals/retire_form.html.erb +++ /dev/null @@ -1,38 +0,0 @@ -
    - -
    - -

    <%= t("proposals.retire_form.title") %>

    - -

    <%= link_to @proposal.title, @proposal %>

    - -
    - <%= t("proposals.retire_form.warning") %> -
    - - <%= form_for(@proposal, url: retire_proposal_path(@proposal)) do |f| %> - <%= render 'shared/errors', resource: @proposal %> -
    -
    - <%= f.label :retired_reason, t("proposals.retire_form.retired_reason_label") %> - <%= f.select :retired_reason, retire_proposals_options, {include_blank: t("proposals.retire_form.retired_reason_blank"), label: false} %> -
    -
    - -
    -
    - <%= f.label :retired_explanation, t("proposals.retire_form.retired_explanation_label") %> - <%= f.text_area :retired_explanation, rows: 4, maxlength: 500, label: false, - placeholder: t('proposals.retire_form.retired_explanation_placeholder') %> -
    -
    - -
    -
    - <%= f.submit(class: "button expanded", value: t("proposals.retire_form.submit_button")) %> -
    -
    - <% end %> - -
    -
    \ No newline at end of file diff --git a/app/views/legislation/proposals/summary.html.erb b/app/views/legislation/proposals/summary.html.erb deleted file mode 100644 index a28cf8750..000000000 --- a/app/views/legislation/proposals/summary.html.erb +++ /dev/null @@ -1,53 +0,0 @@ -
    -
    -
    - <%= back_link_to %> - - <% @proposals.each do |group_name, proposals| %> -
    -

    <%= group_name %>

    - - <% proposals[0..2].each do |proposal| %> -
    -
    -
    -
    -
    -

    <%= link_to proposal.title, namespaced_proposal_path(proposal) %>

    - -

    - <% if proposal.author.hidden? || proposal.author.erased? %> - <%= t("proposals.show.author_deleted") %> - <% else %> - <%= proposal.author.name %> - <% if proposal.author.display_official_position_badge? %> - - <%= proposal.author.official_position %> - - <% end %> - <% end %> -

    - -
    -

    <%= proposal.summary %>

    -
    -
    -
    -
    -
    -
    - <% end %> -
    - <% end %> -
    - -
    - -
    -
    -
    \ No newline at end of file diff --git a/app/views/legislation/proposals/vote_featured.js.erb b/app/views/legislation/proposals/vote_featured.js.erb deleted file mode 100644 index 52619282b..000000000 --- a/app/views/legislation/proposals/vote_featured.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/featured_votes", proposal: @proposal) %>'); \ No newline at end of file From 4db2584f87d4b535aa9b6c39de15e14413fd926f Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 21 Sep 2017 18:21:45 +0200 Subject: [PATCH 074/765] The tags are suggested based on the entries the user makes. Cambios para hacer commit: modificado: app/assets/javascripts/tag_autocomplete.js.coffee modificado: app/assets/stylesheets/autocomplete_overrides.scss nuevo archivo: app/controllers/tags_controller.rb modificado: app/models/abilities/common.rb modificado: app/views/debates/_form.html.erb modificado: app/views/proposals/_form.html.erb modificado: config/initializers/acts_as_taggable_on.rb modificado: config/routes.rb modificado: spec/lib/acts_as_taggable_on_spec.rb --- .../javascripts/tag_autocomplete.js.coffee | 13 +++++-- .../stylesheets/autocomplete_overrides.scss | 39 ++++++++----------- app/controllers/tags_controller.rb | 11 ++++++ app/models/abilities/common.rb | 1 + app/views/debates/_form.html.erb | 3 +- app/views/proposals/_form.html.erb | 5 ++- config/initializers/acts_as_taggable_on.rb | 13 +++++++ config/routes.rb | 33 ++++++++-------- spec/lib/acts_as_taggable_on_spec.rb | 15 +++++++ 9 files changed, 86 insertions(+), 47 deletions(-) create mode 100644 app/controllers/tags_controller.rb diff --git a/app/assets/javascripts/tag_autocomplete.js.coffee b/app/assets/javascripts/tag_autocomplete.js.coffee index 9e10c100e..be27cd81c 100644 --- a/app/assets/javascripts/tag_autocomplete.js.coffee +++ b/app/assets/javascripts/tag_autocomplete.js.coffee @@ -7,13 +7,18 @@ App.TagAutocomplete = return (App.TagAutocomplete.split( term ).pop()) init_autocomplete: -> - $('.js-tag-list').autocomplete + $('.tag-autocomplete').autocomplete source: (request, response) -> - response( $.ui.autocomplete.filter(["Arbol", "Becerro", "Caracol"], App.TagAutocomplete.extractLast( request.term ) ) ); + $.ajax + url: $('.tag-autocomplete').data('js-url'), + data: {search: App.TagAutocomplete.extractLast( request.term )}, + type: 'GET', + dataType: 'json' + success: ( data ) -> + response( data ); + minLength: 0, search: -> - console.log(this.value); - console.log(App.TagAutocomplete.extractLast( this.value )); App.TagAutocomplete.extractLast( this.value ); focus: -> return false; diff --git a/app/assets/stylesheets/autocomplete_overrides.scss b/app/assets/stylesheets/autocomplete_overrides.scss index 68537fd8a..9eac7162b 100644 --- a/app/assets/stylesheets/autocomplete_overrides.scss +++ b/app/assets/stylesheets/autocomplete_overrides.scss @@ -4,7 +4,6 @@ /* Autocomplete ----------------------------------*/ .ui-autocomplete { position: absolute; cursor: default; } -.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; } /* workarounds */ * html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */ @@ -13,29 +12,23 @@ ----------------------------------*/ .ui-menu { list-style:none; - padding: 0px 5px; - margin: 0; + padding: $line-height / 4 $line-height / 3; display:block; - /*width:227px;*/ background: white; border: 1px solid $border; -} -.ui-menu .ui-menu { - margin-top: -3px; -} -.ui-menu .ui-menu-item { - margin:0; - padding: 0; - width: 200px; -} -.ui-menu .ui-menu-item a { - /* text-decoration:none; - display:block;*/ - padding:.2em .4em; - /* line-height:1.5; - zoom:1;*/ -} -.ui-menu .ui-menu-item a.ui-state-hover, -.ui-menu .ui-menu-item a.ui-state-active { - margin: -1px; + font-size: $small-font-size; + + .ui-menu-item { + + .ui-menu-item-wrapper { + padding: $line-height / 4 $line-height / 3; + position: relative; + } + + .ui-state-hover, .ui-state-active { + background: #ececec; + border-radius: rem-calc(6); + } + } + } \ No newline at end of file diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 000000000..c58067048 --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,11 @@ +class TagsController < ApplicationController + + load_and_authorize_resource class: ActsAsTaggableOn::Tag + respond_to :json + + def suggest + @tags = ActsAsTaggableOn::Tag.search(params[:search]).map(&:name) + respond_with @tags + end + +end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 620cfb212..0df92616d 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -24,6 +24,7 @@ module Abilities can :suggest, Debate can :suggest, Proposal + can :suggest, ActsAsTaggableOn::Tag can [:flag, :unflag], Comment cannot [:flag, :unflag], Comment, user_id: user.id diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 28ef69804..a98611011 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -23,7 +23,8 @@ label: false, placeholder: t("debates.form.tags_placeholder"), aria: {describedby: "tag-list-help-text"}, - data: {js_url: tags_search_path}%> + data: {js_url: suggest_tags_path}, + class: 'tag-autocomplete'%>
    <% if @debate.new_record? %> diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 73b39dfdb..b46dbc69e 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -70,8 +70,9 @@ <%= f.text_field :tag_list, value: @proposal.tag_list.to_s, label: false, placeholder: t("proposals.form.tags_placeholder"), - class: 'js-tag-list', - aria: {describedby: "tag-list-help-text"} %> + class: 'js-tag-list tag-autocomplete', + aria: {describedby: "tag-list-help-text"}, + data: {js_url: suggest_tags_path} %>
    <% if current_user.unverified? %> diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 57766c8c9..018319442 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -43,6 +43,18 @@ module ActsAsTaggableOn Tagging.public_for_api.pluck('DISTINCT taggings.tag_id')) end + include PgSearch + + pg_search_scope :pg_search, against: :name, + using: { + tsearch: {prefix: true} + }, + ignoring: :accents + + def self.search(term) + pg_search(term) + end + def increment_custom_counter_for(taggable_type) Tag.increment_counter(custom_counter_field_name_for(taggable_type), id) end @@ -78,6 +90,7 @@ module ActsAsTaggableOn end private + def custom_counter_field_name_for(taggable_type) "#{taggable_type.underscore.pluralize}_count" end diff --git a/config/routes.rb b/config/routes.rb index 666285496..7b1c1cac0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,17 +6,17 @@ Rails.application.routes.draw do end devise_for :users, controllers: { - registrations: 'users/registrations', - sessions: 'users/sessions', - confirmations: 'users/confirmations', - omniauth_callbacks: 'users/omniauth_callbacks' - } + registrations: 'users/registrations', + sessions: 'users/sessions', + confirmations: 'users/confirmations', + omniauth_callbacks: 'users/omniauth_callbacks' + } devise_for :organizations, class_name: 'User', - controllers: { - registrations: 'organizations/registrations', - sessions: 'devise/sessions', - }, - skip: [:omniauth_callbacks] + controllers: { + registrations: 'organizations/registrations', + sessions: 'devise/sessions' + }, + skip: [:omniauth_callbacks] devise_scope :organization do get 'organizations/sign_up/success', to: 'organizations/registrations#success' @@ -167,11 +167,12 @@ Rails.application.routes.draw do resource :email, controller: "email", only: [:new, :show, :create] resource :letter, controller: "letter", only: [:new, :create, :show, :edit, :update] end - - namespace :tags do - get :search - end + resources :tags do + collection do + get :suggest + end + end namespace :admin do root to: "dashboard#index" @@ -435,9 +436,7 @@ Rails.application.routes.draw do get '/graphql', to: 'graphql#query' post '/graphql', to: 'graphql#query' - if Rails.env.development? - mount LetterOpenerWeb::Engine, at: "/letter_opener" - end + mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql' diff --git a/spec/lib/acts_as_taggable_on_spec.rb b/spec/lib/acts_as_taggable_on_spec.rb index 761e90553..de53b35e7 100644 --- a/spec/lib/acts_as_taggable_on_spec.rb +++ b/spec/lib/acts_as_taggable_on_spec.rb @@ -133,6 +133,21 @@ describe 'ActsAsTaggableOn' do expect(ActsAsTaggableOn::Tag.public_for_api).to be_empty end end + + describe "search" do + it "containing the word in the name" do + create(:tag, name: 'Familia') + create(:tag, name: 'Cultura') + create(:tag, name: 'Salud') + create(:tag, name: 'Famosos') + + expect(ActsAsTaggableOn::Tag.pg_search('f').length).to eq(2) + expect(ActsAsTaggableOn::Tag.search('cultura').first.name).to eq('Cultura') + expect(ActsAsTaggableOn::Tag.search('sal').first.name).to eq('Salud') + expect(ActsAsTaggableOn::Tag.search('fami').first.name).to eq('Familia') + end + end + end end From c01208b203a319feac420fc0a78ee26239ffab2d Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 21 Sep 2017 18:27:52 +0200 Subject: [PATCH 075/765] Autocomplete tags for investments projects --- app/views/budgets/investments/_form.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 7cf2bb1e2..8f98b9d5c 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -49,7 +49,8 @@ label: false, placeholder: t("budgets.investments.form.tags_placeholder"), aria: {describedby: "tags-list-help-text"}, - class: 'js-tag-list' %> + class: 'js-tag-list tag-autocomplete', + data: {js_url: suggest_tags_path} %>
    From f3229007e8ba0c0853ea4b03b2bc8df22fe301e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 21:28:54 +0200 Subject: [PATCH 076/765] Run pending migrations --- db/schema.rb | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 41952607e..acacbf347 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170915101519) do +ActiveRecord::Schema.define(version: 20170918231410) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -620,20 +620,6 @@ ActiveRecord::Schema.define(version: 20170915101519) do t.string "location" end - create_table "poll_final_recounts", force: :cascade do |t| - t.integer "booth_assignment_id" - t.integer "officer_assignment_id" - t.integer "count" - t.text "count_log", default: "" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "officer_assignment_id_log", default: "" - t.date "date", null: false - end - - add_index "poll_final_recounts", ["booth_assignment_id"], name: "index_poll_final_recounts_on_booth_assignment_id", using: :btree - add_index "poll_final_recounts", ["officer_assignment_id"], name: "index_poll_final_recounts_on_officer_assignment_id", using: :btree - create_table "poll_null_results", force: :cascade do |t| t.integer "author_id" t.integer "amount" @@ -725,6 +711,21 @@ ActiveRecord::Schema.define(version: 20170915101519) do add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree + create_table "poll_total_results", force: :cascade do |t| + t.integer "author_id" + t.integer "amount" + t.string "origin" + t.date "date" + t.integer "booth_assignment_id" + t.integer "officer_assignment_id" + t.text "amount_log", default: "" + t.text "officer_assignment_id_log", default: "" + t.text "author_id_log", default: "" + end + + add_index "poll_total_results", ["booth_assignment_id"], name: "index_poll_total_results_on_booth_assignment_id", using: :btree + add_index "poll_total_results", ["officer_assignment_id"], name: "index_poll_total_results_on_officer_assignment_id", using: :btree + create_table "poll_voters", force: :cascade do |t| t.string "document_number" t.string "document_type" @@ -1010,7 +1011,7 @@ ActiveRecord::Schema.define(version: 20170915101519) do t.boolean "email_digest", default: true t.boolean "email_on_direct_message", default: true t.boolean "official_position_badge", default: false - t.datetime "password_changed_at", default: '2017-09-06 18:19:39', null: false + t.datetime "password_changed_at", default: '2015-01-01 00:01:01', null: false t.boolean "created_from_signature", default: false t.integer "failed_email_digests_count", default: 0 t.text "former_users_data_log", default: "" @@ -1123,8 +1124,6 @@ ActiveRecord::Schema.define(version: 20170915101519) do add_foreign_key "organizations", "users" add_foreign_key "poll_answers", "poll_questions", column: "question_id" add_foreign_key "poll_booth_assignments", "polls" - add_foreign_key "poll_final_recounts", "poll_booth_assignments", column: "booth_assignment_id" - add_foreign_key "poll_final_recounts", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_null_results", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_null_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_officer_assignments", "poll_booth_assignments", column: "booth_assignment_id" From 0948959a65318284014ad5cff4723285d04e01b1 Mon Sep 17 00:00:00 2001 From: iagirre Date: Fri, 22 Sep 2017 08:09:03 +0200 Subject: [PATCH 077/765] Run scss-lint to fix some errors in autocomplete_overrides.scss --- .../stylesheets/autocomplete_overrides.scss | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/autocomplete_overrides.scss b/app/assets/stylesheets/autocomplete_overrides.scss index 9eac7162b..dd2b939ad 100644 --- a/app/assets/stylesheets/autocomplete_overrides.scss +++ b/app/assets/stylesheets/autocomplete_overrides.scss @@ -3,18 +3,23 @@ /* Autocomplete ----------------------------------*/ -.ui-autocomplete { position: absolute; cursor: default; } +.ui-autocomplete { + position: absolute; + cursor: default; +} /* workarounds */ -* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */ +* html .ui-autocomplete { + width: 1px; +} /* without this, the menu expands to 100% in IE6 */ /* Menu ----------------------------------*/ .ui-menu { - list-style:none; + list-style: none; padding: $line-height / 4 $line-height / 3; - display:block; - background: white; + display: block; + background: #fff; border: 1px solid $border; font-size: $small-font-size; @@ -25,10 +30,11 @@ position: relative; } - .ui-state-hover, .ui-state-active { + .ui-state-hover, + .ui-state-active { background: #ececec; border-radius: rem-calc(6); } } -} \ No newline at end of file +} From ebfa3fb011b200b89a902160f70bbfbc8c4e7a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 11:39:17 +0200 Subject: [PATCH 078/765] Disallow users to edit their legislation proposals --- app/models/abilities/common.rb | 2 +- app/models/abilities/everyone.rb | 2 +- app/views/legislation/proposals/show.html.erb | 12 ------------ 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 459b779c7..2de8e4c79 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -19,7 +19,7 @@ module Abilities can [:retire_form, :retire], Proposal, author_id: user.id can :read, Legislation::Proposal - can :update, Legislation::Proposal do |proposal| + cannot [:edit, :update], Legislation::Proposal do |proposal| proposal.editable_by?(user) end can [:retire_form, :retire], Legislation::Proposal, author_id: user.id diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index e16a53cec..c97bf0d94 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -18,7 +18,7 @@ module Abilities can [:read, :print], Budget::Investment can :read_results, Budget, phase: "finished" can :new, DirectMessage - can [:read, :debate, :draft_publication, :allegations, :result_publication], Legislation::Process, published: true + can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals], Legislation::Process, published: true can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index f3692e3c7..48dae91b6 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -16,18 +16,6 @@
    <%= back_link_to %> - <% if can?(:create, @document) && @proposal.documents.size < Proposal.max_documents_allowed %> - <%= link_to t("documents.upload_document"), - new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url), - class: 'button hollow float-right' %> - <% end %> - - <% if current_user && @proposal.editable_by?(current_user) %> - <%= link_to edit_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal), class: 'edit-proposal button hollow float-right' do %> - <%= t("proposals.show.edit_proposal_link") %> - <% end %> - <% end %> -

    <%= @proposal.title %>

    <% if @proposal.conflictive? %>
    From 3c4f2426db7d11d5f4cb0c72b9459dcf1f93ce6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 11:39:30 +0200 Subject: [PATCH 079/765] Removed unnecessary content --- app/controllers/legislation/proposals_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index f924cb25f..85072a419 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -53,11 +53,6 @@ class Legislation::ProposalsController < Legislation::BaseController end end - def summary - @proposals = Legislation::Proposal.for_summary - @tag_cloud = tag_cloud - end - private def proposal_params From 02fa3a83b5329a9aa82d4571b1016b38c51f95e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 17:16:04 +0200 Subject: [PATCH 080/765] Custom tags for Legislation Process available Custom tags for Legislation Processes, editable in the admin section. --- .../admin/legislation/processes_controller.rb | 10 +++++++++- app/helpers/tags_helper.rb | 2 ++ app/models/legislation/process.rb | 5 ++++- .../admin/legislation/proposals/_form.html.erb | 14 ++++++++++++++ app/views/legislation/proposals/_form.html.erb | 4 ++-- ...1247_add_legislation_processes_count_to_tags.rb | 6 ++++++ db/schema.rb | 4 +++- 7 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index f316d9b65..0e7555211 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -19,6 +19,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def update if @process.update(process_params) + set_tag_list + link = legislation_process_path(@process).html_safe redirect_to :back, notice: t('admin.legislation.processes.update.notice', link: link) else @@ -56,7 +58,13 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :draft_publication_enabled, :result_publication_enabled, :published, - :proposals_description + :proposals_description, + :custom_list ) end + + def set_tag_list + @process.set_tag_list_on(:customs, process_params[:custom_list]) + @process.save + end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index eb34a64f2..b31f3167f 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -24,6 +24,8 @@ module TagsHelper proposal_path(taggable) when 'budget/investment' budget_investment_path(taggable.budget_id, taggable) + when 'legislation/proposal' + legislation_process_proposal_path(@process, taggable) else '#' end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 7e1e884cb..d6eed62db 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -1,6 +1,9 @@ class Legislation::Process < ActiveRecord::Base - acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + include Taggable + + acts_as_paranoid column: :hidden_at + acts_as_taggable_on :customs PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb index 30f7f4950..343164587 100644 --- a/app/views/admin/legislation/proposals/_form.html.erb +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -28,6 +28,20 @@
    +
    +
    + <%= label_tag t('admin.legislation.proposals.form.header_information') %> + <%= t('admin.legislation.proposals.form.header_information_description') %> +
    +
    + <%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s, + label: false, + placeholder: t("proposals.form.tags_placeholder"), + class: 'js-tag-list', + aria: {describedby: "tag-list-help-text"} %> +
    +
    +
    <%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index dec8e56d2..798266ba1 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -63,8 +63,8 @@
    <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %> - <% @categories.each do |tag| %> - <%= tag.name %> + <% @process.tag_list_on(:customs).each do |tag| %> + <%= tag %> <% end %>
    diff --git a/db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb b/db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb new file mode 100644 index 000000000..698a66af6 --- /dev/null +++ b/db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb @@ -0,0 +1,6 @@ +class AddLegislationProcessesCountToTags < ActiveRecord::Migration + def change + add_column :tags, "legislation/processes_count", :integer, default: 0 + add_index :tags, "legislation/processes_count" + end +end diff --git a/db/schema.rb b/db/schema.rb index acacbf347..df544e28a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170918231410) do +ActiveRecord::Schema.define(version: 20170922101247) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -936,9 +936,11 @@ ActiveRecord::Schema.define(version: 20170918231410) do t.string "kind" t.integer "budget/investments_count", default: 0 t.integer "legislation/proposals_count", default: 0 + t.integer "legislation/processes_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree + add_index "tags", ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree From a870f35de8d9f2c98e55e2599896639c9bd35a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 17:21:55 +0200 Subject: [PATCH 081/765] Added translations --- app/views/admin/legislation/proposals/_form.html.erb | 4 ++-- config/locales/en/admin.yml | 2 ++ config/locales/es/admin.yml | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb index 343164587..dd12f9492 100644 --- a/app/views/admin/legislation/proposals/_form.html.erb +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -30,8 +30,8 @@
    - <%= label_tag t('admin.legislation.proposals.form.header_information') %> - <%= t('admin.legislation.proposals.form.header_information_description') %> + <%= label_tag t('admin.legislation.proposals.form.custom_categories') %> + <%= t('admin.legislation.proposals.form.custom_categories_description') %>
    <%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s, diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0953be816..42d18219d 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -300,6 +300,8 @@ en: header_information: Information header header_information_description: Provide information about the proposals. This text will be displayed as an alert in the Proposals section inside this Process. Use Markdown to format the text. header_information_placeholder: Add information for the proposals' header + custom_categories: Categories + custom_categories_description: Categories that users can select creating the proposal. draft_versions: create: notice: 'Draft created successfully. Click to visit' diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 679e41b6c..548cbc98b 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -300,6 +300,8 @@ es: header_information: Encabezado de información header_information_description: Proporciona información sobre el recorrido de las propuestas. Este texto se mostrará como una alerta en el encabezado de la sección de Propuestas dentro de este proceso. Usa Markdown para formatear el texto. header_information_placeholder: Añade información para el encabezado de las las propuestas + custom_categories: Categorías + custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta. draft_versions: create: notice: 'Borrador creado correctamente. Haz click para verlo' From 2629837306fdfb97a6244e55a5cdad373fe8ff62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 17:25:33 +0200 Subject: [PATCH 082/765] Fixed admin menu active states --- app/helpers/admin_helper.rb | 4 ++-- app/views/admin/_menu.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index f9c2e8c69..06fb158a4 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -17,7 +17,7 @@ module AdminHelper end def menu_moderated_content? - ["proposals", "debates", "comments", "hidden_users"].include? controller_name + ["proposals", "debates", "comments", "hidden_users"].include? controller_name && controller.class.parent != Admin::Legislation end def menu_budget? @@ -39,7 +39,7 @@ module AdminHelper def menu_customization? ["pages", "images", "content_blocks"].include? controller_name end - + def official_level_options options = [["", 0]] (1..5).each do |i| diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 11d58adc8..168f8c31b 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -19,7 +19,7 @@ <%= t("admin.menu.title_moderated_content") %>
      > -
    • > +
    • > <%= link_to t("admin.menu.hidden_proposals"), admin_proposals_path %>
    • From 3c2b5281e8d2a4bd159bb2e30ad190ea5ea18cd4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 22 Sep 2017 18:05:53 +0200 Subject: [PATCH 083/765] Fix Admin Polls menu active flags --- app/views/admin/_menu.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 11d58adc8..a2173edf6 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -60,12 +60,12 @@ <%= t("admin.menu.title_polls") %> -
        > +
          >
        • > <%= link_to t('admin.menu.polls'), admin_polls_path %>
        • -
        • > +
        • > <%= link_to t("admin.menu.poll_questions"), admin_questions_path %>
        • From ad63b0a7d7ff673a3ffcca9bedf393ff7927723a Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 22 Sep 2017 18:20:21 +0200 Subject: [PATCH 084/765] makes filter subnav same style than order links --- app/assets/stylesheets/layout.scss | 27 +++++++++++++++++++++--- app/views/shared/_filter_subnav.html.erb | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 9ecf74442..5c7854758 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -205,19 +205,40 @@ a { .menu.simple { border-bottom: 1px solid $border; - margin-bottom: $line-height; + clear: both; + margin-bottom: $line-height / 2; li { - padding-bottom: rem-calc(7); + margin-right: $line-height / 2; + + @include breakpoint(medium) { + margin-right: $line-height * 1.5; + } a { - color: $text-medium; + color: $text; + display: inline-block; + font-weight: bold; + position: relative; + text-align: left; + + &:hover { + color: $link; + } } &.active { border-bottom: 2px solid $brand; color: $brand; } + + &:not(.active) { + margin-bottom: $line-height / 3; + } + } + + h2 { + font-size: $base-font-size; } } diff --git a/app/views/shared/_filter_subnav.html.erb b/app/views/shared/_filter_subnav.html.erb index 7364015e2..5a7e4d9d5 100644 --- a/app/views/shared/_filter_subnav.html.erb +++ b/app/views/shared/_filter_subnav.html.erb @@ -3,7 +3,7 @@ <% @valid_filters.each do |filter| %> <% if @current_filter == filter %> -
        • <%= t("#{i18n_namespace}.filters.#{filter}") %>
        • +
        • <%= t("#{i18n_namespace}.filters.#{filter}") %>

        • <% else %>
        • <%= link_to t("#{i18n_namespace}.filters.#{filter}"), current_path_with_query_params(filter: filter, page: 1) %>
        • From e404d149ce0ce0fd7f66bb9625f16b9ce8d3f32d Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 22 Sep 2017 19:10:39 +0200 Subject: [PATCH 085/765] fixes some lint errors on legislation_process.scss --- .../stylesheets/legislation_process.scss | 70 +++++++++---------- .../legislation/draft_versions/show.html.erb | 2 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 2ec9f8ee9..0e73321d3 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -459,11 +459,11 @@ $border-dark: darken($border, 10%); span { vertical-align: inherit; font-style: normal; + } - a { - text-decoration: underline; - color: $text-medium; - } + .see-changes { + color: $text-medium; + text-decoration: underline; } } @@ -477,6 +477,7 @@ $border-dark: darken($border, 10%); } .draft-allegation { + @include breakpoint(medium) { display: flex; padding-left: 0.9375rem; @@ -493,7 +494,6 @@ $border-dark: darken($border, 10%); } } - // Panel calcs for desktop @media screen and (min-width: 40em) { .calc-index { width: calc(35% - 25px); @@ -509,6 +509,7 @@ $border-dark: darken($border, 10%); width: rem-calc(50); .draft-panel { + .panel-title { display: none; } @@ -912,19 +913,15 @@ $border-dark: darken($border, 10%); display: inline-block; } } - - .show-for-medium { - .panel-title { - display: none; - } - } } } } // 08. Legislation changes // ----------------- + .legislation-changes { + ul { list-style: none; margin-left: 0; @@ -936,35 +933,36 @@ $border-dark: darken($border, 10%); margin-right: 0.25rem; content: '—'; } + } + } - .changes-link { - display: block; - margin-left: 1rem; - font-size: $small-font-size; + .changes-link { + display: block; + margin-left: 1rem; + font-size: $small-font-size; - @include breakpoint(medium) { - display: inline-block; - } + @include breakpoint(medium) { + display: inline-block; + } - a { - span { - text-decoration: underline; - } + a { - .icon-external { - text-decoration: none; - color: #999; - line-height: 0; - vertical-align: sub; - margin-left: 0.5rem; - } + span { + text-decoration: underline; + } - &:active, - &:focus, - &:hover { - text-decoration: none; - } - } + .icon-external { + text-decoration: none; + color: #999; + line-height: 0; + vertical-align: sub; + margin-left: 0.5rem; + } + + &:active, + &:focus, + &:hover { + text-decoration: none; } } } @@ -972,6 +970,7 @@ $border-dark: darken($border, 10%); // 09. Legislation comments // ----------------- + .legislation-comments { .pull-right { @@ -1020,6 +1019,7 @@ $border-dark: darken($border, 10%); // 10. Legislation draft comment // ----------------- + .legislation-comment { .annotation-share-comment { diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index b3067049b..d380e5cc3 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -15,7 +15,7 @@ <%= submit_tag t('.select_version_submit'), class: "button" %> <% end %> <% if @draft_version.changelog.present? %> - <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> + <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version), class: "see-changes" %> <% end %>
    <%= t('.updated_at', date: format_date(@draft_version.updated_at)) %> From bf981ca828ad40dc4df0fa1faf7d23b596a968bd Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 17:33:17 +0200 Subject: [PATCH 086/765] Remove Booth Assignment officer totals and add final&system counts --- .../poll/booth_assignments/show.html.erb | 23 +++++++++++++------ config/locales/en/admin.yml | 3 ++- config/locales/es/admin.yml | 3 ++- .../admin/poll/booth_assigments_spec.rb | 22 ++++++++++++------ 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index b6917bca6..f01270bd4 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -45,25 +45,34 @@

    <%= t("admin.poll_booth_assignments.show.recounts_list") %>

    + + + + + + + + + + + + + + +
    <%= t("admin.poll_booth_assignments.show.count_final") %><%= t("admin.poll_booth_assignments.show.total_system") %>
    <%= total_recounts_by_booth(@booth_assignment) || '-' %><%= @booth_assignment.voters.count %>
    + - <% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %> - <% total_recount = @booth_assignment.total_results.where(date: voting_date).first %> <% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %> - <% if total_recount.present? %> - - <% else %> - - <% end %> <% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8bbe1a5c8..f233579c9 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -532,8 +532,9 @@ en: recounts: "Recounts" recounts_list: "Recount list for this booth" date: "Date" - total_recount: "Total recount (by officer)" + count_final: "Final recount (by officer)" count_by_system: "Votes (automatic)" + total_system: Total votes (automatic) index: booths_title: "List of booths" no_booths: "There are no booths assigned to this poll." diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 93d2d6532..ec804132d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -532,8 +532,9 @@ es: recounts: "Recuentos" recounts_list: "Lista de recuentos de esta urna" date: "Fecha" - total_recount: "Recuento total (presidente de mesa)" + count_final: "Recuento final (presidente de mesa)" count_by_system: "Votos (automático)" + total_system: "Votos totales acumulados(automático)" index: booths_title: "Listado de urnas asignadas" no_booths: "No hay urnas asignadas a esta votación." diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 09a21dd72..77881efaa 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -97,11 +97,8 @@ feature 'Admin booths assignments' do officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.ends_at) final_officer_assignment = create(:poll_officer_assignment, :final, booth_assignment: booth_assignment, date: poll.ends_at) - total_recount = create(:poll_total_result, - booth_assignment: booth_assignment, - officer_assignment: final_officer_assignment, - date: final_officer_assignment.date, - amount: 5678) + create(:poll_voter, poll: poll, booth_assignment: booth_assignment, created_at: poll.starts_at.to_date) + create(:poll_voter, poll: poll, booth_assignment: booth_assignment, created_at: poll.ends_at.to_date) booth_assignment_2 = create(:poll_booth_assignment, poll: poll) @@ -111,9 +108,20 @@ feature 'Admin booths assignments' do within('#assigned_booths_list') { click_link booth.name } click_link 'Recounts' + + within('#totals') do + within("#total_system") { expect(page).to have_content "2" } + end + within('#recounts_list') do - within("#recounting_#{total_recount.date.strftime('%Y%m%d')}") do - expect(page).to have_content total_recount.amount + within("#recounting_#{poll.starts_at.to_date.strftime('%Y%m%d')}") do + expect(page).to have_content 1 + end + within("#recounting_#{(poll.ends_at.to_date - 5.days).strftime('%Y%m%d')}") do + expect(page).to have_content '-' + end + within("#recounting_#{poll.ends_at.to_date.strftime('%Y%m%d')}") do + expect(page).to have_content 1 end end end From 7827f6edd1df7dff693522fa8e8723a3c99e31e1 Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 25 Sep 2017 19:17:48 +0200 Subject: [PATCH 087/765] fixes icon notifications on admin header --- app/assets/stylesheets/admin.scss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 964e1348e..3dcf4a474 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -48,11 +48,7 @@ $sidebar-active: #f4fcd0; color: #000; height: auto; - span { - padding-top: $line-height / 2; - } - - [class^="icon-"] { + [class^="icon-"]:not(.icon-circle) { font-size: $base-font-size; } } @@ -104,6 +100,10 @@ $sidebar-active: #f4fcd0; } } + .notifications .icon-circle { + color: $admin-color; + } + .dropdown.menu > .is-dropdown-submenu-parent > a::after { border-color: #000 transparent transparent; } From 9de8ef2e141389c2b6a6970395b6e93ecfd3f977 Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 25 Sep 2017 19:40:24 +0200 Subject: [PATCH 088/765] sets data-multi-open to false on admin menu --- app/views/admin/_menu.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index a2173edf6..bb246cb6c 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -1,5 +1,5 @@
    -
    +
    + <%= render 'images/nested_images', imageable: @proposal %> +
    +
    <%= render 'documents/nested_documents', documentable: @proposal %>
    diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 4b0cfe6f7..e0143fd08 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -48,6 +48,8 @@ + <%= render_image(@proposal.image, :large, true) if @proposal.image.present? %> +

    <%= t("proposals.show.code") %> @@ -106,7 +108,8 @@

    + @@ -12,6 +13,7 @@ +
    <%= t("admin.poll_booth_assignments.show.date") %><%= t("admin.poll_booth_assignments.show.total_recount") %> <%= t("admin.poll_booth_assignments.show.count_by_system") %>
    <%= l voting_date %><%= total_recount.amount %> - <%= system_count %>
    <%= t("admin.poll_shifts.new.date") %> <%= t("admin.poll_shifts.new.officer") %><%= t("admin.poll_shifts.new.task") %> <%= t("admin.poll_shifts.new.shift") %>
    <%= l(shift.date.to_date, format: :long) %> <%= shift.officer_name %><%= t("admin.poll_shifts.#{shift.task}") %> <%= link_to t("admin.poll_shifts.new.remove_shift"), admin_booth_shift_path(@booth, shift), diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 236ffd51e..0b578feb0 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -503,6 +503,7 @@ en: shift: "Assignment" shifts: "Shifts in this booth" date: "Date" + task: "Task" edit_shifts: Edit shifts new_shift: "New shift" no_shifts: "This booth has no shifts" @@ -512,12 +513,15 @@ en: search_officer_placeholder: Search officer search_officer_text: Search for an officer to assign a new shift select_date: "Select day" + select_task: "Select task" table_shift: "Shift" table_email: "Email" table_name: "Name" flash: create: "Shift added" destroy: "Shift removed" + vote_collection: Collect Votes + recount_scrutiny: Recount & Scrutiny poll_booth_assignments: flash: destroy: "Booth not assigned anymore" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 91af8db6c..b2d0e658c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -503,6 +503,7 @@ es: shift: "Asignación" shifts: "Turnos en esta urna" date: "Fecha" + task: "Tarea" edit_shifts: Asignar turno new_shift: "Nuevo turno" no_shifts: "Esta urna no tiene turnos asignados" @@ -512,12 +513,15 @@ es: search_officer_placeholder: Buscar presidentes de mesa search_officer_text: Busca al presidente de mesa para asignar un turno select_date: "Seleccionar día" + select_task: "Seleccionar tarea" table_shift: "Turno" table_email: "Email" table_name: "Nombre" flash: create: "Añadido turno de presidente de mesa" destroy: "Eliminado turno de presidente de mesa" + vote_collection: Recoger Votos + recount_scrutiny: Recuento & Escrutinio poll_booth_assignments: flash: destroy: "Urna desasignada" From 6c1d1c2cdea001c59d8ff39833f3f28693ab1c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 3 Aug 2017 19:46:23 +0200 Subject: [PATCH 191/765] Add map settings to backend. Install leaflet assets to render maps. --- Gemfile | 3 ++ Gemfile.lock | 2 + app/assets/javascripts/application.js | 3 ++ app/assets/javascripts/map.js.coffee | 44 ++++++++++++++++++++ app/assets/stylesheets/admin.scss | 36 ++++++++++++++++ app/assets/stylesheets/application.scss | 1 + app/controllers/admin/settings_controller.rb | 7 ++++ app/views/admin/settings/_map_form.html.erb | 31 ++++++++++++++ app/views/admin/settings/index.html.erb | 8 ++++ config/locales/en/admin.yml | 15 +++++-- config/locales/en/settings.yml | 1 + config/locales/es/admin.yml | 7 ++++ config/locales/es/settings.yml | 1 + config/routes.rb | 2 + db/dev_seeds.rb | 4 ++ db/seeds.rb | 6 +++ spec/features/admin/settings_spec.rb | 35 ++++++++++++++++ 17 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/map.js.coffee create mode 100644 app/views/admin/settings/_map_form.html.erb diff --git a/Gemfile b/Gemfile index a6c1dc71e..d4a2777a9 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,9 @@ gem 'turnout', '~> 2.4.0' gem 'uglifier', '~> 3.2.0' gem 'unicorn', '~> 5.3.0' gem 'whenever', '~> 0.9.7', require: false +source 'https://rails-assets.org' do + gem 'rails-assets-leaflet' +end group :development, :test do gem "bullet", '~> 5.5.1' diff --git a/Gemfile.lock b/Gemfile.lock index f15f0c6e9..6435af58e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -334,6 +334,7 @@ GEM bundler (>= 1.3.0, < 2.0) railties (= 4.2.9) sprockets-rails + rails-assets-leaflet (1.1.0) rails-assets-markdown-it (8.2.2) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -542,6 +543,7 @@ DEPENDENCIES poltergeist (~> 1.15.0) quiet_assets (~> 1.1.0) rails (= 4.2.9) + rails-assets-leaflet! rails-assets-markdown-it (~> 8.2.1)! redcarpet (~> 3.4.0) responders (~> 2.4.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0b3ee0201..d7c36e944 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -67,6 +67,8 @@ //= require tree_navigator //= require custom //= require tag_autocomplete +//= require leaflet +//= require map var initialize_modules = function() { App.Comments.initialize(); @@ -103,6 +105,7 @@ var initialize_modules = function() { App.Documentable.initialize(); App.Imageable.initialize(); App.TagAutocomplete.initialize(); + App.Map.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/map.js.coffee b/app/assets/javascripts/map.js.coffee new file mode 100644 index 000000000..c3821e338 --- /dev/null +++ b/app/assets/javascripts/map.js.coffee @@ -0,0 +1,44 @@ +App.Map = + + initialize: -> + maps = $('*[data-map]') + + if maps.length > 0 + $.each maps, (index, map) -> + App.Map.initializeMap map + + initializeMap: (element) -> + latitude = $(element).data('latitude') + longitude = $(element).data('longitude') + zoom = $(element).data('zoom') + mapTilesProvider = $(element).data('tiles-provider') + mapAttributionSelector = $(element).data('tiles-attribution-selector') + latitudeInputSelector = $(element).data('latitude-input-selector') + longitudeInputSelector = $(element).data('longitude-input-selector') + zoomInputSelector = $(element).data('zoom-input-selector') + + latLng = new (L.LatLng)(latitude, longitude) + map = L.map(element.id).setView(latLng, zoom) + attribution = $(mapAttributionSelector) + L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map + + marker_icon = L.divIcon( + iconSize: null + html: '
    ') + marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' }) + marker.addTo(map) + + onMapClick = (e) -> + marker.setLatLng(e.latlng) + updateFormfields() + return + + updateFormfields = -> + $(latitudeInputSelector).val marker.getLatLng().lat + $(longitudeInputSelector).val marker.getLatLng().lng + $(zoomInputSelector).val map.getZoom() + return + + marker.on 'dragend', updateFormfields + map.on 'zoomend', updateFormfields + map.on 'click', onMapClick \ No newline at end of file diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 3dcf4a474..2ef6fea23 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -8,6 +8,7 @@ // 06. Polls // 07. Legislation // 08. CMS +// 09. Map // // 01. Global styles @@ -967,3 +968,38 @@ table { border: 0; } } + +// 09. Map +// -------------- + +.map{ + width: 100%; + height: 350px; + .map-marker { + visibility: visible; + width: 30px; + height: 30px; + border-radius: 50% 50% 50% 0; + background: #00cae9; + position: absolute; + transform: rotate(-45deg); + left: 50%; + top: 50%; + margin: -45px 0 0 -15px; + } + .map-marker:after { + content: ""; + width: 14px; + height: 14px; + margin: 8px 0 0 8px; + background: white; + position: absolute; + border-radius: 50%; + } +} +.map-marker{ + visibility: hidden; +} +.map-attributtion{ + visibility: hidden; +} \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 361dcfde3..aff55c88c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -18,3 +18,4 @@ @import 'datepicker_overrides'; @import 'jquery-ui/autocomplete'; @import 'autocomplete_overrides'; +@import 'leaflet'; diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 70541a3a0..2d69ff19a 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -14,6 +14,13 @@ class Admin::SettingsController < Admin::BaseController redirect_to admin_settings_path, notice: t("admin.settings.flash.updated") end + def update_map + Setting["map.latitude"] = params[:latitude].to_f + Setting["map.longitude"] = params[:longitude].to_f + Setting["map.zoom"] = params[:zoom].to_i + redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update") + end + private def settings_params diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb new file mode 100644 index 000000000..1187cfa96 --- /dev/null +++ b/app/views/admin/settings/_map_form.html.erb @@ -0,0 +1,31 @@ +
    +
    +
    " + data-longitude="<%= Setting["map.longitude"] %>" + data-zoom="<%= Setting["map.zoom"] %>" + data-tiles-attribution-selector="#admin-map-attribution" + data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" + data-latitude-input-selector="#latitude" + data-longitude-input-selector="#longitude" + data-zoom-input-selector="#zoom" + data-marker-selector="#admin-map-marker"> +
    +
    + © OpenStreetMap contributors +
    + + <%= form_tag admin_update_map_path, method: :put, id: 'map-form' do |f| %> + + <%= hidden_field_tag :latitude, Setting["map.latitude"] %> + <%= hidden_field_tag :longitude, Setting["map.longitude"] %> + <%= hidden_field_tag :zoom, Setting["map.zoom"] %> + +
    + <%= submit_tag t("admin.settings.index.map.form.submit"), + class: "button hollow expanded" %> +
    + + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 14c89b776..e49174fca 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -95,3 +95,11 @@
    <% end %> + +<% if feature?(:map) %> +

    <%= t("admin.settings.index.map.title") %>

    +

    <%= t("admin.settings.index.map.help") %>

    + + <%= render "map_form" %> + +<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 236ffd51e..be20333d8 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -40,8 +40,8 @@ en: errors: form: error: - one: "prevented this banner from being saved" - other: 'prevented this banner from being saved' + one: "error prevented this banner from being saved" + other: 'errors prevented this banner from being saved' new: creating: Create banner activity: @@ -697,6 +697,13 @@ en: disabled: "Feature disabled" enable: "Enable" disable: "Disable" + map: + title: Map configuration + help: Here you can customize the way the map is displayed to users. Drag map marker or click anywhere over the map, set desired zoom and click button "Update". + flash: + update: Map configuration updated succesfully. + form: + submit: Update shared: booths_search: button: Search @@ -788,8 +795,8 @@ en: errors: form: error: - one: "prevented this geozone from being saved" - other: 'prevented this geozone from being saved' + one: "error prevented this geozone from being saved" + other: 'errors prevented this geozone from being saved' edit: form: submit_button: Save changes diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index e1d84393f..81ddd57d9 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -40,6 +40,7 @@ en: voting_allowed: Voting on investment projects legislation: Legislation community: Community on proposals and investments + map: Proposals and budget investments geolocation mailer_from_name: Origin email name mailer_from_address: Origin email address meta_description: "Site description (SEO)" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 91af8db6c..f2e38be7f 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -697,6 +697,13 @@ es: disabled: "Funcionalidad desactivada" enable: "Activar" disable: "Desactivar" + map: + title: Configuración del mapa + help: Aquí puedes personalizar la manera en la que se muestra el mapa a los usuarios. Arrastra el marcador o pulsa sobre cualquier parte del mapa, ajusta el zoom y pulsa el botón 'Actualizar'. + flash: + update: La configuración del mapa se ha guardado correctamente. + form: + submit: Actualizar shared: booths_search: button: Buscar diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index f0a7b53a2..e6cfde3b1 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -40,6 +40,7 @@ es: voting_allowed: Votaciones sobre propuestas de inversión legislation: Legislación community: Comunidad en propuestas y proyectos de inversión + map: Geolocalización de propuestas y proyectos de inversión mailer_from_name: Nombre email remitente mailer_from_address: Dirección email remitente meta_description: "Descripción del sitio (SEO)" diff --git a/config/routes.rb b/config/routes.rb index 1cb2d45b9..410f2dced 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -250,6 +250,8 @@ Rails.application.routes.draw do end resources :settings, only: [:index, :update] + put :update_map, to: "settings#update_map" + resources :moderators, only: [:index, :create, :destroy] do get :search, on: :collection end diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 1223d94a4..45b0ed27b 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -37,6 +37,7 @@ Setting.create(key: 'feature.google_login', value: "true") Setting.create(key: 'feature.signature_sheets', value: "true") Setting.create(key: 'feature.legislation', value: "true") Setting.create(key: 'feature.community', value: "true") +Setting.create(key: 'feature.map', value: "true") Setting.create(key: 'per_page_code_head', value: "") Setting.create(key: 'per_page_code_body', value: "") Setting.create(key: 'comments_body_max_length', value: '1000') @@ -47,6 +48,9 @@ Setting.create(key: 'meta_keywords', value: 'citizen participation, open governm Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/') Setting.create(key: 'min_age_to_participate', value: '16') Setting.create(key: 'proposal_improvement_path', value: nil) +Setting.create(key: 'map.latitude', value: 51.48) +Setting.create(key: 'map.longitude', value: 0) +Setting.create(key: 'map.zoom', value: 10) puts " ✅" print "Creating Geozones" diff --git a/db/seeds.rb b/db/seeds.rb index 96916f29a..13a532a92 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -80,6 +80,7 @@ Setting['feature.budgets'] = true Setting['feature.signature_sheets'] = true Setting['feature.legislation'] = true Setting['feature.community'] = true +Setting['feature.map'] = true # Spending proposals feature flags Setting['feature.spending_proposal_features.voting_allowed'] = nil @@ -108,3 +109,8 @@ Setting['min_age_to_participate'] = 16 # Proposal improvement url path ('/more-information/proposal-improvement') Setting['proposal_improvement_path'] = nil + +# City map feature default configuration (Greenwich) +Setting['map.latitude'] = 51.48 +Setting['map.longitude'] = 0 +Setting['map.zoom'] = 10 diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index c92b4b525..0a220d05b 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -28,4 +28,39 @@ feature 'Admin settings' do expect(page).to have_content 'Value updated' end + describe "Update map" do + + scenario "Should not be able when map feature deactivated" do + Setting['feature.map'] = false + admin = create(:administrator).user + login_as(admin) + visit admin_settings_path + + expect(page).not_to have_content "Map configuration" + end + + scenario "Should be able when map feature deactivated" do + Setting['feature.map'] = true + admin = create(:administrator).user + login_as(admin) + visit admin_settings_path + + expect(page).to have_content "Map configuration" + end + + scenario "Should show successful notice" do + Setting['feature.map'] = true + admin = create(:administrator).user + login_as(admin) + visit admin_settings_path + + within "#map-form" do + click_on "Update" + end + + expect(page).to have_content "Map configuration updated succesfully" + end + + end + end \ No newline at end of file From 5956207a0070090ac3228a1e082cafb56d413af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 7 Aug 2017 11:10:38 +0200 Subject: [PATCH 192/765] Add map locations. Each map location can belongs to proposal or budget investment. --- app/assets/javascripts/map.js.coffee | 40 +++++++++++++------ .../budgets/investments_controller.rb | 3 +- app/controllers/proposals_controller.rb | 3 +- app/models/budget/investment.rb | 2 + app/models/map_location.rb | 6 +++ app/models/proposal.rb | 2 + app/views/admin/settings/_map_form.html.erb | 3 +- app/views/budgets/investments/_form.html.erb | 13 ++++++ app/views/map_locations/_form_fields.html.erb | 25 ++++++++++++ app/views/proposals/_form.html.erb | 13 ++++++ config/locales/en/general.yml | 2 + config/locales/es/general.yml | 2 + .../20170805132736_create_map_locations.rb | 11 +++++ db/schema.rb | 11 +++++ 14 files changed, 119 insertions(+), 17 deletions(-) create mode 100644 app/models/map_location.rb create mode 100644 app/views/map_locations/_form_fields.html.erb create mode 100644 db/migrate/20170805132736_create_map_locations.rb diff --git a/app/assets/javascripts/map.js.coffee b/app/assets/javascripts/map.js.coffee index c3821e338..8aca94bc7 100644 --- a/app/assets/javascripts/map.js.coffee +++ b/app/assets/javascripts/map.js.coffee @@ -16,20 +16,15 @@ App.Map = latitudeInputSelector = $(element).data('latitude-input-selector') longitudeInputSelector = $(element).data('longitude-input-selector') zoomInputSelector = $(element).data('zoom-input-selector') + removeMarkerSelector = $(element).data('remove-marker-selector') + attribution = $(mapAttributionSelector) + marker_icon = L.divIcon( + iconSize: null + html: '
    ') - latLng = new (L.LatLng)(latitude, longitude) - map = L.map(element.id).setView(latLng, zoom) - attribution = $(mapAttributionSelector) - L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map - - marker_icon = L.divIcon( - iconSize: null - html: '
    ') - marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' }) - marker.addTo(map) - - onMapClick = (e) -> + placeMarker = (e) -> marker.setLatLng(e.latlng) + marker.addTo(map) updateFormfields() return @@ -39,6 +34,25 @@ App.Map = $(zoomInputSelector).val map.getZoom() return + clearFormfields = -> + $(latitudeInputSelector).val '' + $(longitudeInputSelector).val '' + $(zoomInputSelector).val '' + return + + removeMarker = (e) -> + e.preventDefault() + map.removeLayer(marker) + clearFormfields() + return + + latLng = new (L.LatLng)(latitude, longitude) + map = L.map(element.id).setView(latLng, zoom) + marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' }) + L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map + marker.addTo(map) + + $(removeMarkerSelector).on 'click', removeMarker marker.on 'dragend', updateFormfields map.on 'zoomend', updateFormfields - map.on 'click', onMapClick \ No newline at end of file + map.on 'click', placeMarker \ No newline at end of file diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index fb82c51db..bb00f24af 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -107,7 +107,8 @@ module Budgets .permit(:title, :description, :external_url, :heading_id, :tag_list, :organization_name, :location, :terms_of_service, image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + map_location_attributes: [:latitude, :longitude, :zoom]) end def load_ballot diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 9e6fc521d..d1db0e4a2 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -77,7 +77,8 @@ class ProposalsController < ApplicationController params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :geozone_id, image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] ) + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + map_location_attributes: [:latitude, :longitude, :zoom]) end def retired_params diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 857025375..af8feac1d 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -27,6 +27,8 @@ class Budget has_many :valuators, through: :valuator_assignments has_many :comments, as: :commentable has_many :milestones + has_one :map_location + accepts_nested_attributes_for :map_location validates :title, presence: true validates :author, presence: true diff --git a/app/models/map_location.rb b/app/models/map_location.rb new file mode 100644 index 000000000..61cb10893 --- /dev/null +++ b/app/models/map_location.rb @@ -0,0 +1,6 @@ +class MapLocation < ActiveRecord::Base + + belongs_to :proposal + belongs_to :investment + +end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 7a0abcb6e..7ad7a863b 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -25,6 +25,8 @@ class Proposal < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone + has_one :map_location + accepts_nested_attributes_for :map_location has_many :comments, as: :commentable has_many :proposal_notifications diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 1187cfa96..53eb3d882 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -8,8 +8,7 @@ data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" data-latitude-input-selector="#latitude" data-longitude-input-selector="#longitude" - data-zoom-input-selector="#zoom" - data-marker-selector="#admin-map-marker"> + data-zoom-input-selector="#zoom">
    © OpenStreetMap contributors diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 0d0bdd7f1..789d0f8a9 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -29,6 +29,19 @@ <%= render 'documents/nested_documents', documentable: @investment, f: f %>
    + <% if feature?(:map) %> +
    + + <%= render 'map_locations/form_fields', + form: f, + map_location: @investment.map_location || MapLocation.new, + label: t("proposals.form.map_location"), + help: t("proposals.form.map_location_instructions"), + parent_class: "budget_investment" %> + +
    + <% end %> +
    <%= f.text_field :location %>
    diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb new file mode 100644 index 000000000..7c4a1785e --- /dev/null +++ b/app/views/map_locations/_form_fields.html.erb @@ -0,0 +1,25 @@ +<%= form.label :map_location, label %> +

    <%= help %>

    +
    " + data-longitude="<%= map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] %>" + data-zoom="<%= map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] %>" + data-tiles-attribution-selector="#map-location-attribution" + data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" + data-latitude-input-selector="#<%= parent_class %>_map_location_attributes_latitude" + data-longitude-input-selector="#<%= parent_class %>_map_location_attributes_longitude" + data-zoom-input-selector="#<%= parent_class %>_map_location_attributes_zoom" + data-remove-marker-selector=".location-map-remove-marker-button"> +
    + +
    + © OpenStreetMap contributors +
    + +Remove marker + +<%= form.fields_for :map_location, map_location do |map_location_fields| %> + <%= map_location_fields.hidden_field :latitude, value: map_location.latitude, id: "#{parent_class}_map_location_attributes_latitude" %> + <%= map_location_fields.hidden_field :longitude, value: map_location.longitude, id: "#{parent_class}_map_location_attributes_longitude" %> + <%= map_location_fields.hidden_field :zoom, value: map_location.zoom, id: "#{parent_class}_map_location_attributes_zoom" %> +<% end %> \ No newline at end of file diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index df1e096e9..72feba9c3 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -59,6 +59,19 @@ <%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
    + <% if feature?(:map) %> +
    + + <%= render 'map_locations/form_fields', + form: f, + map_location: @proposal.map_location || MapLocation.new, + label: t("proposals.form.map_location"), + help: t("proposals.form.map_location_instructions"), + parent_class: "proposal" %> + +
    + <% end %> +
    <%= f.label :tag_list, t("proposals.form.tags_label") %>

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

    diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 6312a9a5c..c118db367 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -333,6 +333,8 @@ en: tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own" tags_label: Tags tags_placeholder: "Enter the tags you would like to use, separated by commas (',')" + map_location: "Map location" + map_location_instructions: "Navigate the map to the location and place the marker." index: featured_proposals: Featured filter_topic: diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 4b1ebe2ba..46664e2ae 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -333,6 +333,8 @@ es: tags_label: Temas tag_category_label: "Categorías" tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')" + map_location: "Ubicación en el mapa" + map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador." index: featured_proposals: Destacadas filter_topic: diff --git a/db/migrate/20170805132736_create_map_locations.rb b/db/migrate/20170805132736_create_map_locations.rb new file mode 100644 index 000000000..a75820d54 --- /dev/null +++ b/db/migrate/20170805132736_create_map_locations.rb @@ -0,0 +1,11 @@ +class CreateMapLocations < ActiveRecord::Migration + def change + create_table :map_locations do |t| + t.float :latitude + t.float :longitude + t.integer :zoom + t.integer :proposal_id, index: true + t.integer :investment_id, index: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 41063df03..86d22f3b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -549,6 +549,17 @@ ActiveRecord::Schema.define(version: 20170918231410) do add_index "managers", ["user_id"], name: "index_managers_on_user_id", using: :btree + create_table "map_locations", force: :cascade do |t| + t.float "latitude" + t.float "longitude" + t.integer "zoom" + t.integer "proposal_id" + t.integer "investment_id" + end + + add_index "map_locations", ["investment_id"], name: "index_map_locations_on_investment_id", using: :btree + add_index "map_locations", ["proposal_id"], name: "index_map_locations_on_proposal_id", using: :btree + create_table "moderators", force: :cascade do |t| t.integer "user_id" end From 874a951dd27f5cc9060c1a3df9b6929918b9e994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 7 Aug 2017 11:59:25 +0200 Subject: [PATCH 193/765] Add map locations helper. Allow to configure map marker edition on map instantiation at views. --- app/assets/javascripts/map.js.coffee | 24 ++++++------ app/helpers/map_locations_helper.rb | 19 +++++++++ app/views/budgets/investments/_form.html.erb | 5 ++- app/views/map_locations/_form_fields.html.erb | 39 ++++++++++++------- app/views/proposals/_form.html.erb | 1 + config/locales/en/budgets.yml | 3 ++ config/locales/en/general.yml | 1 + config/locales/es/budgets.yml | 3 ++ config/locales/es/general.yml | 1 + 9 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 app/helpers/map_locations_helper.rb diff --git a/app/assets/javascripts/map.js.coffee b/app/assets/javascripts/map.js.coffee index 8aca94bc7..fb82d0800 100644 --- a/app/assets/javascripts/map.js.coffee +++ b/app/assets/javascripts/map.js.coffee @@ -8,16 +8,17 @@ App.Map = App.Map.initializeMap map initializeMap: (element) -> - latitude = $(element).data('latitude') - longitude = $(element).data('longitude') - zoom = $(element).data('zoom') - mapTilesProvider = $(element).data('tiles-provider') - mapAttributionSelector = $(element).data('tiles-attribution-selector') + latitude = $(element).data('marker-latitude') + longitude = $(element).data('marker-longitude') + zoom = $(element).data('map-zoom') + mapTilesProvider = $(element).data('map-tiles-provider') + mapAttributionSelector = $(element).data('map-tiles-attribution-selector') latitudeInputSelector = $(element).data('latitude-input-selector') longitudeInputSelector = $(element).data('longitude-input-selector') zoomInputSelector = $(element).data('zoom-input-selector') - removeMarkerSelector = $(element).data('remove-marker-selector') + removeMarkerSelector = $(element).data('marker-remove-selector') attribution = $(mapAttributionSelector) + editable = $(element).data('marker-editable') marker_icon = L.divIcon( iconSize: null html: '
    ') @@ -48,11 +49,12 @@ App.Map = latLng = new (L.LatLng)(latitude, longitude) map = L.map(element.id).setView(latLng, zoom) - marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' }) + marker = L.marker(latLng, { icon: marker_icon, draggable: editable }) L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map marker.addTo(map) - $(removeMarkerSelector).on 'click', removeMarker - marker.on 'dragend', updateFormfields - map.on 'zoomend', updateFormfields - map.on 'click', placeMarker \ No newline at end of file + if editable + $(removeMarkerSelector).on 'click', removeMarker + marker.on 'dragend', updateFormfields + map.on 'zoomend', updateFormfields + map.on 'click', placeMarker \ No newline at end of file diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb new file mode 100644 index 000000000..08d16391f --- /dev/null +++ b/app/helpers/map_locations_helper.rb @@ -0,0 +1,19 @@ +module MapLocationsHelper + + def map_location_latitude(map_location) + map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] + end + + def map_location_longitude(map_location) + map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] + end + + def map_location_zoom(map_location) + map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] + end + + def map_location_input_id(prefix, attribute) + "#{prefix}_map_location_attributes_#{attribute}" + end + +end \ No newline at end of file diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 789d0f8a9..8a19c188a 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -35,8 +35,9 @@ <%= render 'map_locations/form_fields', form: f, map_location: @investment.map_location || MapLocation.new, - label: t("proposals.form.map_location"), - help: t("proposals.form.map_location_instructions"), + label: t("budgets.investments.form.map_location"), + help: t("budgets.investments.form.map_location_instructions"), + remove_marker_label: t("budgets.investments.form.map_remove_marker"), parent_class: "budget_investment" %>
    diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index 7c4a1785e..4fcefa2fa 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -1,25 +1,34 @@ <%= form.label :map_location, label %>

    <%= help %>

    -
    " - data-longitude="<%= map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] %>" - data-zoom="<%= map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] %>" - data-tiles-attribution-selector="#map-location-attribution" - data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" - data-latitude-input-selector="#<%= parent_class %>_map_location_attributes_latitude" - data-longitude-input-selector="#<%= parent_class %>_map_location_attributes_longitude" - data-zoom-input-selector="#<%= parent_class %>_map_location_attributes_zoom" - data-remove-marker-selector=".location-map-remove-marker-button"> + +
    © OpenStreetMap contributors
    -Remove marker +<%= remove_marker_label %> -<%= form.fields_for :map_location, map_location do |map_location_fields| %> - <%= map_location_fields.hidden_field :latitude, value: map_location.latitude, id: "#{parent_class}_map_location_attributes_latitude" %> - <%= map_location_fields.hidden_field :longitude, value: map_location.longitude, id: "#{parent_class}_map_location_attributes_longitude" %> - <%= map_location_fields.hidden_field :zoom, value: map_location.zoom, id: "#{parent_class}_map_location_attributes_zoom" %> +<%= form.fields_for :map_location, map_location do |m_l_fields| %> + <%= m_l_fields.hidden_field :latitude, + value: map_location.latitude, + id: map_location_input_id(parent_class, 'latitude') %> + <%= m_l_fields.hidden_field :longitude, + value: map_location.longitude, + id: map_location_input_id(parent_class, 'latitude') %> + <%= m_l_fields.hidden_field :zoom, + value: map_location.zoom, + id: map_location_input_id(parent_class, 'latitude') %> <% end %> \ No newline at end of file diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 72feba9c3..2390b62f6 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -67,6 +67,7 @@ map_location: @proposal.map_location || MapLocation.new, label: t("proposals.form.map_location"), help: t("proposals.form.map_location_instructions"), + remove_marker_label: t("proposals.form.map_remove_marker"), parent_class: "proposal" %>
    diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index c1879df16..1f29370bb 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -55,6 +55,9 @@ en: tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own" tags_label: Tags tags_placeholder: "Enter the tags you would like to use, separated by commas (',')" + map_location: "Map location" + map_location_instructions: "Navigate the map to the location and place the marker." + map_remove_marker: "Remove map marker" index: title: Participatory budgeting unfeasible: Unfeasible investment projects diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index c118db367..290e1a278 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -335,6 +335,7 @@ en: tags_placeholder: "Enter the tags you would like to use, separated by commas (',')" map_location: "Map location" map_location_instructions: "Navigate the map to the location and place the marker." + map_remove_marker: "Remove map marker" index: featured_proposals: Featured filter_topic: diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 78b81fbd3..5c76c8abe 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -55,6 +55,9 @@ es: tags_label: Temas tag_category_label: "Categorías" tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')" + map_location: "Ubicación en el mapa" + map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador." + map_remove_marker: "Eliminar el marcador" index: title: Presupuestos participativos unfeasible: Propuestas de inversión no viables diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 46664e2ae..722c0dabb 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -335,6 +335,7 @@ es: tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')" map_location: "Ubicación en el mapa" map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador." + map_remove_marker: "Eliminar el marcador" index: featured_proposals: Destacadas filter_topic: From a14bb77f49c8c805fe07c4cfaf11c304fe093395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 7 Aug 2017 13:22:37 +0200 Subject: [PATCH 194/765] Fix map location form fields ids definition. --- app/views/map_locations/_form_fields.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index 4fcefa2fa..2b1b3738c 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -1,7 +1,7 @@ <%= form.label :map_location, label %>

    <%= help %>

    -
    <%= m_l_fields.hidden_field :longitude, value: map_location.longitude, - id: map_location_input_id(parent_class, 'latitude') %> + id: map_location_input_id(parent_class, 'longitude') %> <%= m_l_fields.hidden_field :zoom, value: map_location.zoom, - id: map_location_input_id(parent_class, 'latitude') %> + id: map_location_input_id(parent_class, 'zoom') %> <% end %> \ No newline at end of file From dd7afd3593a2fbb33855cc5412b3c71a63a9d41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 7 Aug 2017 18:08:20 +0200 Subject: [PATCH 195/765] Add methods to map locations helper. --- app/assets/stylesheets/admin.scss | 5 ++ app/helpers/map_locations_helper.rb | 46 +++++++++++++++++++ app/views/admin/settings/_map_form.html.erb | 14 +++--- app/views/map_locations/_form_fields.html.erb | 22 +-------- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 2ef6fea23..aec72b35b 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -996,10 +996,15 @@ table { position: absolute; border-radius: 50%; } + .map-attributtion{ + visibility: visible; + height: auto; + } } .map-marker{ visibility: hidden; } .map-attributtion{ visibility: hidden; + height: 0; } \ No newline at end of file diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index 08d16391f..805d5504c 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -16,4 +16,50 @@ module MapLocationsHelper "#{prefix}_map_location_attributes_#{attribute}" end + def map_location_attribution_id(map_location) + "attribution-#{dom_id(map_location)}" + end + + def map_location_remove_marker_link_id(map_location) + "remove-marker-link-#{dom_id(map_location)}" + end + + def render_map(map_location, parent_class, editable, remove_marker_label) + map = content_tag_for :div, + map_location, + class: "map", + data:{ + map: "", + map_zoom: map_location_zoom(map_location), + map_tiles_attribution_selector: map_location_attribution_id(map_location), + map_tiles_provider: "//{s}.tile.osm.org/{z}/{x}/{y}.png", + marker_editable: editable, + marker_latitude: map_location_latitude(map_location), + marker_longitude: map_location_longitude(map_location), + marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", + latitude_input_selector: "##{map_location_input_id(parent_class, 'latitude')}", + longitude_input_selector: "##{map_location_input_id(parent_class, 'longitude')}", + zoom_input_selector: "##{map_location_input_id(parent_class, 'zoom')}" + } + map += map_attributtion(map_location) + map += map_location_remove_marker(map_location, remove_marker_label) if editable + end + + def map_attributtion(map_location, klass = nil) + content = "©#{link_to("OpenStreetMap", "http://osm.org/copyright")} contributors".html_safe + content_tag :div, id: map_location_attribution_id(map_location), class: "map-attributtion #{klass}" do + content + end + end + + def map_location_remove_marker(map_location, text) + content_tag :div, class: "small-12 column text-right" do + content_tag :a, + id: map_location_remove_marker_link_id(map_location), + class: "location-map-remove-marker-button delete" do + text + end + end + end + end \ No newline at end of file diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 53eb3d882..256bcd478 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -1,11 +1,13 @@
    -
    " - data-longitude="<%= Setting["map.longitude"] %>" - data-zoom="<%= Setting["map.zoom"] %>" - data-tiles-attribution-selector="#admin-map-attribution" - data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" +
    " + data-map-tiles-attribution-selector="#admin-map-attribution" + data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" + data-marker-editable="true" + data-marker-latitude="<%= Setting["map.latitude"] %>" + data-marker-longitude="<%= Setting["map.longitude"] %>" data-latitude-input-selector="#latitude" data-longitude-input-selector="#longitude" data-zoom-input-selector="#zoom"> diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index 2b1b3738c..f838d1f98 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -1,25 +1,7 @@ <%= form.label :map_location, label %>

    <%= help %>

    -
    -
    - -
    - © OpenStreetMap contributors -
    - -<%= remove_marker_label %> +<%= render_map(map_location, parent_class, true, remove_marker_label) %> <%= form.fields_for :map_location, map_location do |m_l_fields| %> <%= m_l_fields.hidden_field :latitude, @@ -27,7 +9,7 @@ id: map_location_input_id(parent_class, 'latitude') %> <%= m_l_fields.hidden_field :longitude, value: map_location.longitude, - id: map_location_input_id(parent_class, 'longitude') %> + id: map_location_input_id(parent_class, 'longitude') %> <%= m_l_fields.hidden_field :zoom, value: map_location.zoom, id: map_location_input_id(parent_class, 'zoom') %> From 130e4533ac7b241f7d65ee60b9612844bb80725b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 8 Aug 2017 10:47:35 +0200 Subject: [PATCH 196/765] Allow to render map without marker on new forms. --- app/assets/javascripts/map.js.coffee | 69 ++++++++++++------- app/helpers/map_locations_helper.rb | 11 ++- app/models/budget/investment.rb | 4 +- app/models/map_location.rb | 4 ++ app/models/proposal.rb | 4 +- app/views/admin/settings/_map_form.html.erb | 2 + .../investments/_investment_show.html.erb | 4 ++ app/views/proposals/show.html.erb | 4 ++ spec/models/map_location_spec.rb | 9 +++ 9 files changed, 79 insertions(+), 32 deletions(-) create mode 100644 spec/models/map_location_spec.rb diff --git a/app/assets/javascripts/map.js.coffee b/app/assets/javascripts/map.js.coffee index fb82d0800..33f13d25c 100644 --- a/app/assets/javascripts/map.js.coffee +++ b/app/assets/javascripts/map.js.coffee @@ -8,24 +8,47 @@ App.Map = App.Map.initializeMap map initializeMap: (element) -> - latitude = $(element).data('marker-latitude') - longitude = $(element).data('marker-longitude') - zoom = $(element).data('map-zoom') - mapTilesProvider = $(element).data('map-tiles-provider') - mapAttributionSelector = $(element).data('map-tiles-attribution-selector') - latitudeInputSelector = $(element).data('latitude-input-selector') - longitudeInputSelector = $(element).data('longitude-input-selector') - zoomInputSelector = $(element).data('zoom-input-selector') - removeMarkerSelector = $(element).data('marker-remove-selector') - attribution = $(mapAttributionSelector) - editable = $(element).data('marker-editable') - marker_icon = L.divIcon( + + mapCenterLatitude = $(element).data('map-center-latitude') + mapCenterLongitude = $(element).data('map-center-longitude') + markerLatitude = $(element).data('marker-latitude') + markerLongitude = $(element).data('marker-longitude') + zoom = $(element).data('map-zoom') + mapTilesProvider = $(element).data('map-tiles-provider') + mapAttributionSelector = $(element).data('map-tiles-attribution-selector') + latitudeInputSelector = $(element).data('latitude-input-selector') + longitudeInputSelector = $(element).data('longitude-input-selector') + zoomInputSelector = $(element).data('zoom-input-selector') + removeMarkerSelector = $(element).data('marker-remove-selector') + attribution = $(mapAttributionSelector) + editable = $(element).data('marker-editable') + marker = null; + markerIcon = L.divIcon( iconSize: null html: '
    ') - placeMarker = (e) -> - marker.setLatLng(e.latlng) + createMarker = (latitude, longitude) -> + markerLatLng = new (L.LatLng)(latitude, longitude) + marker = L.marker(markerLatLng, { icon: markerIcon, draggable: editable }) + if editable + marker.on 'dragend', updateFormfields marker.addTo(map) + return marker + + removeMarker = (e) -> + e.preventDefault() + if marker + map.removeLayer(marker) + marker = null; + clearFormfields() + return + + moveOrPlaceMarker = (e) -> + if marker + marker.setLatLng(e.latlng) + else + marker = createMarker(e.latlng.lat, e.latlng.lng) + updateFormfields() return @@ -41,20 +64,14 @@ App.Map = $(zoomInputSelector).val '' return - removeMarker = (e) -> - e.preventDefault() - map.removeLayer(marker) - clearFormfields() - return - - latLng = new (L.LatLng)(latitude, longitude) - map = L.map(element.id).setView(latLng, zoom) - marker = L.marker(latLng, { icon: marker_icon, draggable: editable }) + mapCenterLatLng = new (L.LatLng)(mapCenterLatitude, mapCenterLongitude) + map = L.map(element.id).setView(mapCenterLatLng, zoom) L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map - marker.addTo(map) + + if markerLatitude && markerLongitude + marker = createMarker(markerLatitude, markerLongitude) if editable $(removeMarkerSelector).on 'click', removeMarker - marker.on 'dragend', updateFormfields map.on 'zoomend', updateFormfields - map.on 'click', placeMarker \ No newline at end of file + map.on 'click', moveOrPlaceMarker \ No newline at end of file diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index 805d5504c..1df7a861c 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -1,5 +1,9 @@ module MapLocationsHelper + def map_location_available?(map_location) + map_location.present? && map_location.filled? + end + def map_location_latitude(map_location) map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] end @@ -30,12 +34,14 @@ module MapLocationsHelper class: "map", data:{ map: "", + map_center_latitude: map_location_latitude(map_location), + map_center_longitude: map_location_longitude(map_location), map_zoom: map_location_zoom(map_location), map_tiles_attribution_selector: map_location_attribution_id(map_location), map_tiles_provider: "//{s}.tile.osm.org/{z}/{x}/{y}.png", marker_editable: editable, - marker_latitude: map_location_latitude(map_location), - marker_longitude: map_location_longitude(map_location), + marker_latitude: map_location.latitude, + marker_longitude: map_location.longitude, marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", latitude_input_selector: "##{map_location_input_id(parent_class, 'latitude')}", longitude_input_selector: "##{map_location_input_id(parent_class, 'longitude')}", @@ -43,6 +49,7 @@ module MapLocationsHelper } map += map_attributtion(map_location) map += map_location_remove_marker(map_location, remove_marker_label) if editable + map end def map_attributtion(map_location, klass = nil) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index af8feac1d..e48bc2c57 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -27,8 +27,8 @@ class Budget has_many :valuators, through: :valuator_assignments has_many :comments, as: :commentable has_many :milestones - has_one :map_location - accepts_nested_attributes_for :map_location + has_one :map_location, dependent: :destroy + accepts_nested_attributes_for :map_location, allow_destroy: true validates :title, presence: true validates :author, presence: true diff --git a/app/models/map_location.rb b/app/models/map_location.rb index 61cb10893..8db4cda9c 100644 --- a/app/models/map_location.rb +++ b/app/models/map_location.rb @@ -3,4 +3,8 @@ class MapLocation < ActiveRecord::Base belongs_to :proposal belongs_to :investment + def filled? + latitude.present? && longitude.present? && zoom.present? + end + end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 7ad7a863b..b8d919e97 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -25,8 +25,8 @@ class Proposal < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone - has_one :map_location - accepts_nested_attributes_for :map_location + has_one :map_location, dependent: :destroy + accepts_nested_attributes_for :map_location, allow_destroy: true has_many :comments, as: :commentable has_many :proposal_notifications diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 256bcd478..beac8e87b 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -2,6 +2,8 @@
    " + data-map-center-longitude="<%= Setting["map.longitude"] %>" data-map-zoom="<%= Setting["map.zoom"] %>" data-map-tiles-attribution-selector="#admin-map-attribution" data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png" diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index e257de0bb..eab4de525 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -45,6 +45,10 @@ <%= safe_html_with_links investment.description.html_safe %> + <% if feature?(:map) && map_location_available?(@investment.map_location) %> + <%= render_map(@investment.map_location, "budget_investment", false, nil) %> + <% end %> + <% if investment.external_url.present? %>