City filter added in most pages.

This filter is based on the geocoding filter, when no distance has been set...

Refs #170
This commit is contained in:
echarp 2020-04-06 16:47:55 +02:00
parent f9470cf07d
commit fb01a0f8da
18 changed files with 53952 additions and 17 deletions

View File

@ -12,6 +12,15 @@ $(document).on 'turbolinks:load', ->
when error.PERMISSION_DENIED
$('ul.regions li#near-me').remove()
$('body.pages.show form').submit ->
# Juggle between near location and city
if $('#near_location').val() && $('#near_distance').val()
$('#city').val('')
else
$('#city').val($('#near_location').val())
$('#near_location').val('')
showPosition = (position) ->
location.replace window.goto.replace '[me]',
"[#{position.coords.latitude.toFixed(2)}, #{position.coords.longitude.toFixed(2)}]"

View File

@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery prepend: true, with: :exception
preserve :region, :tag, :near
preserve :city, :region, :tag, :near
layout :handle_xhr_layout

View File

@ -1,6 +1,6 @@
# A digest of all events over a period of time
class DigestsController < ApplicationController
has_scope :region, :locality, :tag
has_scope :city, :region, :locality, :tag
has_scope :near, type: :hash, using: %i[location distance]
has_scope :period, allow_blank: true, type: :hash, using: %i[year week],
default: (

View File

@ -1,7 +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 :city, :region, :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
has_scope :future, type: :boolean, default: true, only: [:index], if: :future?

View File

@ -2,7 +2,7 @@
#
# Access to OSM controls
class MapsController < ApplicationController
has_scope :region, :locality, :tag, :daylimit, :year
has_scope :city, :region, :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
has_scope :future, type: :boolean, default: true
has_scope :period, type: :hash, using: %i[year week]

View File

@ -1,6 +1,6 @@
# Event management life cycle
class ModerationsController < ApplicationController
has_scope :region, :locality, :tag, :daylimit, :year
has_scope :city, :region, :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
before_action :authenticate_user!

View File

@ -1,6 +1,6 @@
# Groups life cycle
class OrgasController < ApplicationController
has_scope :region, :tag
has_scope :city, :region, :tag
has_scope :near, type: :hash, using: %i[location distance]
has_scope :active, type: :boolean, default: true, allow_blank: true

View File

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

View File

@ -65,6 +65,7 @@ class Event < ApplicationRecord
where '? <= end_time and start_time <= ?',
start_date, start_date.end_of_week.end_of_day
end)
scope :city, ->(city) { where city: city }
scope :region, (lambda do |region|
return if region == 'all'

View File

@ -34,6 +34,7 @@ class Orga < ApplicationRecord
scope :period, ->(_year, _week) {}
scope :kind, ->(kind) { where kind: kind }
scope :city, ->(city) { where city: city }
scope :region, (lambda do |region|
temp = Region.find region
where region: [temp, temp.regions].flatten

View File

@ -5,7 +5,7 @@
- else
= render '/orgas/search'
- if params[:tag].blank? && (params[:near].blank? || params[:near][:location].blank?)
- if params[:tag].blank?
= link_to page_path('filter'), class: 'filter' do
= t 'title', scope: 'pages.filter'

View File

@ -7,10 +7,12 @@
%fieldset
= form_tag events_url, method: :get do
= hidden_field_tag 'city', params[:city]
.field.near_location
= label_tag 'near[location]', t('.near_location')
= text_field_tag 'near[location]',
params[:near].present? ? params[:near][:location] : '',
params[:city] || (params[:near].present? ? params[:near][:location] : ''),
placeholder: t('.near_location_helper')
.field.near_distance
@ -24,8 +26,7 @@
= label_tag :region, t('.region')
= select_tag :region,
options_from_collection_for_select(Region.all, :id, :name,
params[:region]),
include_blank: true
params[:region]), include_blank: true
.field.tag
= label_tag :tag, t('.tag'), for: 'tag_tag'

View File

@ -10,6 +10,12 @@
= params[:near][:distance]
km
%em.fa.fa-times
- elsif params[:city].present?
%li.selected
%a(href="?city=")
%em.fa.fa-map-pin
= params[:city]
%em.fa.fa-times
- else
%li#near-me

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,32 @@
(function() {
var showPosition;
$(document).on('turbolinks:load', function() {
if (!navigator.geolocation) {
return;
}
$('a.near-me').click(function(event) {
event.preventDefault();
window.goto = event.target.href;
return navigator.geolocation.getCurrentPosition(showPosition, function(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
return $('ul.regions li#near-me').remove();
}
});
});
return $('body.pages.show form').submit(function() {
if ($('#near_location').val() && $('#near_distance').val()) {
return $('#city').val('');
} else {
$('#city').val($('#near_location').val());
return $('#near_location').val('');
}
});
});
showPosition = function(position) {
return location.replace(window.goto.replace('[me]', "[" + (position.coords.latitude.toFixed(2)) + ", " + (position.coords.longitude.toFixed(2)) + "]"));
};
}).call(this);