Organisations' filter display active one by default, inactive on after a click

Closes #130
This commit is contained in:
echarp 2019-04-24 19:53:49 +02:00
parent 913534abd4
commit ad0c37e467
3 changed files with 11 additions and 9 deletions

View File

@ -2,6 +2,7 @@
class OrgasController < ApplicationController
has_scope :region, :tag
has_scope :near, type: :hash, using: %i[location distance]
has_scope :active, type: :boolean, default: true, allow_blank: true
before_action :set_orga, except: %i[index new create]
before_action :set_mailer_host

View File

@ -21,7 +21,7 @@ class Orga < ApplicationRecord
# after_validation :geocode, if: -> (obj) { obj.saved_change_to_address? }
after_validation :geocode
scope :active, -> { where active: true }
scope :active, ->(value = true) { where active: value }
scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false }
@ -38,7 +38,6 @@ class Orga < ApplicationRecord
end)
scope :tag, ->(tag) { tagged_with tag }
scope :geo, -> { where 'latitude is not null and longitude is not null' }
scope :active, -> { where active: true }
before_validation do
# Populate submitter using contact info if absent

View File

@ -6,14 +6,16 @@
- @unfiltered_orgas.reorder('').group(:kind).count(:all).each do |kind, count|
- p[:kind_id_eq] = kind.id
%li{ title: Kind.human_attribute_name("name_#{kind.name}") }
= link_to orgas_url(q: p) do
= link_to orgas_url(q: p, active: params[:active]) do
%em.fa{ class: "fa-#{kind.icon}" }
= count
%li{ title: Kind.human_attribute_name('active').pluralize }
%li{ title: Kind.human_attribute_name('active').pluralize + '?' }
- p[:kind_id_eq] = params[:q][:kind_id_eq]
- p[:active_eq] = true
|
= link_to orgas_url(q: p) do
%em.fa.fa-heartbeat
= @unfiltered_orgas.active.count :all
\/
= link_to orgas_url(q: p, active: params[:active].present? && params[:active] != 'true') do
- if params[:active].nil? || params[:active] == 'true'
%em.fa.fa-heartbeat
- else
%em.fa.fa-heart-broken
= @unfiltered_orgas.count