Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consultations: unify navigation #3524

Merged
merged 9 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ must now set a resource name:
- **decidim-assemblies**: Update card layout for assemblies and assembly members [\#3405](https://github.com/decidim/decidim/pull/3405)
- **decidim-sortitions**: Update card layout [\#3405](https://github.com/decidim/decidim/pull/3405)
- **decidim**: Changes on how to register resources. Resources from a component now they need a specific reference to the component manifest, and all resources need a name. [\#3416](https://github.com/decidim/decidim/pull/3416)
- **decidim-consultations**: Improve overall navigation [\#3524](https://github.com/decidim/decidim/pull/3524)
- **decidim-comments**: Let comments have paragraphs to increase readability [\#3538](https://github.com/decidim/decidim/pull/3538)

**Fixed**:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,14 @@ class ConsultationsController < Decidim::Consultations::ApplicationController

def index
enforce_permission_to :read, :consultation_list
redirect_to consultation_path(active_consultations.first) if active_consultations.count == 1
end

def show
enforce_permission_to :read, :consultation, consultation: current_consultation
end

def finished
enforce_permission_to :read, :consultation
render layout: "layouts/decidim/consultation_choose"
end

private

def finished_consultations
@finished_consultations ||= OrganizationConsultations.for(current_organization).finished.published
end

def active_consultations
@active_consultations ||= OrganizationConsultations.for(current_organization).active.published
end

def consultations
@consultations = search.results
@consultations = reorder(@consultations)
Expand Down
4 changes: 2 additions & 2 deletions decidim-consultations/app/models/decidim/consultation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def highlighted_questions
questions.published.where(decidim_scope_id: decidim_highlighted_scope_id)
end

def regular_questions
questions.published.where.not(decidim_scope_id: decidim_highlighted_scope_id).group_by(&:scope)
def questions_by_scope
questions.published.group_by(&:scope)
end

# This method exists with the only purpose of getting rid of whats seems to be an issue in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<div class="row small-up-1 medium-up-2 card-grid">
<% consultations.each do |consultation| %>
<%= render partial: "consultation_card", locals: { consultation: consultation } %>
<%= card_for consultation %>
<% end %>
</div>
<%= decidim_paginate consultations, random_seed: random_seed %>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<% if consultation.regular_questions.any? %>
<% if consultation.questions.any? %>
<section id="regular-questions" class="row section">
<h2 class=section-heading>
<%= t "consultations.regular_questions.title", scope: "decidim" %>
</h2>

<% consultation.regular_questions.each do |scope_id, questions| %>
<% consultation.questions_by_scope.each do |scope_id, questions| %>
<h3 class="heading6"><%= translated_attribute questions.first.scope.name %></h3>
<% questions.each do |question| %>
<%= render partial: "decidim/consultations/consultations/question", locals: { question: question } %>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<%= render partial: "consultation_details", locals: { consultation: current_consultation } %>
<%= render partial: "highlighted_questions", locals: { consultation: current_consultation } %>
<%= render partial: "regular_questions", locals: { consultation: current_consultation } %>

<% if finished_consultations.any? %>
<div class="text-center">
<%= link_to t("consultations.show.see_finished_consultations", scope: "decidim"),
finished_consultations_path,
class: "button hollow button--sc" %>
</div>
<% end %>
8 changes: 2 additions & 6 deletions decidim-consultations/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,8 @@ en:
filter: Filter
filter_by: Filter by
unfold: Unfold
finished:
active_consultations: Active consultations
past_consultations: Past consultations
highlighted_questions:
title: Consultations from %{scope_name}
title: Questions from %{scope_name}
index:
title: Consultations
question:
Expand All @@ -215,7 +212,7 @@ en:
create:
error: There have been errors when voting the question
regular_questions:
title: Other consultations
title: Questions for this consultation
show:
badge_name:
finished: Finished
Expand All @@ -227,7 +224,6 @@ en:
view: View
view_results: View results
vote: Vote
see_finished_consultations: See previous consultations
unspecified: Not specified
menu:
consultations: Consultations
Expand Down
1 change: 0 additions & 1 deletion decidim-consultations/lib/decidim/consultations/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Engine < ::Rails::Engine
}, constraints: { question_id: /[0-9]+/ }

resources :consultations, only: [:index, :show], param: :slug, path: "consultations" do
get "finished", on: :collection
resource :consultation_widget, only: :show, path: "embed"

resources :questions, only: [:show], param: :slug, path: "questions", shallow: true do
Expand Down
17 changes: 2 additions & 15 deletions decidim-consultations/spec/system/consultation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it "Shows the highlighted questions section" do
expect(page).to have_content("Consultations from #{translated consultation.highlighted_scope.name}".upcase)
expect(page).to have_content("Questions from #{translated consultation.highlighted_scope.name}".upcase)
end

it "shows highlighted question details" do
Expand All @@ -60,7 +60,7 @@
end

it "Shows the regular questions section" do
expect(page).to have_content("OTHER CONSULTATIONS")
expect(page).to have_content("QUESTIONS FOR THIS CONSULTATION")
end

it "shows the scope name" do
Expand All @@ -72,17 +72,4 @@
expect(page).to have_i18n_content(question.subtitle)
end
end

context "when finished consultations" do
let!(:finished_consultation) { create :consultation, :finished, :published, :published_results, organization: organization }

before do
switch_to_host(organization.host)
visit decidim_consultations.consultation_path(consultation)
end

it "consultation page contains finished consultations" do
expect(page).to have_content("SEE PREVIOUS CONSULTATIONS")
end
end
end
16 changes: 1 addition & 15 deletions decidim-consultations/spec/system/consultations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,9 @@
expect(page).to have_selector("ul[data-dropdown-menu$=dropdown-menu]", text: "Random")
end

expect(page).to have_selector(".card--process", count: 2)
expect(page).to have_selector(".card--consultation", count: 2)
expect(page).to have_content(translated(consultations.first.title))
expect(page).to have_content(translated(consultations.last.title))
end
end

context "when there is only one active consultation in the organization" do
let!(:consultation) { create(:consultation, :active, :published, organization: organization) }
let!(:finished_consultation) { create :consultation, :finished, :published, organization: organization }

before do
switch_to_host(organization.host)
visit decidim_consultations.consultations_path
end

it "is redirected to consultation view" do
expect(page).to have_current_path(decidim_consultations.consultation_path(consultation))
end
end
end