Skip to content

Commit

Permalink
Fix assemblies filter by type (#4778)
Browse files Browse the repository at this point in the history
* Move code parent assemblies from index to partial

* Refactor filtered assemblies query

* Refactor filter assemblies helper and partial

* Change tests

* Add CHANGELOG entry
  • Loading branch information
Aitor Lopez Beltran authored and oriolgual committed Jan 22, 2019
1 parent 8a15228 commit 2c9d4d7
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@

**Fixed**:

- **decidim-assemblies**: Fix assemblies filter by type [\#4778](https://github.com/decidim/decidim/pull/4778)
- **decidim-conferences**: Fix error when visiting a Conference event[\#4776](https://github.com/decidim/decidim/pull/4776)
- **decidim-proposals** Fix unhideable reported collaborative drafts and mail jobs [\#4706](https://github.com/decidim/decidim/pull/4706)
- **decidim-assemblies**: Fix parent assemblies children_count counter [\#4718](https://github.com/decidim/decidim/pull/4718/)
Expand Down
Expand Up @@ -71,7 +71,7 @@ def assemblies
end

def parent_assemblies
@parent_assemblies ||= assemblies | ParentAssemblies.new | FilteredAssemblies.new(params[:filter])
@parent_assemblies ||= assemblies | ParentAssemblies.new | FilteredAssemblies.new(current_filter)
end

alias collection parent_assemblies
Expand All @@ -87,6 +87,10 @@ def stats
def assembly_participatory_processes
@assembly_participatory_processes ||= @current_participatory_space.linked_participatory_space_resources(:participatory_processes, "included_participatory_processes")
end

def current_filter
params[:filter] || "all"
end
end
end
end
Expand Up @@ -12,12 +12,16 @@ def filter_link(filter)
link_to t(filter, scope: "decidim.assemblies.filter"), url_for(params.to_unsafe_h.merge(page: nil, filter: filter)), data: { filter: filter }, remote: true
end

def label_text
t("label", scope: "decidim.assemblies.filter")
def help_text
t("help", scope: "decidim.assemblies.filter")
end

def placeholder_text
t("placeholder", scope: "decidim.assemblies.filter")
def filter
params[:filter] || "all"
end

def current_filter_text
t(filter, scope: "decidim.assemblies.filter")
end
end
end
Expand Down
Expand Up @@ -8,20 +8,14 @@ def initialize(filter)
@filter = filter
end

def filter
return "all" if @filter.nil?

@filter
end

def assemblies
Decidim::Assembly
end

def query
return assemblies.all if filter == "all"
return assemblies.all if @filter == "all"

assemblies.where(assembly_type: filter)
assemblies.where(assembly_type: @filter)
end
end
end
Expand Down
@@ -1,7 +1,7 @@
<div class="inline-filters">
<div id="assemblies-filter" class="inline-filters">
<label>
<span><%= label_text %></span>
<button data-toggle="inline-filter-sort"><%= placeholder_text %></button>
<span><%= help_text %></span>
<button id="button-text" data-toggle="inline-filter-sort"><%= current_filter_text %></button>
<div id="inline-filter-sort" class="dropdown-pane" data-position="bottom" data-alignment="right" data-dropdown data-auto-focus="true">
<ul class="list-reset">
<% available_filters.each do |filter| %>
Expand All @@ -10,4 +10,5 @@
</ul>
</div>
</label>
<script> $(document).foundation(); </script>
</div>
@@ -0,0 +1,14 @@
<section id="parent-assemblies" class="section row collapse">
<div class="row column">
<div class="flex--sbe">
<h2 id="assemblies-count" class="section-heading collapse">
<%= render partial: "count" %>
</h2>
<%= render partial: "decidim/assemblies/filter_by_type" %>
</div>
<hr class="reset mt-s mb-s" />
</div>
<div class="row small-up-1 medium-up-2 large-up-3 card-grid">
<%= render(collection) %>
</div>
</section>
Expand Up @@ -16,20 +16,7 @@ edit_link(
</section>
<% end %>
<section id="assemblies-grid" class="section row collapse">
<div class="row column">
<div class="flex--sbe">
<h2 id="assemblies-count" class="section-heading collapse">
<%= render partial: "count" %>
</h2>
<%= render partial: "decidim/assemblies/filter_by_type" %>
</div>
<hr class="reset mt-s mb-s" />
</div>
<div class="row small-up-1 medium-up-2 large-up-3 card-grid">
<%= render(collection) %>
</div>
</section>
<%= render partial: "parent_assemblies" %>

<section id="assemblies-chart" class="row column section">
<div class="row column">
Expand Down
@@ -1,5 +1,7 @@
var $grid = $('#assemblies-grid');
var $grid = $('#parent-assemblies');
var $assembliesCount = $('#assemblies-count');
var $assembliesFilter = $('#assemblies-filter');

$grid.find('.card-grid').html('<%= j(render(collection)).strip.html_safe %>');
$assembliesCount.html('<%= j(render partial: "count").strip.html_safe %>');
$assembliesFilter.html('<%= j(render partial: "decidim/assemblies/filter_by_type") %>');
5 changes: 2 additions & 3 deletions decidim-assemblies/config/locales/en.yml
Expand Up @@ -258,15 +258,14 @@ en:
others: Others
public: Public
filter:
all: All
all: All types of assemblies
commission: Commission
consultative_advisory: Consultative/Advisory
executive: Executive
government: Government
label: 'Show:'
help: 'Show:'
others: Others
participatory: Participatory
placeholder: Filter by type
working_group: Working group
index:
title: Assemblies
Expand Down
22 changes: 11 additions & 11 deletions decidim-assemblies/spec/system/assemblies_spec.rb
Expand Up @@ -104,8 +104,8 @@
end

it "lists the parent assemblies" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("2")
end

Expand All @@ -127,54 +127,54 @@

before do
visit decidim_assemblies.assemblies_path
click_button "Filter by type"
click_button "All types of assemblies"
end

it "filters by All types" do
click_link "All"
click_link "All types of assemblies"
expect(page).to have_selector("article.card.card--assembly", count: 7)
end

it "filters by Government type" do
click_link "Government"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Government")
expect(page).to have_selector("#button-text", text: "Government")
end

it "filters by Executive type" do
click_link "Executive"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Executive")
expect(page).to have_selector("#button-text", text: "Executive")
end

it "filters by Consultative/Advisory type" do
click_link "Consultative/Advisory"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Consultative/Advisory")
expect(page).to have_selector("#button-text", text: "Consultative/Advisory")
end

it "filters by Participatory type" do
click_link "Participatory"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Participatory")
expect(page).to have_selector("#button-text", text: "Participatory")
end

it "filters by Working group type" do
click_link "Working group"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Working group")
expect(page).to have_selector("#button-text", text: "Working group")
end

it "filters by Commission type" do
click_link "Commission"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Commission")
expect(page).to have_selector("#button-text", text: "Commission")
end

it "filters by Others type" do
click_link "Others"
expect(page).to have_selector("article.card.card--assembly", count: 1)
expect(page).to have_content("Others")
expect(page).to have_selector("#button-text", text: "Others")
end
end

Expand Down
24 changes: 12 additions & 12 deletions decidim-assemblies/spec/system/private_assemblies_spec.rb
Expand Up @@ -23,8 +23,8 @@
end

it "lists all the assemblies" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("2")
end

Expand All @@ -44,8 +44,8 @@
end

it "lists all the assemblies" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("2")
end

Expand All @@ -68,8 +68,8 @@
end

it "lists only the not private assembly" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("1")
end

Expand All @@ -89,8 +89,8 @@
end

it "lists only the not private assembly" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("1")
end

Expand All @@ -109,8 +109,8 @@
end

it "lists private assemblies" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("2")
end

Expand All @@ -137,8 +137,8 @@
end

it "lists private assemblies" do
within "#assemblies-grid" do
within "#assemblies-grid h2" do
within "#parent-assemblies" do
within "#parent-assemblies h2" do
expect(page).to have_content("2")
end

Expand Down

0 comments on commit 2c9d4d7

Please sign in to comment.