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 ->
$('input[name=utf8]').prop 'disabled', true
$(':input', this).filter ->
this.value.length == 0
this.value.length == 0 && this.name != 'region'
.prop 'disabled', true

View File

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

View File

@ -1,7 +1,7 @@
# A digest of all events over a period of time
class DigestsController < ApplicationController
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],
default: (
lambda do

View File

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

View File

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

View File

@ -1,8 +1,5 @@
# Groups life cycle
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_mailer_host
before_action :authenticate_user!, except: %i[index new create show],

View File

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

View File

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

View File

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

View File

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

View File

@ -5,13 +5,13 @@
- Kind.all.each do |kind|
- p[:kind_id_eq] = kind.id
%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}" }
= @unfiltered_orgas.kind(kind).count
%li
- p[:kind_id_eq] = params[:q][:kind_id_eq]
- 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
= @unfiltered_orgas.active.count

View File

@ -20,7 +20,8 @@
.field.region
= label_tag :region, t('.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
.helper

View File

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

View File

@ -1,17 +1,17 @@
%header.calendar-header
- if params[:year]
= 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]
= start_date.year
- else
= 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]
= link_to root_path(year: start_date.year) do
= start_date.year
= 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
%thead