It is now possible to filter organisations by region. Refs #11

This commit is contained in:
echarp 2015-12-27 16:12:27 +01:00
parent 6981b9a3ea
commit 79cb273d2c
4 changed files with 19 additions and 12 deletions

View File

@ -1,5 +1,7 @@
# Groups life cycle
class OrgasController < ApplicationController
has_scope :region
before_action :set_orga, except: [:index, :new, :create]
before_action :set_mailer_host
before_action :authenticate_user!, only: [:edit, :update],
@ -8,7 +10,8 @@ class OrgasController < ApplicationController
:destroy]
def index
@search = Orga.moderated.includes(:kind).includes(:region).search params[:q]
@search = apply_scopes(Orga).moderated.includes(:kind,
:region).search params[:q]
@search.sorts = 'updated_at desc' if @search.sorts.empty?
@orgas = @search.result.page params[:page]
end

View File

@ -17,6 +17,8 @@ class Orga < ActiveRecord::Base
scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false }
scope :region, ->(region) { where region: region unless region == 'all' }
before_validation do
unless submitter.blank?
self.secret ||= SecureRandom.urlsafe_base64(32)[0...32]

View File

@ -1,9 +1,10 @@
= render 'search'
= render '/regions/selector'
%h2
%em.fa.fa-users
= title t 'orgas.search.title', entity: Orga.model_name.human
= render 'search'
%table.list.autopagerize_page_element
%thead
%th= sort_link @search, :kind_name, Orga.human_attribute_name(:kind)

View File

@ -8,12 +8,12 @@
- elsif params[:locality]
%span.placeholder
%em.locality.fa.fa-globe
=t '.national'
= t '.national'
%em.fa.fa-chevron-down
- else
%span.placeholder
%em.locality.fa.fa-globe
=t '.all_regions'
= t '.all_regions'
%em.fa.fa-chevron-down
-# Choose a region to filter events with
@ -31,10 +31,11 @@
year: params[:year],
tag: params[:tag]
- unless controller.class == OrgasController
%li
= link_to locality: 1,
start_date: params[:start_date],
year: params[:year],
tag: params[:tag] do
%em.fa.fa-globe
=t '.national'
= t '.national'