Add community to investments

This commit is contained in:
taitus
2017-08-23 20:51:16 +02:00
parent 4539c5fa00
commit 895c942a39
11 changed files with 65 additions and 11 deletions

View File

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

View File

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

View File

@@ -6,4 +6,9 @@ class Community < ActiveRecord::Base
def participants
User.community_participants(self)
end
def from_proposal?
self.proposal.present?
end
end

View File

@@ -123,6 +123,13 @@
<%= render 'follows/follow_button', follow: find_or_build_follow(current_user, investment) %>
<% end %>
<div class="sidebar-divider"></div>
<h2><%= t("community.sidebar.title") %></h2>
<p>
<%= t("community.sidebar.description") %>
</p>
<%= link_to t("community.sidebar.button_to_access"), community_path(investment.community_id), class: 'button hollow expanded' %>
</aside>
</div>
</section>

View File

@@ -2,9 +2,9 @@
<div class="jumbo light">
<div class="row">
<div class="small-12 column">
<h2><%= t("community.show.title") %></h2>
<p class="lead"> <%= @community.proposal.title %> </p>
<p><%= t("community.show.description") %> </p>
<h2><%= community_text(@community) %></h2>
<p class="lead"> <%= community_title(@community) %> </p>
<p><%= community_description(@community) %> </p>
</div>
</div>
</div>

View File

@@ -3,7 +3,7 @@
<%= render "shared/back_link" %>
<br>
<p><%= t("community.topic.show.community_of_the_proposal") %> <strong><%= @community.proposal.title %></strong></p>
<p><%= t("community.topic.show.community_of_the_proposal") %> <strong><%= community_title(@community) %></strong></p>
<h1><%= @topic.title %></h1>
<div class="topic-info">
<p><%= @topic.description %></p>

View File

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

View File

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

View File

@@ -0,0 +1,5 @@
class AddCommunityToBudgetInvestments < ActiveRecord::Migration
def change
add_reference :budget_investments, :community, index: true, foreign_key: true
end
end

View File

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

View File

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