Orgas filtering can now use the near scope

This commit is contained in:
echarp 2017-09-17 23:43:04 +02:00
parent 12ba0c42dd
commit 01ae744c7b
3 changed files with 76 additions and 70 deletions

View File

@ -9,7 +9,7 @@ class OrgasController < ApplicationController
unless: :check_secret
def index
@unfiltered_orgas = apply_scopes(Orga.moderated).includes(:kind, :region)
@unfiltered_orgas = apply_scopes(Orga.moderated)
@search = @unfiltered_orgas.search params[:q]
@search.sorts = 'updated_at desc' if @search.sorts.empty?
@orgas = @search.result.page params[:page]

View File

@ -2,16 +2,17 @@
- p = params[:q].clone
%ul.counters
- Kind.all.each do |kind|
-# The reorder and specific count are required for the "near" scope
- @unfiltered_orgas.reorder('').group(:kind).count(:id).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
%em.fa{ class: "fa-#{kind.icon}" }
= @unfiltered_orgas.kind(kind).count
= count
%li
- 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
= @unfiltered_orgas.active.count :id

View File

@ -5,6 +5,7 @@
:markdown
#{t '.helper'}
%fieldset
= form_tag events_url, method: :get do
.field.near_location
= label_tag 'near[location]', t('.near_location')
@ -24,18 +25,6 @@
session[:region]),
include_blank: true
.helper
:markdown
#{t '.period_year_helper'}
.field.period_year
= label_tag 'period[year]', t('.period_year')
= number_field_tag 'period[year]', params['period[year]'],
placeholder: "Ex: #{(Time.zone.today + 7.days).year}"
.field.period_week
= label_tag 'period[week]', t('.period_week')
= number_field_tag 'period[week]', params['period[week]'],
placeholder: "Ex: #{(Time.zone.today + 7.days).cweek}"
.field.tags
= label_tag :tag, t('.tag')
= text_field_tag :tag
@ -83,6 +72,22 @@
%em.fa.fa-users
= t '.orgas'
%fieldset
= form_tag events_url, method: :get do
.helper
:markdown
#{t '.period_year_helper'}
.field.period_year
= label_tag 'period[year]', t('.period_year')
= number_field_tag 'period[year]', params['period[year]'],
placeholder: "Ex: #{(Time.zone.today + 7.days).year}"
.field.period_week
= label_tag 'period[week]', t('.period_week')
= number_field_tag 'period[week]', params['period[week]'],
placeholder: "Ex: #{(Time.zone.today + 7.days).cweek}"
.actions
= button_tag formaction: digest_url(:markdown) do
%em.fa.fa-hashtag
= t '.digest'