Skip to content

Commit

Permalink
fix: refactor sorts
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Feb 28, 2024
1 parent 1b97530 commit 7c5942a
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ def filtered_processes
def participatory_processes
@participatory_processes ||= filtered_processes.groupless.includes(attachments: :file_attachment)
case search.with_date
when "active", "past", "all"
when "active"
@participatory_processes.sort_by(&:end_date)
when "past"
@participatory_processes.sort_by(&:end_date).reverse

Check warning on line 98 in app/controllers/decidim/participatory_processes/participatory_processes_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim/participatory_processes/participatory_processes_controller.rb#L98

Added line #L98 was not covered by tests
when "upcoming"
@participatory_processes.sort_by(&:start_date)

Check warning on line 100 in app/controllers/decidim/participatory_processes/participatory_processes_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim/participatory_processes/participatory_processes_controller.rb#L100

Added line #L100 was not covered by tests
when "all"
@participatory_processes = sort_all_processes

Check warning on line 102 in app/controllers/decidim/participatory_processes/participatory_processes_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim/participatory_processes/participatory_processes_controller.rb#L102

Added line #L102 was not covered by tests
else
@participatory_processes

Check warning on line 104 in app/controllers/decidim/participatory_processes/participatory_processes_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim/participatory_processes/participatory_processes_controller.rb#L104

Added line #L104 was not covered by tests
end
Expand Down Expand Up @@ -137,6 +141,13 @@ def related_processes
def linked_assemblies
@linked_assemblies ||= current_participatory_space.linked_participatory_space_resources(:assembly, "included_participatory_processes").public_spaces
end

def sort_all_processes
actives = @participatory_processes.select(&:active?).sort_by(&:end_date)
pasts = @participatory_processes.select(&:past?).sort_by(&:end_date).reverse
upcomings = @participatory_processes.select(&:upcoming?).sort_by(&:start_date)
(actives + upcomings + pasts)

Check warning on line 149 in app/controllers/decidim/participatory_processes/participatory_processes_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim/participatory_processes/participatory_processes_controller.rb#L146-L149

Added lines #L146 - L149 were not covered by tests
end
end
end
end

0 comments on commit 7c5942a

Please sign in to comment.