The region filter is now set in the user's session

This commit is contained in:
echarp 2017-07-14 17:50:13 +02:00
parent 98dfad55e0
commit 4e3055ada3
14 changed files with 32 additions and 32 deletions

View File

@ -5,5 +5,5 @@ $(document).on 'turbolinks:load', ->
$('body.pages form').submit -> $('body.pages form').submit ->
$('input[name=utf8]').prop 'disabled', true $('input[name=utf8]').prop 'disabled', true
$(':input', this).filter -> $(':input', this).filter ->
this.value.length == 0 this.value.length == 0 && this.name != 'region'
.prop 'disabled', true .prop 'disabled', true

View File

@ -1,11 +1,13 @@
# The top level controller, where can be centralised almost everything # The top level controller, where can be centralised almost everything
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit before_action :set_paper_trail_whodunnit, :set_locale, :set_filters
before_action :set_locale
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
has_scope :region
has_scope :near, type: :hash, using: %i[location distance]
private private
def set_locale def set_locale
@ -13,6 +15,14 @@ class ApplicationController < ActionController::Base
http_accept_language.compatible_language_from I18n.available_locales http_accept_language.compatible_language_from I18n.available_locales
end end
def set_filters
if params.include? :region
session[:region] = params[:region]
else
params[:region] = session[:region]
end
end
protected protected
# Useful to manage absolute url in mails # Useful to manage absolute url in mails

View File

@ -1,7 +1,7 @@
# A digest of all events over a period of time # A digest of all events over a period of time
class DigestsController < ApplicationController class DigestsController < ApplicationController
has_scope :moderated, default: nil, allow_blank: true has_scope :moderated, default: nil, allow_blank: true
has_scope :region, :locality, :tag has_scope :locality, :tag
has_scope :period, allow_blank: true, type: :hash, using: %i[year week], has_scope :period, allow_blank: true, type: :hash, using: %i[year week],
default: ( default: (
lambda do lambda do

View File

@ -1,8 +1,7 @@
# Event life cycle # Event life cycle
# This is a central part to this project # This is a central part to this project
class EventsController < ApplicationController class EventsController < ApplicationController
has_scope :region, :locality, :tag, :daylimit, :year has_scope :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
before_action :set_events, only: [:index] before_action :set_events, only: [:index]
before_action :set_event, except: %i[index new preview_create create] before_action :set_event, except: %i[index new preview_create create]

View File

@ -2,10 +2,8 @@
# #
# Access to OSM controls # Access to OSM controls
class MapsController < ApplicationController class MapsController < ApplicationController
has_scope :region, :locality, :tag, :daylimit
has_scope :future, type: :boolean, default: true has_scope :future, type: :boolean, default: true
has_scope :period, type: :hash, using: %i[year week] has_scope :period, type: :hash, using: %i[year week]
has_scope :near, type: :hash, using: %i[location distance]
def index def index
respond_to do |format| respond_to do |format|

View File

@ -1,8 +1,5 @@
# Groups life cycle # Groups life cycle
class OrgasController < ApplicationController class OrgasController < ApplicationController
has_scope :region
has_scope :near, type: :hash, using: %i[location distance]
before_action :set_orga, except: %i[index new create] before_action :set_orga, except: %i[index new create]
before_action :set_mailer_host before_action :set_mailer_host
before_action :authenticate_user!, except: %i[index new create show], before_action :authenticate_user!, except: %i[index new create show],

View File

@ -1,7 +1,6 @@
# Generate statistics, around events, by date or place # Generate statistics, around events, by date or place
class StatsController < ApplicationController class StatsController < ApplicationController
has_scope :region, :locality, :tag, :daylimit, :year has_scope :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
before_action :set_events, :counts, :temporal, :local, only: [:index] before_action :set_events, :counts, :temporal, :local, only: [:index]

View File

@ -1,6 +1,6 @@
# Manage event and organisation tags # Manage event and organisation tags
class TagsController < InheritedResources::Base class TagsController < InheritedResources::Base
has_scope :region, :locality, :daylimit has_scope :locality, :daylimit
has_scope :period, type: :hash, using: %i[year week] has_scope :period, type: :hash, using: %i[year week]
has_scope :tag, as: :id has_scope :tag, as: :id

View File

@ -2,12 +2,10 @@
- if params[:year] - if params[:year]
%header.calendar-header.year %header.calendar-header.year
= link_to year: params[:year].to_i - 1, tag: params[:tag], = link_to year: params[:year].to_i - 1, tag: params[:tag] do
region: params[:region] do
%em.fa.fa-backward %em.fa.fa-backward
= params[:year] = params[:year]
= link_to year: params[:year].to_i + 1, tag: params[:tag], = link_to year: params[:year].to_i + 1, tag: params[:tag] do
region: params[:region] do
%em.fa.fa-forward %em.fa.fa-forward
:ruby :ruby
set_meta_tags( set_meta_tags(
@ -39,8 +37,7 @@
.links .links
= raw t '.calendar_in', = raw t '.calendar_in',
map: link_to(t('.map'), maps_path(tag: params[:tag], map: link_to(t('.map'), maps_path(tag: params[:tag])),
region: params[:region])),
rss: link_to('RSS', events_path(:rss, rss: link_to('RSS', events_path(:rss,
tag: params[:tag], region: params[:region])), tag: params[:tag], region: params[:region])),
webcal: link_to('webcal', events_path(tag: params[:tag], webcal: link_to('webcal', events_path(tag: params[:tag],

View File

@ -25,8 +25,7 @@
= render '/regions/filter' = render '/regions/filter'
%h1= link_to t('.title'), root_path %h1= link_to t('.title'), root_path
%h2 %h2= t '.subtitle'
= t '.subtitle'
= render 'layouts/flash', flash: flash if flash.present? = render 'layouts/flash', flash: flash if flash.present?
@ -34,10 +33,10 @@
%footer.bottom %footer.bottom
%nav %nav
= link_to new_event_path region: params[:region] do = link_to new_event_path do
%em.fa.fa-pencil %em.fa.fa-pencil
= t '.propose' = t '.propose'
= link_to new_orga_path region: params[:region] do = link_to new_orga_path do
%em.fa.fa-users %em.fa.fa-users
= t '.propose_orga' = t '.propose_orga'
%br/ %br/

View File

@ -5,13 +5,13 @@
- Kind.all.each do |kind| - Kind.all.each do |kind|
- p[:kind_id_eq] = kind.id - p[:kind_id_eq] = kind.id
%li{ title: Kind.human_attribute_name("name_#{kind.name}") } %li{ title: Kind.human_attribute_name("name_#{kind.name}") }
= link_to orgas_url(q: p, region: params[:region]) do = link_to orgas_url(q: p) do
%em.fa{ class: "fa-#{kind.icon}" } %em.fa{ class: "fa-#{kind.icon}" }
= @unfiltered_orgas.kind(kind).count = @unfiltered_orgas.kind(kind).count
%li %li
- p[:kind_id_eq] = params[:q][:kind_id_eq] - p[:kind_id_eq] = params[:q][:kind_id_eq]
- p[:active_eq] = true - p[:active_eq] = true
= link_to orgas_url(q: p, region: params[:region]) do = link_to orgas_url(q: p) do
%em.fa.fa-heartbeat %em.fa.fa-heartbeat
= @unfiltered_orgas.active.count = @unfiltered_orgas.active.count

View File

@ -20,7 +20,8 @@
.field.region .field.region
= label_tag :region, t('.region') = label_tag :region, t('.region')
= select_tag :region, = select_tag :region,
options_from_collection_for_select(Region.all, :id, :name), options_from_collection_for_select(Region.all, :id, :name,
params[:region]),
include_blank: true include_blank: true
.helper .helper

View File

@ -7,8 +7,8 @@
= link_to filter_region.url do = link_to filter_region.url do
= flag_icon filter_region.code.try :downcase = flag_icon filter_region.code.try :downcase
= filter_region.name = filter_region.name
- if regions.present? %sup
%em.fa.fa-chevron-down %em.fa.fa-external-link
- else - else
= link_to region: filter_region.id, = link_to region: filter_region.id,
start_date: params[:start_date], start_date: params[:start_date],

View File

@ -1,17 +1,17 @@
%header.calendar-header %header.calendar-header
- if params[:year] - if params[:year]
= link_to start_date: start_date.beginning_of_month, = link_to start_date: start_date.beginning_of_month,
tag: params[:tag], region: params[:region] do tag: params[:tag] do
= I18n.t('date.month_names')[start_date.month] = I18n.t('date.month_names')[start_date.month]
= start_date.year = start_date.year
- else - else
= link_to '<<', start_date: (date_range.first - 1.day).beginning_of_month, = link_to '<<', start_date: (date_range.first - 1.day).beginning_of_month,
tag: params[:tag], region: params[:region] tag: params[:tag]
= I18n.t('date.month_names')[start_date.month] = I18n.t('date.month_names')[start_date.month]
= link_to root_path(year: start_date.year) do = link_to root_path(year: start_date.year) do
= start_date.year = start_date.year
= link_to '>>', start_date: (date_range.last + 1.day).beginning_of_month, = link_to '>>', start_date: (date_range.last + 1.day).beginning_of_month,
tag: params[:tag], region: params[:region] tag: params[:tag]
%table.table.table-striped %table.table.table-striped
%thead %thead