From 895c942a3988cec418c653cb0fd178e9af262e40 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 23 Aug 2017 20:51:16 +0200 Subject: [PATCH] Add community to investments --- app/helpers/communities_helper.rb | 20 +++++++++++++++++++ app/models/budget/investment.rb | 7 +++++++ app/models/community.rb | 5 +++++ .../investments/_investment_show.html.erb | 7 +++++++ app/views/communities/show.html.erb | 6 +++--- app/views/topics/show.html.erb | 2 +- config/locales/en/community.yml | 8 ++++++-- config/locales/es/community.yml | 10 +++++++--- ...743_add_community_to_budget_investments.rb | 5 +++++ db/schema.rb | 5 ++++- spec/features/comments/proposals_spec.rb | 1 - 11 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 app/helpers/communities_helper.rb create mode 100644 db/migrate/20170822144743_add_community_to_budget_investments.rb diff --git a/app/helpers/communities_helper.rb b/app/helpers/communities_helper.rb new file mode 100644 index 000000000..fd70df758 --- /dev/null +++ b/app/helpers/communities_helper.rb @@ -0,0 +1,20 @@ +module CommunitiesHelper + + def community_title(community) + if community.from_proposal? + community.proposal.title + else + investment = Budget::Investment.where(community_id: community.id).first + investment.title + end + end + + def community_text(community) + community.from_proposal? ? t("community.show.title.proposal") : t("community.show.title.investment") + end + + def community_description(community) + community.from_proposal? ? t("community.show.description.proposal") : t("community.show.description.investment") + end + +end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 0dfd7836c..124824030 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -21,6 +21,7 @@ class Budget belongs_to :group belongs_to :budget belongs_to :administrator + belongs_to :community has_many :valuator_assignments, dependent: :destroy has_many :valuators, through: :valuator_assignments @@ -71,6 +72,7 @@ class Budget before_save :calculate_confidence_score after_save :recalculate_heading_winners if :incompatible_changed? + before_create :associate_community before_validation :set_responsible_name before_validation :set_denormalized_ids @@ -258,6 +260,11 @@ class Budget investments end + def associate_community + community = Community.create + self.community_id = community.id + end + private def set_denormalized_ids diff --git a/app/models/community.rb b/app/models/community.rb index feb6f9c59..b2fe91651 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -6,4 +6,9 @@ class Community < ActiveRecord::Base def participants User.community_participants(self) end + + def from_proposal? + self.proposal.present? + end + end diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 3f1890ae8..b72c295f2 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -123,6 +123,13 @@ <%= render 'follows/follow_button', follow: find_or_build_follow(current_user, investment) %> <% end %> + +

<%= t("community.sidebar.title") %>

+

+ <%= t("community.sidebar.description") %> +

+ <%= link_to t("community.sidebar.button_to_access"), community_path(investment.community_id), class: 'button hollow expanded' %> + diff --git a/app/views/communities/show.html.erb b/app/views/communities/show.html.erb index 1720c1792..2382ede24 100644 --- a/app/views/communities/show.html.erb +++ b/app/views/communities/show.html.erb @@ -2,9 +2,9 @@
-

<%= t("community.show.title") %>

-

<%= @community.proposal.title %>

-

<%= t("community.show.description") %>

+

<%= community_text(@community) %>

+

<%= community_title(@community) %>

+

<%= community_description(@community) %>

diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 54bfb104b..2de6158cb 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -3,7 +3,7 @@ <%= render "shared/back_link" %>
-

<%= t("community.topic.show.community_of_the_proposal") %> <%= @community.proposal.title %>

+

<%= t("community.topic.show.community_of_the_proposal") %> <%= community_title(@community) %>

<%= @topic.title %>

<%= @topic.description %>

diff --git a/config/locales/en/community.yml b/config/locales/en/community.yml index 8298400a4..1aa78574a 100644 --- a/config/locales/en/community.yml +++ b/config/locales/en/community.yml @@ -5,8 +5,12 @@ en: description: Partecipa a la comunidad de usuarios, da tu opinión. button_to_access: Access the community show: - title: Proposal community - description: Participate in the community of this proposal + title: + proposal: Proposal community + investment: Budget Investment community + description: + proposal: Participate in the community of this proposal + investment: Participate in the community of this budget investment create_first_community_topic: Create the first community topic tab: participants: Participants diff --git a/config/locales/es/community.yml b/config/locales/es/community.yml index 347cf7dc9..bbae21159 100644 --- a/config/locales/es/community.yml +++ b/config/locales/es/community.yml @@ -2,11 +2,15 @@ es: community: sidebar: title: Comunidad - description: Partecipa a la comunidad de usuarios, da tu opinión. + description: Participa en la comunidad de usuarios, da tu opinión. button_to_access: Acceder a la comunidad show: - title: Comunidad de la propuesta - description: Participa en la comunidad de esta propuesta + title: + proposal: Comunidad de la propuesta + investment: Comunidad del presupuesto participativo + description: + proposal: Participa en la comunidad de esta propuesta + investment: Participa en la comunidad de este presupuesto participativo create_first_community_topic: Crea el primer tema de la comunidad tab: paricipants: Participantes diff --git a/db/migrate/20170822144743_add_community_to_budget_investments.rb b/db/migrate/20170822144743_add_community_to_budget_investments.rb new file mode 100644 index 000000000..08fefbb63 --- /dev/null +++ b/db/migrate/20170822144743_add_community_to_budget_investments.rb @@ -0,0 +1,5 @@ +class AddCommunityToBudgetInvestments < ActiveRecord::Migration + def change + add_reference :budget_investments, :community, index: true, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 42c137cae..043e0db7e 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: 20170807082243) do +ActiveRecord::Schema.define(version: 20170822144743) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -160,10 +160,12 @@ ActiveRecord::Schema.define(version: 20170807082243) do t.integer "previous_heading_id" t.boolean "winner", default: false t.boolean "incompatible", default: false + t.integer "community_id" 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", ["community_id"], name: "index_budget_investments_on_community_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 @@ -1052,6 +1054,7 @@ ActiveRecord::Schema.define(version: 20170807082243) do add_foreign_key "administrators", "users" add_foreign_key "annotations", "legacy_legislations" add_foreign_key "annotations", "users" + add_foreign_key "budget_investments", "communities" add_foreign_key "documents", "users" add_foreign_key "failed_census_calls", "poll_officers" add_foreign_key "failed_census_calls", "users" diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 24d1024b7..475e018f3 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -31,7 +31,6 @@ feature 'Commenting proposals' do expect(page).to have_content parent_comment.body expect(page).to have_content first_child.body expect(page).to have_content second_child.body - debugger expect(page).to have_link "Go back to #{proposal.title}", href: proposal_path(proposal) end