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 # Groups life cycle
class OrgasController < ApplicationController class OrgasController < ApplicationController
has_scope :region
before_action :set_orga, except: [:index, :new, :create] before_action :set_orga, except: [:index, :new, :create]
before_action :set_mailer_host before_action :set_mailer_host
before_action :authenticate_user!, only: [:edit, :update], before_action :authenticate_user!, only: [:edit, :update],
@ -8,7 +10,8 @@ class OrgasController < ApplicationController
:destroy] :destroy]
def index 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? @search.sorts = 'updated_at desc' if @search.sorts.empty?
@orgas = @search.result.page params[:page] @orgas = @search.result.page params[:page]
end end

View File

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

View File

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

View File

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