Browse Source

City filter added in most pages.

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

Refs #170
master
echarp 2 years ago
parent
commit
fb01a0f8da
  1. 9
      app/assets/javascripts/pages.js.coffee
  2. 2
      app/controllers/application_controller.rb
  3. 2
      app/controllers/digests_controller.rb
  4. 2
      app/controllers/events_controller.rb
  5. 2
      app/controllers/maps_controller.rb
  6. 2
      app/controllers/moderations_controller.rb
  7. 2
      app/controllers/orgas_controller.rb
  8. 2
      app/controllers/stats_controller.rb
  9. 1
      app/models/event.rb
  10. 1
      app/models/orga.rb
  11. 2
      app/views/pages/_search.haml
  12. 17
      app/views/pages/filter.haml
  13. 6
      app/views/regions/_filter.haml
  14. 2
      public/assets/.sprockets-manifest-1ecf1692b9cfa13c0271559a479b9688.json
  15. 53885
      public/assets/application-dfb17f4381f1a6caeb36d8a028f05ccab9c3e4c16367de070fd79f3c378b7686.js
  16. BIN
      public/assets/application-dfb17f4381f1a6caeb36d8a028f05ccab9c3e4c16367de070fd79f3c378b7686.js.gz
  17. 32
      public/assets/pages-9095e3d3785d23f61fcfb57e1cb9f4c10cf262409efe6d656b9710c721249e6c.js
  18. BIN
      public/assets/pages-9095e3d3785d23f61fcfb57e1cb9f4c10cf262409efe6d656b9710c721249e6c.js.gz

9
app/assets/javascripts/pages.js.coffee

@ -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)}]"

2
app/controllers/application_controller.rb

@ -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

2
app/controllers/digests_controller.rb

@ -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: (

2
app/controllers/events_controller.rb

@ -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?

2
app/controllers/maps_controller.rb

@ -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]

2
app/controllers/moderations_controller.rb

@ -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!

2
app/controllers/orgas_controller.rb

@ -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

2
app/controllers/stats_controller.rb

@ -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]

1
app/models/event.rb

@ -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'

1
app/models/orga.rb

@ -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

2
app/views/pages/_search.haml

@ -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'

17
app/views/pages/filter.haml

@ -7,25 +7,26 @@
%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] : '',
placeholder: t('.near_location_helper')
params[:city] || (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].present? ? params[:near][:distance] : '',
placeholder: t('.near_distance_helper')
params[:near].present? ? params[:near][:distance] : '',
placeholder: t('.near_distance_helper')
%span.helper km
.field.region
= 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'
@ -85,14 +86,14 @@
.field.period_year
= label_tag 'period[year]', t('.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
:markdown
#{t '.period_year_helper'}
.field.period_week
= label_tag 'period[week]', t('.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
= button_tag formaction: digest_url(:markdown) do

6
app/views/regions/_filter.haml

@ -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

2
public/assets/.sprockets-manifest-1ecf1692b9cfa13c0271559a479b9688.json

File diff suppressed because one or more lines are too long

53885
public/assets/application-dfb17f4381f1a6caeb36d8a028f05ccab9c3e4c16367de070fd79f3c378b7686.js

File diff suppressed because one or more lines are too long

BIN
public/assets/application-dfb17f4381f1a6caeb36d8a028f05ccab9c3e4c16367de070fd79f3c378b7686.js.gz

Binary file not shown.

32
public/assets/pages-9095e3d3785d23f61fcfb57e1cb9f4c10cf262409efe6d656b9710c721249e6c.js

@ -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);

BIN
public/assets/pages-9095e3d3785d23f61fcfb57e1cb9f4c10cf262409efe6d656b9710c721249e6c.js.gz

Binary file not shown.
Loading…
Cancel
Save