From 38ba5e159bbce7e8bf4a0823daa96e32c724ab1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 20 Sep 2017 17:45:17 +0200 Subject: [PATCH] Legislation proposals show and edit views available --- app/controllers/application_controller.rb | 4 ---- app/controllers/legislation/base_controller.rb | 4 ++++ app/controllers/legislation/processes_controller.rb | 1 + app/controllers/legislation/proposals_controller.rb | 11 ++++++----- app/views/legislation/proposals/_proposal.html.erb | 4 ++-- app/views/legislation/proposals/_votes.html.erb | 4 ++-- app/views/legislation/proposals/edit.html.erb | 4 ++-- app/views/legislation/proposals/share.html.erb | 2 +- app/views/legislation/proposals/show.html.erb | 6 +++--- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 318777314f9..495a253144a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -76,10 +76,6 @@ def set_proposal_votes(proposals) @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/base_controller.rb b/app/controllers/legislation/base_controller.rb index ca609ecbaf1..c08ffc44472 100644 --- a/app/controllers/legislation/base_controller.rb +++ b/app/controllers/legislation/base_controller.rb @@ -2,4 +2,8 @@ class Legislation::BaseController < ApplicationController include FeatureFlags feature_flag :legislation + + def set_legislation_proposal_votes(proposals) + @legislation_proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {} + end end diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 6c12cea5b58..d788d3bf363 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -88,6 +88,7 @@ def proposals @phase = :proposals_phase if @process.proposals_phase.started? + set_legislation_proposal_votes(@process.proposals) render :proposals else render :phase_not_open diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index 1eab070470d..c65315ddffa 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -20,6 +20,7 @@ class Legislation::ProposalsController < Legislation::BaseController def show super + set_legislation_proposal_votes(@process.proposals) @notifications = @proposal.notifications @document = Document.new(documentable: @proposal) redirect_to legislation_process_proposal_path(params[:process_id], @proposal), @@ -79,18 +80,18 @@ def summary private def proposal_params - params.require(:proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :external_url, :video_url, + params.require(:legislation_proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :geozone_id, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) end def retired_params - params.require(:proposal).permit(:retired_reason, :retired_explanation) + params.require(:legislation_proposal).permit(:retired_reason, :retired_explanation) end def valid_retired_params? - @proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:proposal][:retired_reason].blank? - @proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:proposal][:retired_explanation].blank? + @proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:legislation_proposal][:retired_reason].blank? + @proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:legislation_proposal][:retired_explanation].blank? @proposal.errors.empty? end @@ -102,7 +103,7 @@ def resource_name 'proposal' end - def set_legislation_proposal_votes(proposals) + def set_featured_proposal_votes(proposals) @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} end diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb index 996be8f953b..f3b603aa543 100644 --- a/app/views/legislation/proposals/_proposal.html.erb +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -8,10 +8,10 @@
<% cache [locale_and_user_status(proposal), 'index', proposal, proposal.author] do %> -

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

+

<%= link_to proposal.title, legislation_process_proposal_path(proposal.legislation_process_id, proposal) %>

  - <%= link_to t("proposals.proposal.comments", count: proposal.comments_count), namespaced_proposal_path(proposal, anchor: "comments") %> + <%= link_to t("proposals.proposal.comments", count: proposal.comments_count), legislation_process_proposal_path(proposal.legislation_process_id, proposal, anchor: "comments") %>  •  <%= l proposal.created_at.to_date %> diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index fb41357af9b..b44c4d6cbd0 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -16,7 +16,7 @@

- <% if voted_for?(@proposal_votes, proposal) %> + <% if voted_for?(@legislation_proposal_votes, proposal) %>
<%= t("proposals.proposal.already_supported") %>
@@ -58,7 +58,7 @@
<% end %> - <% if voted_for?(@proposal_votes, proposal) && setting['twitter_handle'] %> + <% if voted_for?(@legislation_proposal_votes, proposal) && setting['twitter_handle'] %> diff --git a/app/views/legislation/proposals/edit.html.erb b/app/views/legislation/proposals/edit.html.erb index 6e5b14a087e..6d4761524f1 100644 --- a/app/views/legislation/proposals/edit.html.erb +++ b/app/views/legislation/proposals/edit.html.erb @@ -4,11 +4,11 @@ <%= back_link_to %>
- <%= link_to t("proposals.edit.show_link"), @proposal %> + <%= link_to t("proposals.edit.show_link"), legislation_process_proposal_path(@proposal.legislation_process_id, @proposal) %>

<%= t("proposals.edit.editing") %>

- <%= render "form", form_url: proposal_url(@proposal) %> + <%= render "form", form_url: legislation_process_proposal_url(@proposal.legislation_process_id, @proposal) %>
diff --git a/app/views/legislation/proposals/share.html.erb b/app/views/legislation/proposals/share.html.erb index 5faa9d985b5..8ea0f7e98fe 100644 --- a/app/views/legislation/proposals/share.html.erb +++ b/app/views/legislation/proposals/share.html.erb @@ -9,7 +9,7 @@ <%= render "shared/canonical", href: proposal_url(@proposal) %> <% end %> -<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @legislation_proposal_votes] do %>
diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index 1dc918e8e6c..b17464a04d9 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -10,7 +10,7 @@ <%= render "shared/canonical", href: proposal_url(@proposal) %> <% end %> -<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @legislation_proposal_votes] do %>
@@ -29,7 +29,7 @@ <% end %> <% if current_user && @proposal.editable_by?(current_user) %> - <%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button hollow float-right' do %> + <%= 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 %> @@ -147,7 +147,7 @@
<% else %> <%= render 'votes', - { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: 'yes') } %> + { proposal: @proposal, vote_url: vote_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal, value: 'yes') } %> <% end %>
<%= render partial: 'shared/social_share', locals: {