diff --git a/app/controllers/orgas_controller.rb b/app/controllers/orgas_controller.rb index 79bba1ab..f41d5878 100644 --- a/app/controllers/orgas_controller.rb +++ b/app/controllers/orgas_controller.rb @@ -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 diff --git a/app/models/orga.rb b/app/models/orga.rb index 83f0a0fb..b6638ab7 100644 --- a/app/models/orga.rb +++ b/app/models/orga.rb @@ -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 diff --git a/app/views/orgas/_types.haml b/app/views/orgas/_types.haml index ef08c014..8842a4e1 100644 --- a/app/views/orgas/_types.haml +++ b/app/views/orgas/_types.haml @@ -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