diff --git a/app/assets/javascripts/filter.js.coffee b/app/assets/javascripts/filter.js.coffee index 37862cfc..5e1ea10f 100644 --- a/app/assets/javascripts/filter.js.coffee +++ b/app/assets/javascripts/filter.js.coffee @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b4d95d9c..3eaaf0b9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/digests_controller.rb b/app/controllers/digests_controller.rb index e3a1d44d..bd0359ba 100644 --- a/app/controllers/digests_controller.rb +++ b/app/controllers/digests_controller.rb @@ -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 diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index dd693b98..3bd59d7a 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -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] diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index dff32b4d..bf016012 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -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| diff --git a/app/controllers/orgas_controller.rb b/app/controllers/orgas_controller.rb index 84bed9fb..67f441aa 100644 --- a/app/controllers/orgas_controller.rb +++ b/app/controllers/orgas_controller.rb @@ -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], diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 532ec544..b84ed995 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -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] diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index de835530..856a4e0c 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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 diff --git a/app/views/events/index.html.haml b/app/views/events/index.html.haml index 1e6bf0f0..79b62617 100644 --- a/app/views/events/index.html.haml +++ b/app/views/events/index.html.haml @@ -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], diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index bec54fc5..b4c0361d 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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/ diff --git a/app/views/orgas/_types.haml b/app/views/orgas/_types.haml index ef28f53e..75362e0a 100644 --- a/app/views/orgas/_types.haml +++ b/app/views/orgas/_types.haml @@ -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 diff --git a/app/views/pages/filter.haml b/app/views/pages/filter.haml index 0086846c..8666c63d 100644 --- a/app/views/pages/filter.haml +++ b/app/views/pages/filter.haml @@ -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 diff --git a/app/views/regions/_filter_region.haml b/app/views/regions/_filter_region.haml index 8b9fc33e..5c14b566 100644 --- a/app/views/regions/_filter_region.haml +++ b/app/views/regions/_filter_region.haml @@ -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], diff --git a/app/views/simple_calendar/_month_calendar.html.haml b/app/views/simple_calendar/_month_calendar.html.haml index 58367aac..2a1819dc 100644 --- a/app/views/simple_calendar/_month_calendar.html.haml +++ b/app/views/simple_calendar/_month_calendar.html.haml @@ -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