Permanent filters: "near" and "tag"

This commit is contained in:
echarp 2018-10-17 15:47:43 +02:00
parent 02f8977dc5
commit a75f7c5314
19 changed files with 75 additions and 52 deletions

View File

@ -46,6 +46,7 @@ gem 'differ'
# A generic library to administrate the tool # A generic library to administrate the tool
gem 'activeadmin' gem 'activeadmin'
gem 'has_scope' gem 'has_scope'
gem 'preserve'
# Markdown display # Markdown display
gem 'kramdown' gem 'kramdown'

View File

@ -114,7 +114,7 @@ GEM
ffi (1.9.25) ffi (1.9.25)
flag-icons-rails (3.1.0) flag-icons-rails (3.1.0)
sass (~> 3.2) sass (~> 3.2)
font-awesome-sass (5.3.1) font-awesome-sass (5.4.1)
sassc (>= 1.11) sassc (>= 1.11)
formatador (0.2.5) formatador (0.2.5)
formtastic (3.1.5) formtastic (3.1.5)
@ -272,6 +272,8 @@ GEM
activesupport activesupport
rails (>= 3.0.0) rails (>= 3.0.0)
powerpack (0.1.2) powerpack (0.1.2)
preserve (0.1.0)
rails (>= 3.0)
pry (0.11.3) pry (0.11.3)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.9.0) method_source (~> 0.9.0)
@ -476,6 +478,7 @@ DEPENDENCIES
mysql2 mysql2
paper_trail paper_trail
piwik_analytics piwik_analytics
preserve
puma (~> 3.7) puma (~> 3.7)
rack-livereload rack-livereload
rails (>= 5.1.4) rails (>= 5.1.4)

View File

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

View File

@ -74,18 +74,19 @@ header.top
text-align: left text-align: left
img.logo img.logo
float: left float: left
margin-right: 2% margin-right: 1%
h1 h1
margin-top: 0 margin: 0
margin-bottom: 0.2em padding: 0
h2 h2
font: font:
size: inherit size: inherit
style: italic style: italic
weight: normal weight: normal
margin-top: 0 margin-top: 0.2em
main, body.mce-content-body main, body.mce-content-body
clear: both
position: relative position: relative
h3 h3
text-align: left text-align: left
@ -109,6 +110,7 @@ aside
z-index: 10 z-index: 10
padding: 5px padding: 5px
position: relative position: relative
max-width: 20em
box-shadow: 4px 4px 1em gray box-shadow: 4px 4px 1em gray
margin-right: -4em margin-right: -4em
border-radius: 1em border-radius: 1em

View File

@ -180,7 +180,7 @@ input, textarea, select, a.button, .actions > button, .mce-tinymce, div.tagsinpu
&.period_week label:before &.period_week label:before
content: fa-content($fa-var-step-backward) content: fa-content($fa-var-step-backward)
&.near_location label:before &.near_location label:before
content: fa-content($fa-var-dot-circle) content: fa-content($fa-var-map-pin)
&.near_distance label:before &.near_distance label:before
content: fa-content($fa-var-arrows-alt-h) content: fa-content($fa-var-arrows-alt-h)
&.iframe label:before &.iframe label:before

View File

@ -17,7 +17,7 @@
main ul main ul
margin-left: 0 margin-left: 0
form#orga_search form#orga_search, button.search, .digest
font-size: smaller !important font-size: smaller !important
table.list.dates table.list.dates
@ -35,14 +35,10 @@
padding-right: 0.4em padding-right: 0.4em
header.top header.top
text-align: center
nav nav
display: none display: none
img.logo img.logo
margin-right: 0 margin-right: 0
h1
padding-top: 0
letter-spacing: initial
form#orga_search form#orga_search
display: none display: none

View File

@ -7,7 +7,8 @@ form#orga_search
clear: right clear: right
float: right float: right
font-size: larger font-size: larger
margin-top: 1em margin-top: 0.9em
margin-left: 1em
label label
display: none display: none
em.fa em.fa

View File

@ -1,3 +1,10 @@
body.pages main body.pages main
h3, h4 h3, h4
text-align: left text-align: left
.digest
float: right
font-size: larger
margin-top: 1em
span
margin-left: 1em

View File

@ -1,5 +1,6 @@
header header
nav nav
max-width: calc(99% - 91px)
margin-top: -3.1em margin-top: -3.1em
&:hover nav &:hover nav
margin-top: 0 margin-top: 0

View File

@ -1,10 +1,12 @@
# 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, :set_filters before_action :set_paper_trail_whodunnit, :discard
# 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 prepend: true, with: :exception protect_from_forgery prepend: true, with: :exception
preserve :region, :tag, :near
layout :handle_xhr_layout layout :handle_xhr_layout
private private
@ -14,12 +16,10 @@ class ApplicationController < ActionController::Base
http_accept_language.compatible_language_from I18n.available_locales http_accept_language.compatible_language_from I18n.available_locales
end end
# Mechanism to manage the region filter # Mechanism to manage filter resets
def set_filters def discard
if params.include? :region params.keys.keep_if { |key| params[key].empty? }
session[:region] = params[:region] == 'all' ? nil : params[:region].to_i .each { |key| session.delete ['application', key].join '_' }
end
params[:region] ||= session[:region]
end end
protected protected

View File

@ -8,28 +8,29 @@ class StatsController < ApplicationController
private private
def counts def counts
@events_count = @events.count @events_count = @events.count :all
@events_um_count = apply_scopes(Event.unmoderated).count @events_um_count = apply_scopes(Event.unmoderated).count :all
@orgas_count = apply_scopes(Orga).moderated.count @orgas_count = apply_scopes(Orga).moderated.count :all
@orgas_um_count = apply_scopes(Orga.unmoderated).count @orgas_um_count = apply_scopes(Orga.unmoderated).count :all
end end
def temporal def temporal
@years = @events.group(year_grouping).count @years = @events.group(year_grouping).count :all
@months = @events.group(year_grouping, month_grouping).count @months = @events.group(year_grouping, month_grouping).count :all
end end
def local def local
@region_events = @events.group(:region_id, year_grouping).count @region_events = @events.group(:region_id, year_grouping).count :all
@regions = Region.all.find_all do |region| @regions = Region.all.find_all do |region|
@years.sum { |year| @region_events[[region.id, year[0]]] || 0 }.positive? @years.sum { |year| @region_events[[region.id, year[0]]] || 0 }.positive?
end end
@city_events = @events.group(:city).having('count(city) > 3') @city_events = @events.group(:city).having('count(city) > 3')
.order('count(city) desc').count .order('count(city) desc').count :all
end end
def set_events def set_events
@events = apply_scopes Event.moderated # Remove the ordering which can occur after geocoding
@events = apply_scopes(Event.moderated).reorder nil
end end
def year_grouping def year_grouping

View File

@ -63,8 +63,6 @@ class Event < ApplicationRecord
start_date, start_date.end_of_week.end_of_day start_date, start_date.end_of_week.end_of_day
end) end)
scope :region, (lambda do |region| scope :region, (lambda do |region|
return if region.nil? || region == 'all' || region.to_i.zero?
temp = Region.find region temp = Region.find region
where region: [temp, temp.regions].flatten where region: [temp, temp.regions].flatten
end) end)

View File

@ -33,8 +33,6 @@ class Orga < ApplicationRecord
scope :kind, ->(kind) { where kind: kind } scope :kind, ->(kind) { where kind: kind }
scope :region, (lambda do |region| scope :region, (lambda do |region|
return if region.nil? || region == 'all' || region.to_i.zero?
temp = Region.find region temp = Region.find region
where region: [temp, temp.regions].flatten where region: [temp, temp.regions].flatten
end) end)

View File

@ -20,9 +20,11 @@
- sub = request.domain ? request.domain.split('.')[0] : '' - sub = request.domain ? request.domain.split('.')[0] : ''
%body{ class: [sub, controller_name, action_name] } %body{ class: [sub, controller_name, action_name] }
%header.top %header.top
= render '/regions/filter'
= image_tag 'baby_gnu_adl.png', alt: '', class: :logo = image_tag 'baby_gnu_adl.png', alt: '', class: :logo
= render '/regions/filter'
= render '/orgas/search' = render '/orgas/search'
= render '/pages/search'
%h1= link_to t('.title'), root_path %h1= link_to t('.title'), root_path
%h2= t '.subtitle' %h2= t '.subtitle'

View File

@ -1,9 +1,6 @@
%h2 %h2
%em.fa.fa-map %em.fa.fa-map
= title t '.title' = title t '.title'
- if params[:tag]
%em.fa.fa-tag
%em= params[:tag]
%ul.list#map %ul.list#map
%li %li

View File

@ -3,7 +3,7 @@
%ul.counters %ul.counters
-# The reorder and specific count are required for the "near" scope -# The reorder and specific count are required for the "near" scope
- @unfiltered_orgas.reorder('').group(:kind).count.each do |kind, count| - @unfiltered_orgas.reorder('').group(:kind).count(:all).each do |kind, count|
- 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) do = link_to orgas_url(q: p) do
@ -16,4 +16,4 @@
| |
= link_to orgas_url(q: p) do = link_to orgas_url(q: p) do
%em.fa.fa-heartbeat %em.fa.fa-heartbeat
= @unfiltered_orgas.active.count = @unfiltered_orgas.active.count :all

View File

@ -0,0 +1,18 @@
- if action_name == 'index' && controller_name != 'tags'
.digest
- if params[:tag].present?
%span.tag
%em.fa.fa-tag
= params[:tag]
%a(href="?tag=")
%em.fa.fa-times
- if params[:near].present?
%span.near
%em.fa.fa-map-pin
= params[:near][:location]
%em.fa.fa-arrows-alt-h
= params[:near][:distance]
km
%a(href="?near=")
%em.fa.fa-times

View File

@ -9,12 +9,14 @@
= form_tag events_url, method: :get do = form_tag events_url, method: :get do
.field.near_location .field.near_location
= label_tag 'near[location]', t('.near_location') = label_tag 'near[location]', t('.near_location')
= text_field_tag 'near[location]', params['near[location]'], = text_field_tag 'near[location]',
params[:near].present? ? params[:near][:location] : '',
placeholder: t('.near_location_helper') placeholder: t('.near_location_helper')
.field.near_distance .field.near_distance
= label_tag 'near[distance]', t('.near_distance') = label_tag 'near[distance]', t('.near_distance')
= number_field_tag 'near[distance]', params['near[distance]'], = number_field_tag 'near[distance]',
params[:near].present? ? params[:near][:distance] : '',
placeholder: t('.near_distance_helper') placeholder: t('.near_distance_helper')
%span.helper km %span.helper km
@ -22,12 +24,12 @@
= 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,
session[:region]), params[:region]),
include_blank: true include_blank: true
.field.tags .field.tags
= label_tag :tag, t('.tag'), for: 'tag_tag' = label_tag :tag, t('.tag'), for: 'tag_tag'
= text_field_tag :tag = text_field_tag :tag, params[:tag]
.field.future .field.future
= label_tag :future, t('.past') = label_tag :future, t('.past')

View File

@ -1,4 +1,4 @@
%li{ class: session[:region] == filter_region.id ? 'selected' : '' } %li{ class: params[:region] == filter_region.id.to_s ? 'selected' : '' }
- if filter_region.url.present? - if filter_region.url.present?
= link_to filter_region.url do = link_to filter_region.url do
- if filter_region.code.present? - if filter_region.code.present?
@ -7,16 +7,14 @@
%small %small
%em.fa.fa-external-link-alt %em.fa.fa-external-link-alt
- else - else
= link_to tag: params[:tag], = link_to start_date: params[:start_date], year: params[:year],
region: session[:region] == filter_region.id ? :all : filter_region, region: params[:region] == filter_region.id.to_s ? '' : filter_region do
start_date: params[:start_date],
year: params[:year] do
- if filter_region.code.present? - if filter_region.code.present?
= flag_icon filter_region.code.downcase = flag_icon filter_region.code.downcase
- else - else
%em.fa.fa-shield-alt %em.fa.fa-shield-alt
= filter_region.name = filter_region.name
- if session[:region] == filter_region.id - if params[:region] == filter_region.id.to_s
%em.fa.fa-times %em.fa.fa-times
- elsif !filter_region.region && filter_region.regions.present? - elsif !filter_region.region && filter_region.regions.present?
%small %small