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

Backport 'Fix order when filtering Meetings' to v0.26 #9751

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
6 changes: 5 additions & 1 deletion decidim-core/app/helpers/decidim/filters_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def filter_form_for(filter, url = url_for, html_options = {})
remote: true,
html: { id: nil }.merge(html_options)
) do |form|
yield form
# Cannot use `concat()` here because it's not available in cells
inner = []
inner << hidden_field_tag("per_page", params[:per_page], id: nil) if params[:per_page]
inner << capture { yield form }
inner.join.html_safe
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def calendar
private

def meetings
@meetings ||= paginate(search.results)
is_past_meetings = params.dig("filter", "date")&.include?("past")
@meetings ||= paginate(search.results.order(start_time: is_past_meetings ? :desc : :asc))
end

def search_klass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def meeting
end

def meetings
@meetings ||= paginate(search.results.order(start_time: :desc))
is_past_meetings = params.dig("filter", "date")&.include?("past")
@meetings ||= paginate(search.results.order(start_time: is_past_meetings ? :desc : :asc))
end

def registration
Expand All @@ -126,7 +127,7 @@ def meeting_form
def default_filter_params
{
search_text: "",
date: %w(upcoming),
date: "upcoming",
activity: "all",
scope_id: default_filter_scope_params,
category_id: default_filter_category_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ def filter_type_values
end

def filter_date_values
TreeNode.new(
TreePoint.new("", t("decidim.meetings.meetings.filters.date_values.all")),
[
TreePoint.new("upcoming", t("decidim.meetings.meetings.filters.date_values.upcoming")),
TreePoint.new("past", t("decidim.meetings.meetings.filters.date_values.past"))
]
)
[
["all", t("decidim.meetings.meetings.filters.date_values.all")],
["upcoming", t("decidim.meetings.meetings.filters.date_values.upcoming")],
["past", t("decidim.meetings.meetings.filters.date_values.past")]
]
end

# Options to filter meetings by activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ def filter_type_values
end

def filter_date_values
TreeNode.new(
TreePoint.new("", t("decidim.meetings.meetings.filters.date_values.all")),
[
TreePoint.new("upcoming", t("decidim.meetings.meetings.filters.date_values.upcoming")),
TreePoint.new("past", t("decidim.meetings.meetings.filters.date_values.past"))
]
)
[
["all", t("decidim.meetings.meetings.filters.date_values.all")],
["upcoming", t("decidim.meetings.meetings.filters.date_values.upcoming")],
["past", t("decidim.meetings.meetings.filters.date_values.past")]
]
end

def directory_filter_scopes_values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>

<% unless @forced_past_meetings %>
<%= form.check_boxes_tree :date, filter_date_values, legend_title: t("decidim.meetings.meetings.filters.date") %>
<%= form.collection_radio_buttons :date, filter_date_values, :first, :last, legend_title: t("decidim.meetings.meetings.filters.date") %>
<% end %>

<%= form.check_boxes_tree :type, filter_type_values, legend_title: t("decidim.meetings.meetings.filters.type") %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= form.hidden_field "state", value: params.dig("filter", "state") %>

<% unless @forced_past_meetings %>
<%= form.check_boxes_tree :date, filter_date_values, legend_title: t(".date") %>
<%= form.collection_radio_buttons :date, filter_date_values, :first, :last, legend_title: t(".date") %>
<% end %>

<%= form.check_boxes_tree :type, filter_type_values, legend_title: t(".type") %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
var $meetings = $('#meetings');
var $meetingsCount = $('#meetings-count');

// make sure that calendar modal will use the updated filter values
var $calendarShare = $('#calendarShare');
$calendarShare.remove();

$meetings.html('<%= j(render partial: "meetings").strip.html_safe %>');
$meetingsCount.html('<%= j(render partial: "count").strip.html_safe %>');

var $dropdownMenu = $('.dropdown.menu', $meetings);
$dropdownMenu.foundation();

$("#calendarShare").foundation(); // initialize export calendar on the page

var markerData = JSON.parse('<%= escape_javascript meetings_data_for_map(search.results.select(&:geocoded_and_valid?)).to_json.html_safe %>');

var $map = $("#map");
Expand Down
4 changes: 2 additions & 2 deletions decidim-meetings/lib/decidim/meetings/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
end

2.times do
start_time = [rand(1..20).weeks.from_now, rand(1..20).weeks.ago].sample
start_time = Faker::Date.between(from: 20.weeks.ago, to: 20.weeks.from_now)
end_time = start_time + [rand(1..4).hours, rand(1..20).days].sample
params = {
component: component,
Expand Down Expand Up @@ -282,7 +282,7 @@
author = user_group.users.sample
end

start_time = [rand(1..20).weeks.from_now, rand(1..20).weeks.ago].sample
start_time = Faker::Date.between(from: 20.weeks.ago, to: 20.weeks.from_now)
params = {
component: component,
scope: Faker::Boolean.boolean(true_ratio: 0.5) ? global : scopes.sample,
Expand Down
113 changes: 80 additions & 33 deletions decidim-meetings/spec/system/explore_meeting_directory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
require "spec_helper"

describe "Explore meeting directory", type: :system do
let(:directory) do
Decidim::Meetings::DirectoryEngine.routes.url_helpers.root_path
end
let(:directory) { Decidim::Meetings::DirectoryEngine.routes.url_helpers.root_path }
let(:organization) { create(:organization) }
let(:participatory_process) { create :participatory_process, organization: organization }
let(:components) do
Expand All @@ -22,12 +20,30 @@
visit directory
end

it "shows all the upcoming meetings" do
within "#meetings" do
expect(page).to have_css(".card--meeting", count: 6)
describe "with default filter" do
let!(:past_meeting) { create(:meeting, :published, start_time: 2.weeks.ago, component: components.first) }
let!(:upcoming_meeting) { create(:meeting, :published, :not_official, component: components.first) }

it "shows all the upcoming meetings" do
visit directory

within ".date_collection_radio_buttons_filter" do
expect(find("input[value='upcoming']").checked?).to be(true)
end

within "#meetings" do
expect(page).to have_css(".card--meeting", count: 7)
end

expect(page).to have_css("#meetings-count", text: "7 MEETINGS")
expect(page).to have_content(translated(upcoming_meeting.title))
end

expect(page).to have_css("#meetings-count", text: "6 MEETINGS")
it "doesn't show past meetings" do
within "#meetings" do
expect(page).not_to have_content(translated(past_meeting.title))
end
end
end

describe "category filter" do
Expand Down Expand Up @@ -143,12 +159,8 @@

describe "type filter" do
context "when there are only online meetings" do
let!(:online_meeting1) do
create(:meeting, :published, :online, component: components.last)
end
let!(:online_meeting2) do
create(:meeting, :published, :online, component: components.last)
end
let!(:online_meeting1) { create(:meeting, :published, :online, component: components.last) }
let!(:online_meeting2) { create(:meeting, :published, :online, component: components.last) }

it "allows filtering by type 'online'" do
within ".type_check_boxes_tree_filter" do
Expand All @@ -163,9 +175,7 @@
end

context "when there are only in-person meetings" do
let!(:in_person_meeting) do
create(:meeting, :published, :in_person, component: components.last)
end
let!(:in_person_meeting) { create(:meeting, :published, :in_person, component: components.last) }

it "allows filtering by type 'in-person'" do
within ".type_check_boxes_tree_filter" do
Expand All @@ -179,9 +189,7 @@
end

context "when there are hybrid meetings" do
let!(:online_meeting) do
create(:meeting, :published, :hybrid, component: components.last)
end
let!(:online_meeting) { create(:meeting, :published, :hybrid, component: components.last) }

it "allows filtering by type 'both'" do
within ".type_check_boxes_tree_filter" do
Expand All @@ -194,19 +202,59 @@
end
end

context "when there's a past meeting" do
let!(:past_meeting) do
create(:meeting, :published, component: components.last, start_time: 1.week.ago)
describe "date filter" do
let!(:past_meeting1) { create(:meeting, :published, component: components.last, start_time: 1.week.ago) }
let!(:past_meeting2) { create(:meeting, :published, component: components.last, start_time: 3.months.ago) }
let!(:past_meeting3) { create(:meeting, :published, component: components.last, start_time: 2.days.ago) }
let!(:upcoming_meeting1) { create(:meeting, :published, component: components.last, start_time: 1.week.from_now) }
let!(:upcoming_meeting2) { create(:meeting, :published, component: components.last, start_time: 3.months.from_now) }
let!(:upcoming_meeting3) { create(:meeting, :published, component: components.last, start_time: 2.days.from_now) }

context "with all meetings" do
it "orders them by start date" do
visit directory

within ".date_collection_radio_buttons_filter" do
choose "All"
end

expect(page).to have_css("#meetings-count", text: "12 MEETINGS")

result = page.find("#meetings .card-grid").text
expect(result.index(translated(past_meeting2.title))).to be < result.index(translated(past_meeting1.title))
expect(result.index(translated(past_meeting1.title))).to be < result.index(translated(past_meeting3.title))
expect(result.index(translated(past_meeting2.title))).to be < result.index(translated(upcoming_meeting1.title))
expect(result.index(translated(upcoming_meeting3.title))).to be < result.index(translated(upcoming_meeting1.title))
expect(result.index(translated(upcoming_meeting1.title))).to be < result.index(translated(upcoming_meeting2.title))
end
end

it "allows filtering by past events" do
within ".date_check_boxes_tree_filter" do
uncheck "All"
check "Past"
context "with past meetings" do
it "orders them by start date" do
visit directory

within ".date_collection_radio_buttons_filter" do
choose "Past"
end

expect(page).to have_css("#meetings-count", text: "3 MEETINGS")

result = page.find("#meetings .card-grid").text
expect(result.index(translated(past_meeting3.title))).to be < result.index(translated(past_meeting1.title))
expect(result.index(translated(past_meeting1.title))).to be < result.index(translated(past_meeting2.title))
end
end

expect(page).to have_content(past_meeting.title["en"])
expect(page).to have_css("#meetings-count", text: "1 MEETING")
context "with upcoming meetings" do
it "orders them by start date" do
visit directory

expect(page).to have_css("#meetings-count", text: "9 MEETINGS")

result = page.find("#meetings .card-grid").text
expect(result.index(translated(upcoming_meeting3.title))).to be < result.index(translated(upcoming_meeting1.title))
expect(result.index(translated(upcoming_meeting1.title))).to be < result.index(translated(upcoming_meeting2.title))
end
end
end

Expand All @@ -232,9 +280,8 @@
# have_content to wait for the card list to change. This is a hack to
# reset the contents to no meetings at all, and then showing only the upcoming
# assembly meetings.
within ".date_check_boxes_tree_filter" do
uncheck "All"
check "Past"
within ".date_collection_radio_buttons_filter" do
choose "Past"
end

expect(page).to have_no_css(".card--meeting")
Expand All @@ -243,8 +290,8 @@
check "Assemblies"
end

within ".date_check_boxes_tree_filter" do
check "Upcoming"
within ".date_collection_radio_buttons_filter" do
choose "Upcoming"
end

expect(page).to have_content(assembly_meeting.title["en"])
Expand Down
Loading