From 3d5f7f207c81f9f7daef865b7d1896c918e1ac9f Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Wed, 7 Sep 2016 11:58:10 +0200 Subject: [PATCH 001/102] no need to db:create here --- README.md | 1 - README_ES.md | 1 - 2 files changed, 2 deletions(-) diff --git a/README.md b/README.md index 27162bfd7..f376dfded 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ cd consul bundle install cp config/database.yml.example config/database.yml cp config/secrets.yml.example config/secrets.yml -rake db:create bin/rake db:setup bin/rake db:dev_seed RAILS_ENV=test rake db:setup diff --git a/README_ES.md b/README_ES.md index d8c394680..7c7720ee7 100644 --- a/README_ES.md +++ b/README_ES.md @@ -32,7 +32,6 @@ cd consul bundle install cp config/database.yml.example config/database.yml cp config/secrets.yml.example config/secrets.yml -rake db:create bin/rake db:setup bin/rake db:dev_seed RAILS_ENV=test rake db:setup From a527de4f9224dc67a6da675a9d980f2dcc5de7b2 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 7 Sep 2016 12:43:12 +0200 Subject: [PATCH 002/102] Adds proposal ballots controller and views --- .../proposal_ballots_controller.rb | 8 ++ .../_featured_successfull_proposal.html.erb | 3 + .../_successfull_proposal.html.erb | 13 +++ app/views/proposal_ballots/index.html.erb | 36 ++++++++ config/routes.rb | 2 + db/schema.rb | 87 +++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 app/controllers/proposal_ballots_controller.rb create mode 100644 app/views/proposal_ballots/_featured_successfull_proposal.html.erb create mode 100644 app/views/proposal_ballots/_successfull_proposal.html.erb create mode 100644 app/views/proposal_ballots/index.html.erb diff --git a/app/controllers/proposal_ballots_controller.rb b/app/controllers/proposal_ballots_controller.rb new file mode 100644 index 000000000..4e3e99671 --- /dev/null +++ b/app/controllers/proposal_ballots_controller.rb @@ -0,0 +1,8 @@ +class ProposalBallotsController < ApplicationController + skip_authorization_check + + def index + @proposal_ballots = Proposal.successfull.sort_by_confidence_score + end + +end diff --git a/app/views/proposal_ballots/_featured_successfull_proposal.html.erb b/app/views/proposal_ballots/_featured_successfull_proposal.html.erb new file mode 100644 index 000000000..97754ce9c --- /dev/null +++ b/app/views/proposal_ballots/_featured_successfull_proposal.html.erb @@ -0,0 +1,3 @@ +
+

<%= link_to proposal.title, proposal_ballots_path %>

+
diff --git a/app/views/proposal_ballots/_successfull_proposal.html.erb b/app/views/proposal_ballots/_successfull_proposal.html.erb new file mode 100644 index 000000000..3a8c2a557 --- /dev/null +++ b/app/views/proposal_ballots/_successfull_proposal.html.erb @@ -0,0 +1,13 @@ +
+

<%= link_to proposal.title, proposal %>

+

<%= proposal.question %>

+
+ <% if proposal.author.hidden? || proposal.author.erased? %> + <%= t("proposals.show.author_deleted") %> + <% else %> + <%= proposal.author.name %> + <% end %> +  •  + <%= t("proposals.proposal.supports", count: proposal.total_votes) %> +
+
diff --git a/app/views/proposal_ballots/index.html.erb b/app/views/proposal_ballots/index.html.erb new file mode 100644 index 000000000..6206a856c --- /dev/null +++ b/app/views/proposal_ballots/index.html.erb @@ -0,0 +1,36 @@ +
+
+
+

+ <%= t("proposal_ballots.title") %> +

+

+ <%= t("proposal_ballots.description_html", + supports: Setting['votes_for_proposal_success'].to_i).html_safe %> +

+
+ +
+

 <%= t("proposal_ballots.date_title") %>

+

<%= t("proposal_ballots.date") %>

+
+
+
+ +
+
+
+ <% if @proposal_ballots.present? %> +
+ <% @proposal_ballots.each do |proposal_for_vote| %> + <%= render "successfull_proposal", proposal: proposal_for_vote %> + <% end %> +
+ <% else %> +

+ <%= t("proposal_ballots.nothing_to_vote") %> +

+ <% end %> +
+
+
diff --git a/config/routes.rb b/config/routes.rb index 4f3eb94ec..df1a7c6fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,6 +61,8 @@ Rails.application.routes.draw do end end + resources :proposal_ballots, only: [:index] + resources :comments, only: [:create, :show], shallow: true do member do post :vote diff --git a/db/schema.rb b/db/schema.rb index becde4f8a..6124f31d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -78,6 +78,91 @@ ActiveRecord::Schema.define(version: 20160803154011) do add_index "banners", ["hidden_at"], name: "index_banners_on_hidden_at", using: :btree + create_table "budget_ballot_lines", force: :cascade do |t| + t.integer "ballot_id" + t.integer "investment_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "budget_id" + t.integer "group_id" + t.integer "heading_id" + end + + add_index "budget_ballot_lines", ["ballot_id"], name: "index_budget_ballot_lines_on_ballot_id", using: :btree + add_index "budget_ballot_lines", ["investment_id"], name: "index_budget_ballot_lines_on_investment_id", using: :btree + + create_table "budget_ballots", force: :cascade do |t| + t.integer "user_id" + t.integer "budget_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "budget_groups", force: :cascade do |t| + t.integer "budget_id" + t.string "name", limit: 50 + end + + add_index "budget_groups", ["budget_id"], name: "index_budget_groups_on_budget_id", using: :btree + + create_table "budget_headings", force: :cascade do |t| + t.integer "budget_id" + t.integer "geozone_id" + t.string "name", limit: 50 + t.integer "price", limit: 8 + end + + create_table "budget_investments", force: :cascade do |t| + t.integer "author_id" + t.integer "administrator_id" + t.string "title" + t.text "description" + t.string "external_url" + t.integer "price", limit: 8 + t.string "feasibility", limit: 15, default: "undecided" + t.text "price_explanation" + t.text "unfeasibility_explanation" + t.text "internal_comments" + t.boolean "valuation_finished", default: false + t.integer "valuator_assignments_count", default: 0 + t.integer "price_first_year", limit: 8 + t.string "duration" + t.datetime "hidden_at" + t.integer "cached_votes_up", default: 0 + t.integer "comments_count", default: 0 + t.integer "confidence_score", default: 0, null: false + t.integer "physical_votes", default: 0 + t.tsvector "tsv" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "heading_id" + t.string "responsible_name" + end + + add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree + add_index "budget_investments", ["author_id"], name: "index_budget_investments_on_author_id", using: :btree + add_index "budget_investments", ["heading_id"], name: "index_budget_investments_on_heading_id", using: :btree + add_index "budget_investments", ["tsv"], name: "index_budget_investments_on_tsv", using: :gin + + create_table "budget_valuator_assignments", force: :cascade do |t| + t.integer "valuator_id" + t.integer "investment_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "budget_valuator_assignments", ["investment_id"], name: "index_budget_valuator_assignments_on_investment_id", using: :btree + + create_table "budgets", force: :cascade do |t| + t.string "name", limit: 30 + t.text "description" + t.string "currency_symbol", limit: 10 + t.string "phase", limit: 15, default: "on_hold" + t.boolean "valuating", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "campaigns", force: :cascade do |t| t.string "name" t.string "track_id" @@ -378,6 +463,7 @@ ActiveRecord::Schema.define(version: 20160803154011) do t.integer "proposals_count", default: 0 t.integer "spending_proposals_count", default: 0 t.string "kind" + t.integer "budget/investments_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree @@ -484,6 +570,7 @@ ActiveRecord::Schema.define(version: 20160803154011) do t.integer "user_id" t.string "description" t.integer "spending_proposals_count", default: 0 + t.integer "budget_investments_count", default: 0 end add_index "valuators", ["user_id"], name: "index_valuators_on_user_id", using: :btree From b107790039bddd175eb98df13be7b03089832792 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 7 Sep 2016 12:46:29 +0200 Subject: [PATCH 003/102] Adds links, texts and i18n --- app/controllers/proposals_controller.rb | 5 +++++ app/models/proposal.rb | 5 +++++ app/views/proposals/_proposal.html.erb | 24 ++++++++++++++++++------ app/views/proposals/index.html.erb | 16 ++++++++++++++-- app/views/proposals/show.html.erb | 18 +++++++++++++----- app/views/shared/_subnavigation.html.erb | 3 +++ config/locales/en.yml | 10 ++++++++++ config/locales/es.yml | 10 ++++++++++ 8 files changed, 78 insertions(+), 13 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 578395ab3..898ad9949 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -28,6 +28,7 @@ class ProposalsController < ApplicationController def index_customization load_retired load_featured + load_proposal_ballots end def vote @@ -97,4 +98,8 @@ class ProposalsController < ApplicationController end end + def load_proposal_ballots + @proposal_ballots = Proposal.successfull.sort_by_confidence_score + end + end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 9a92a8d18..4c3cc9e40 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -47,6 +47,7 @@ class Proposal < ActiveRecord::Base scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} scope :retired, -> { where.not(retired_at: nil) } scope :not_retired, -> { where(retired_at: nil) } + scope :successfull, -> { where("cached_votes_up + physical_votes >= ?", Proposal.votes_needed_for_success)} def to_param "#{id}-#{title}".parameterize @@ -155,6 +156,10 @@ class Proposal < ActiveRecord::Base Setting['votes_for_proposal_success'].to_i end + def successfull? + total_votes >= Proposal.votes_needed_for_success + end + def notifications proposal_notifications end diff --git a/app/views/proposals/_proposal.html.erb b/app/views/proposals/_proposal.html.erb index 70c2b9c89..464710493 100644 --- a/app/views/proposals/_proposal.html.erb +++ b/app/views/proposals/_proposal.html.erb @@ -1,10 +1,12 @@ -
+
Proposal.votes_needed_for_success) %>" + data-type="proposal">
+
- <% cache [locale_and_user_status(proposal), 'index', proposal, proposal.author] do %> <%= t("proposals.proposal.proposal") %> @@ -50,11 +52,21 @@
-
- <%= render 'votes', - { proposal: proposal, vote_url: vote_proposal_path(proposal, value: 'yes') } %> +
+ <% if proposal.successfull? %> +
+

+ <%= t("proposal_ballots.successfull", + voting: link_to(t("proposal_ballots.voting"), proposal_ballots_path)).html_safe %> +

+
+ <% else %> +
+ <%= render 'votes', + { proposal: proposal, vote_url: vote_proposal_path(proposal, value: 'yes') } %> +
+ <% end %>
-
diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index 6f6516890..ff9c23d08 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -30,8 +30,20 @@ <% if has_banners %> <%= render "shared/banner" %> <% end %> - - <% if @featured_proposals.present? %> + + <% if @proposal_ballots.present? %> + + <% elsif @featured_proposals.present? %>