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
gem 'activeadmin'
gem 'has_scope'
gem 'preserve'
# Markdown display
gem 'kramdown'

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,12 @@
# The top level controller, where can be centralised almost everything
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.
# For APIs, you may want to use :null_session instead.
protect_from_forgery prepend: true, with: :exception
preserve :region, :tag, :near
layout :handle_xhr_layout
private
@ -14,12 +16,10 @@ class ApplicationController < ActionController::Base
http_accept_language.compatible_language_from I18n.available_locales
end
# Mechanism to manage the region filter
def set_filters
if params.include? :region
session[:region] = params[:region] == 'all' ? nil : params[:region].to_i
end
params[:region] ||= session[:region]
# Mechanism to manage filter resets
def discard
params.keys.keep_if { |key| params[key].empty? }
.each { |key| session.delete ['application', key].join '_' }
end
protected

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
%ul.counters
-# 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
%li{ title: Kind.human_attribute_name("name_#{kind.name}") }
= link_to orgas_url(q: p) do
@ -16,4 +16,4 @@
|
= link_to orgas_url(q: p) do
%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
.field.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')
.field.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')
%span.helper km
@ -22,12 +24,12 @@
= label_tag :region, t('.region')
= select_tag :region,
options_from_collection_for_select(Region.all, :id, :name,
session[:region]),
params[:region]),
include_blank: true
.field.tags
= label_tag :tag, t('.tag'), for: 'tag_tag'
= text_field_tag :tag
= text_field_tag :tag, params[:tag]
.field.future
= 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?
= link_to filter_region.url do
- if filter_region.code.present?
@ -7,16 +7,14 @@
%small
%em.fa.fa-external-link-alt
- else
= link_to tag: params[:tag],
region: session[:region] == filter_region.id ? :all : filter_region,
start_date: params[:start_date],
year: params[:year] do
= link_to start_date: params[:start_date], year: params[:year],
region: params[:region] == filter_region.id.to_s ? '' : filter_region do
- if filter_region.code.present?
= flag_icon filter_region.code.downcase
- else
%em.fa.fa-shield-alt
= filter_region.name
- if session[:region] == filter_region.id
- if params[:region] == filter_region.id.to_s
%em.fa.fa-times
- elsif !filter_region.region && filter_region.regions.present?
%small