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:
parent
f9470cf07d
commit
fb01a0f8da
@ -12,6 +12,15 @@ $(document).on 'turbolinks:load', ->
|
|||||||
when error.PERMISSION_DENIED
|
when error.PERMISSION_DENIED
|
||||||
$('ul.regions li#near-me').remove()
|
$('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) ->
|
showPosition = (position) ->
|
||||||
location.replace window.goto.replace '[me]',
|
location.replace window.goto.replace '[me]',
|
||||||
"[#{position.coords.latitude.toFixed(2)}, #{position.coords.longitude.toFixed(2)}]"
|
"[#{position.coords.latitude.toFixed(2)}, #{position.coords.longitude.toFixed(2)}]"
|
||||||
|
@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
|
|||||||
# 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
|
preserve :city, :region, :tag, :near
|
||||||
|
|
||||||
layout :handle_xhr_layout
|
layout :handle_xhr_layout
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# A digest of all events over a period of time
|
# A digest of all events over a period of time
|
||||||
class DigestsController < ApplicationController
|
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 :near, type: :hash, using: %i[location distance]
|
||||||
has_scope :period, allow_blank: true, type: :hash, using: %i[year week],
|
has_scope :period, allow_blank: true, type: :hash, using: %i[year week],
|
||||||
default: (
|
default: (
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Event life cycle
|
# Event life cycle
|
||||||
# This is a central part to this project
|
# This is a central part to this project
|
||||||
class EventsController < ApplicationController
|
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 :near, type: :hash, using: %i[location distance]
|
||||||
has_scope :future, type: :boolean, default: true, only: [:index], if: :future?
|
has_scope :future, type: :boolean, default: true, only: [:index], if: :future?
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Access to OSM controls
|
# Access to OSM controls
|
||||||
class MapsController < ApplicationController
|
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 :near, type: :hash, using: %i[location distance]
|
||||||
has_scope :future, type: :boolean, default: true
|
has_scope :future, type: :boolean, default: true
|
||||||
has_scope :period, type: :hash, using: %i[year week]
|
has_scope :period, type: :hash, using: %i[year week]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Event management life cycle
|
# Event management life cycle
|
||||||
class ModerationsController < ApplicationController
|
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]
|
has_scope :near, type: :hash, using: %i[location distance]
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Groups life cycle
|
# Groups life cycle
|
||||||
class OrgasController < ApplicationController
|
class OrgasController < ApplicationController
|
||||||
has_scope :region, :tag
|
has_scope :city, :region, :tag
|
||||||
has_scope :near, type: :hash, using: %i[location distance]
|
has_scope :near, type: :hash, using: %i[location distance]
|
||||||
has_scope :active, type: :boolean, default: true, allow_blank: true
|
has_scope :active, type: :boolean, default: true, allow_blank: true
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Generate statistics, around events, by date or place
|
# Generate statistics, around events, by date or place
|
||||||
class StatsController < ApplicationController
|
class StatsController < ApplicationController
|
||||||
has_scope :region, :tag
|
has_scope :city, :region, :tag
|
||||||
has_scope :near, type: :hash, using: %i[location distance]
|
has_scope :near, type: :hash, using: %i[location distance]
|
||||||
|
|
||||||
before_action :set_events, :counts, :temporal, :local, only: [:index]
|
before_action :set_events, :counts, :temporal, :local, only: [:index]
|
||||||
|
@ -65,6 +65,7 @@ class Event < ApplicationRecord
|
|||||||
where '? <= end_time and start_time <= ?',
|
where '? <= end_time and start_time <= ?',
|
||||||
start_date, start_date.end_of_week.end_of_day
|
start_date, start_date.end_of_week.end_of_day
|
||||||
end)
|
end)
|
||||||
|
scope :city, ->(city) { where city: city }
|
||||||
scope :region, (lambda do |region|
|
scope :region, (lambda do |region|
|
||||||
return if region == 'all'
|
return if region == 'all'
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ class Orga < ApplicationRecord
|
|||||||
scope :period, ->(_year, _week) {}
|
scope :period, ->(_year, _week) {}
|
||||||
|
|
||||||
scope :kind, ->(kind) { where kind: kind }
|
scope :kind, ->(kind) { where kind: kind }
|
||||||
|
scope :city, ->(city) { where city: city }
|
||||||
scope :region, (lambda do |region|
|
scope :region, (lambda do |region|
|
||||||
temp = Region.find region
|
temp = Region.find region
|
||||||
where region: [temp, temp.regions].flatten
|
where region: [temp, temp.regions].flatten
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
- else
|
- else
|
||||||
= render '/orgas/search'
|
= 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
|
= link_to page_path('filter'), class: 'filter' do
|
||||||
= t 'title', scope: 'pages.filter'
|
= t 'title', scope: 'pages.filter'
|
||||||
|
|
||||||
|
@ -7,25 +7,26 @@
|
|||||||
|
|
||||||
%fieldset
|
%fieldset
|
||||||
= form_tag events_url, method: :get do
|
= form_tag events_url, method: :get do
|
||||||
|
= hidden_field_tag 'city', params[:city]
|
||||||
|
|
||||||
.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]',
|
= text_field_tag 'near[location]',
|
||||||
params[:near].present? ? params[:near][:location] : '',
|
params[:city] || (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]',
|
= number_field_tag 'near[distance]',
|
||||||
params[:near].present? ? params[:near][:distance] : '',
|
params[:near].present? ? params[:near][:distance] : '',
|
||||||
placeholder: t('.near_distance_helper')
|
placeholder: t('.near_distance_helper')
|
||||||
%span.helper km
|
%span.helper km
|
||||||
|
|
||||||
.field.region
|
.field.region
|
||||||
= 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,
|
||||||
params[:region]),
|
params[:region]), include_blank: true
|
||||||
include_blank: true
|
|
||||||
|
|
||||||
.field.tag
|
.field.tag
|
||||||
= label_tag :tag, t('.tag'), for: 'tag_tag'
|
= label_tag :tag, t('.tag'), for: 'tag_tag'
|
||||||
@ -85,14 +86,14 @@
|
|||||||
.field.period_year
|
.field.period_year
|
||||||
= label_tag 'period[year]', t('.period_year')
|
= label_tag 'period[year]', t('.period_year')
|
||||||
= number_field_tag 'period[year]', params['period[year]'],
|
= number_field_tag 'period[year]', params['period[year]'],
|
||||||
placeholder: "Ex: #{(Time.zone.today + 7.days).year}"
|
placeholder: "Ex: #{(Time.zone.today + 7.days).year}"
|
||||||
.helper
|
.helper
|
||||||
:markdown
|
:markdown
|
||||||
#{t '.period_year_helper'}
|
#{t '.period_year_helper'}
|
||||||
.field.period_week
|
.field.period_week
|
||||||
= label_tag 'period[week]', t('.period_week')
|
= label_tag 'period[week]', t('.period_week')
|
||||||
= number_field_tag 'period[week]', params['period[week]'],
|
= number_field_tag 'period[week]', params['period[week]'],
|
||||||
placeholder: "Ex: #{(Time.zone.today + 7.days).cweek}"
|
placeholder: "Ex: #{(Time.zone.today + 7.days).cweek}"
|
||||||
|
|
||||||
.actions
|
.actions
|
||||||
= button_tag formaction: digest_url(:markdown) do
|
= button_tag formaction: digest_url(:markdown) do
|
||||||
|
@ -10,6 +10,12 @@
|
|||||||
= params[:near][:distance]
|
= params[:near][:distance]
|
||||||
km
|
km
|
||||||
%em.fa.fa-times
|
%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
|
- else
|
||||||
%li#near-me
|
%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
Binary file not shown.
@ -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);
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user