Work on the weekly digest. Refs #4
This commit is contained in:
parent
2e2d790d35
commit
a9981262c5
5
Gemfile
5
Gemfile
@ -15,6 +15,9 @@ gem 'has_scope'
|
||||
# Use Capistrano for deployment
|
||||
# gem 'capistrano-rails', group: :development
|
||||
|
||||
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
||||
gem 'jbuilder'
|
||||
|
||||
gem 'haml-rails'
|
||||
|
||||
gem 'devise'
|
||||
@ -108,8 +111,6 @@ group :development, :test, :assets do
|
||||
# faster. Read more: https://github.com/rails/turbolinks
|
||||
gem 'turbolinks'
|
||||
gem 'jquery-turbolinks'
|
||||
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
||||
gem 'jbuilder'
|
||||
# bundle exec rake doc:rails generates the API under doc/api.
|
||||
gem 'sdoc', '~> 0.4.0', group: :doc
|
||||
|
||||
|
26
Gemfile.lock
26
Gemfile.lock
@ -81,7 +81,7 @@ GEM
|
||||
bourbon (4.2.6)
|
||||
sass (~> 3.4)
|
||||
thor (~> 0.19)
|
||||
brakeman (3.1.1)
|
||||
brakeman (3.1.2)
|
||||
erubis (~> 2.6)
|
||||
fastercsv (~> 1.5)
|
||||
haml (>= 3.0, < 5.0)
|
||||
@ -89,13 +89,14 @@ GEM
|
||||
multi_json (~> 1.2)
|
||||
ruby2ruby (>= 2.1.1, < 2.3.0)
|
||||
ruby_parser (~> 3.7.0)
|
||||
safe_yaml
|
||||
sass (~> 3.0)
|
||||
slim (>= 1.3.6, < 4.0)
|
||||
terminal-table (~> 1.4)
|
||||
buftok (0.2.0)
|
||||
builder (3.2.2)
|
||||
byebug (6.0.2)
|
||||
chunky_png (1.3.4)
|
||||
byebug (8.0.0)
|
||||
chunky_png (1.3.5)
|
||||
coderay (1.1.0)
|
||||
coffee-rails (4.1.0)
|
||||
coffee-script (>= 2.2.0)
|
||||
@ -152,7 +153,7 @@ GEM
|
||||
formtastic (3.1.3)
|
||||
actionpack (>= 3.2.13)
|
||||
formtastic_i18n (0.4.1)
|
||||
geocoder (1.2.11)
|
||||
geocoder (1.2.12)
|
||||
globalid (0.3.6)
|
||||
activesupport (>= 4.1.0)
|
||||
guard (2.13.0)
|
||||
@ -172,7 +173,7 @@ GEM
|
||||
guard (~> 2.2)
|
||||
guard-compat (~> 1.1)
|
||||
guard-compat (1.2.1)
|
||||
guard-livereload (2.5.0)
|
||||
guard-livereload (2.5.1)
|
||||
em-websocket (~> 0.5)
|
||||
guard (~> 2.8)
|
||||
guard-compat (~> 1.0)
|
||||
@ -245,7 +246,7 @@ GEM
|
||||
railties (>= 3.1)
|
||||
leaflet-rails (0.7.4)
|
||||
libv8 (3.16.14.13)
|
||||
listen (3.0.3)
|
||||
listen (3.0.4)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
loofah (2.0.3)
|
||||
@ -260,7 +261,7 @@ GEM
|
||||
method_source (0.8.2)
|
||||
mime-types (2.6.2)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.8.1)
|
||||
minitest (5.8.2)
|
||||
modernizr-rails (2.7.1)
|
||||
multi_json (1.11.2)
|
||||
multipart-post (2.0.0)
|
||||
@ -337,18 +338,19 @@ GEM
|
||||
request_store (1.2.0)
|
||||
responders (2.1.0)
|
||||
railties (>= 4.2.0, < 5)
|
||||
rubocop (0.34.2)
|
||||
rubocop (0.35.0)
|
||||
astrolabe (~> 1.3)
|
||||
parser (>= 2.2.2.5, < 3.0)
|
||||
parser (>= 2.2.3.0, < 3.0)
|
||||
powerpack (~> 0.1)
|
||||
rainbow (>= 1.99.1, < 3.0)
|
||||
ruby-progressbar (~> 1.4)
|
||||
ruby-progressbar (~> 1.7)
|
||||
ruby-progressbar (1.7.5)
|
||||
ruby2ruby (2.2.0)
|
||||
ruby_parser (~> 3.1)
|
||||
sexp_processor (~> 4.0)
|
||||
ruby_parser (3.7.1)
|
||||
ruby_parser (3.7.2)
|
||||
sexp_processor (~> 4.1)
|
||||
safe_yaml (1.0.4)
|
||||
sass (3.4.19)
|
||||
sass-rails (5.0.4)
|
||||
railties (>= 4.0.0, < 5.0)
|
||||
@ -397,7 +399,7 @@ GEM
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
tinymce-rails (4.2.6)
|
||||
tinymce-rails (4.2.7)
|
||||
railties (>= 3.1.1)
|
||||
tinymce-rails-langs (4.20140129)
|
||||
tinymce-rails (~> 4.0)
|
||||
|
17
app/assets/stylesheets/digest.css.sass
Normal file
17
app/assets/stylesheets/digest.css.sass
Normal file
@ -0,0 +1,17 @@
|
||||
@import compass
|
||||
|
||||
body.digests main
|
||||
padding: 1em
|
||||
max-width: 60em
|
||||
+box-shadow(1px 1px 5px gray)
|
||||
+border-radius(0.4em)
|
||||
|
||||
h2
|
||||
margin: 0
|
||||
padding: 0
|
||||
font-size: larger
|
||||
text-align: left
|
||||
|
||||
textarea
|
||||
width: 40em
|
||||
height: 20em
|
@ -2,7 +2,7 @@
|
||||
@import font-awesome-sprockets
|
||||
@import font-awesome
|
||||
|
||||
.events form, .moderations form, .orgas form
|
||||
.events form, .moderations form, .orgas form, .digests form
|
||||
.field, .actions
|
||||
max-width: 70em
|
||||
text-align: left
|
||||
|
@ -8,8 +8,8 @@ class ApplicationController < ActionController::Base
|
||||
private
|
||||
|
||||
def set_locale
|
||||
I18n.locale = http_accept_language
|
||||
.compatible_language_from I18n.available_locales
|
||||
I18n.locale =
|
||||
http_accept_language.compatible_language_from I18n.available_locales
|
||||
end
|
||||
|
||||
protected
|
||||
|
27
app/controllers/digests_controller.rb
Normal file
27
app/controllers/digests_controller.rb
Normal file
@ -0,0 +1,27 @@
|
||||
# Resume of all events over a period of time
|
||||
class DigestsController < ApplicationController
|
||||
has_scope :region, :locality, :tag
|
||||
has_scope :period, allow_blank: true,
|
||||
type: :hash, using: [:year, :week],
|
||||
default: { year: (Time.zone.today + 7.days).year,
|
||||
week: (Time.zone.today + 7.days).cweek }
|
||||
|
||||
before_action :set_week, if: -> { params[:period] }
|
||||
before_action :set_events, only: [:show]
|
||||
|
||||
def show
|
||||
render params[:id]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_week
|
||||
@week = DateTime.commercial params[:period][:year].to_i,
|
||||
params[:period][:week].to_i
|
||||
end
|
||||
|
||||
def set_events
|
||||
@week ||= Time.zone.today + 7.days
|
||||
@events = apply_scopes Event.moderated
|
||||
end
|
||||
end
|
@ -13,7 +13,7 @@ class EventsController < ApplicationController
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html { render layout: 'iframe' if params[:iframe] }
|
||||
format.json { }
|
||||
format.json {}
|
||||
format.rss { @events = @events.future }
|
||||
format.ics { @events = @events.last_year.includes :region }
|
||||
format.xml { @events = @events.includes :region }
|
||||
|
@ -2,8 +2,12 @@
|
||||
#
|
||||
# Access to OSM controls
|
||||
class MapsController < ApplicationController
|
||||
has_scope :region, :locality, :tag, :daylimit, :week
|
||||
has_scope :region, :locality, :tag, :daylimit
|
||||
has_scope :future, type: :boolean, default: true
|
||||
has_scope :period, allow_blank: true,
|
||||
type: :hash, using: [:year, :week],
|
||||
default: { year: (Time.zone.today + 7.days).year,
|
||||
week: (Time.zone.today + 7.days).cweek }
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
|
@ -23,6 +23,7 @@ class Event < ActiveRecord::Base
|
||||
# after_validation :geocode, if: -> (obj) { obj.address_changed? }
|
||||
after_validation :geocode
|
||||
|
||||
# Mechanism to store some reason which can be used when sending notifications
|
||||
attr_accessor :reason_for_deletion
|
||||
|
||||
after_create EventCallbacks
|
||||
@ -34,21 +35,25 @@ class Event < ActiveRecord::Base
|
||||
scope :last_year, -> { where '? <= end_time', 1.year.ago }
|
||||
scope :past, -> { where 'start_time <= ?', Time.zone.now }
|
||||
scope :future, -> { where '? <= end_time', Time.zone.now }
|
||||
scope :daylimit, -> d { where 'end_time <= ?', (d || 30).to_i.days.from_now }
|
||||
scope :daylimit, -> (d) { where 'end_time <= ?', d.to_i.days.from_now }
|
||||
scope :year, (lambda do |year|
|
||||
where '? <= end_time and start_time <= ?',
|
||||
Date.new(year, 1, 1).beginning_of_week,
|
||||
Date.new(year, 12, 31).end_of_week.end_of_day
|
||||
Date.new(year.to_i, 1, 1).beginning_of_week,
|
||||
Date.new(year.to_i, 12, 31).end_of_week.end_of_day
|
||||
end)
|
||||
scope :month, (lambda do |start_date|
|
||||
start_date ||= Time.zone.today
|
||||
where '? <= end_time and start_time <= ?',
|
||||
start_date.beginning_of_month.beginning_of_week,
|
||||
start_date.end_of_month.end_of_week.end_of_day
|
||||
start_date.to_date.beginning_of_month.beginning_of_week,
|
||||
start_date.to_date.end_of_month.end_of_week.end_of_day
|
||||
end)
|
||||
scope :region, -> region { where region: region unless region == 'all' }
|
||||
scope :locality, -> locality { where locality: locality }
|
||||
scope :tag, -> tag { where 'tags like ?', "%#{tag}%" }
|
||||
scope :period, (lambda do |year, week|
|
||||
start_date = DateTime.commercial(year.to_i, week.to_i)
|
||||
where '? <= end_time and start_time <= ?',
|
||||
start_date, start_date.end_of_week.end_of_day
|
||||
end)
|
||||
scope :region, -> (region) { where region: region unless region == 'all' }
|
||||
scope :locality, -> (locality) { where locality: locality }
|
||||
scope :tag, -> (tag) { where 'tags like ?', "%#{tag}%" }
|
||||
scope :geo, -> { where 'latitude is not null and longitude is not null' }
|
||||
|
||||
before_validation do
|
||||
@ -86,9 +91,7 @@ class Event < ActiveRecord::Base
|
||||
id: id, name: title, tags: tags,
|
||||
popupContent: "<a href=\"/events/#{id}\">#{self}</a>",
|
||||
start_time: start_time, end_time: end_time, locality: locality
|
||||
}, geometry: {
|
||||
type: 'Point', coordinates: [longitude, latitude]
|
||||
} }
|
||||
}, geometry: { type: 'Point', coordinates: [longitude, latitude] } }
|
||||
end
|
||||
|
||||
def full_address
|
||||
|
1
app/views/digests/index.html.haml
Normal file
1
app/views/digests/index.html.haml
Normal file
@ -0,0 +1 @@
|
||||
hello world!!
|
121
app/views/digests/markdown.html.haml
Normal file
121
app/views/digests/markdown.html.haml
Normal file
@ -0,0 +1,121 @@
|
||||
- title = "Agenda du Libre pour la semaine #{@week.cweek} de l'année #{@week.year}"
|
||||
|
||||
- description = capture_haml do
|
||||
- @events.group_by { |evt| evt.start_time.to_date }.sort.each do |day, evts|
|
||||
= l(day, format: :long).capitalize
|
||||
\-----
|
||||
|
||||
- evts.each do |event|
|
||||
* [[#{event.city}] #{event.title}](#{event_url event})
|
||||
\
|
||||
|
||||
- second_part = capture_haml do
|
||||
= title
|
||||
\=====
|
||||
- @events.sort_by { |e| e.start_time }.each do |event|
|
||||
- @event = event
|
||||
[#{event.city}] [#{event.title}](#{event_url event})
|
||||
\-----
|
||||
|
||||
%p= display_date
|
||||
%p= event.full_address
|
||||
|
||||
> #{strip_tags(@event.description).remove(/\n.*/)}
|
||||
|
||||
\
|
||||
* #{link_to @event.url, @event.url}
|
||||
* #{@event.tags.split.collect { |tag| "[#{tag}](#{tag_url tag})" }.join ', '}
|
||||
\
|
||||
|
||||
%h1= title
|
||||
|
||||
:markdown
|
||||
#{description}
|
||||
|
||||
%hr
|
||||
|
||||
:markdown
|
||||
* [April](http://april.org)
|
||||
* [Agenda du Libre](http://www.agendadulibre.org)
|
||||
* [Carte des événements](#{maps_url period:
|
||||
{ year: @week.year, week: @week.cweek }})
|
||||
* [Proposer un événement](http://www.agendadulibre.org/events/new)
|
||||
* [Annuaire des organisations](http://www.agendadulibre.org/orgas)
|
||||
* [Agenda pour la semaine précédante]
|
||||
(http://linuxfr.org/news/agenda-pour-la-semaine-#{(@week - 1.week).cweek}-de-l-annee-#{(@week - 1.week).year}")
|
||||
|
||||
%hr
|
||||
|
||||
:markdown
|
||||
#{second_part}
|
||||
|
||||
%hr
|
||||
|
||||
%form(action='https://linuxfr.org/news' method='post' accept-charset='UTF-8')
|
||||
%input(type='hidden' name='utf8' value='✓')
|
||||
%input(type='hidden' name='news[section_id]' value='9')
|
||||
%input(type='hidden' name='commit' value='Prévisualiser')
|
||||
|
||||
.field.title
|
||||
%label(for='title') Titre
|
||||
%input#title(type='text' name='news[title]' value=title)
|
||||
|
||||
.field.authenticity_token
|
||||
%label(for='token') Jeton
|
||||
%input#token(type='text' name='authenticity_token')
|
||||
|
||||
.field.description
|
||||
%label(for='description') Contenu
|
||||
%textarea#description(name='news[wiki_body]')= description
|
||||
|
||||
.field.links
|
||||
%input(type='hidden' name='news[links_attributes][0][title]'
|
||||
value='April')
|
||||
%input(type='hidden' name='news[links_attributes][0][url]'
|
||||
value='http://april.org')
|
||||
%input(type='hidden' name='news[links_attributes][0][lang]'
|
||||
value='fr')
|
||||
|
||||
%input(type='hidden' name='news[links_attributes][1][title]'
|
||||
value='Agenda du Libre')
|
||||
%input(type='hidden' name='news[links_attributes][1][url]'
|
||||
value='http://www.agendadulibre.org')
|
||||
%input(type='hidden' name='news[links_attributes][1][lang]'
|
||||
value='fr')
|
||||
|
||||
%input(type='hidden' name='news[links_attributes][2][title]'
|
||||
value='Carte des événements')
|
||||
%input(type='hidden' name='news[links_attributes][2][url]'
|
||||
value="#{maps_url period: { year: @week.year, week: @week.cweek }}")
|
||||
%input(type='hidden' name='news[links_attributes][2][lang]'
|
||||
value='fr')
|
||||
|
||||
%input(type='hidden' name='news[links_attributes][3][title]'
|
||||
value='Proposer un événement')
|
||||
%input(type='hidden' name='news[links_attributes][3][url]'
|
||||
value='http://www.agendadulibre.org/events/new')
|
||||
%input(type='hidden' name='news[links_attributes][3][lang]'
|
||||
value='fr' size='2')
|
||||
|
||||
%input(type='hidden' name='news[links_attributes][4][title]'
|
||||
value='Annuaire des organisations')
|
||||
%input(type='hidden' name='news[links_attributes][4][url]'
|
||||
value="http://www.agendadulibre.org/orgas")
|
||||
%input(type='hidden' name='news[links_attributes][4][lang]'
|
||||
value='fr' size='2')
|
||||
|
||||
%input(type='hidden' name='news[links_attributes][5][title]'
|
||||
value='Agenda de la semaine précédante')
|
||||
%input(type='hidden' name='news[links_attributes][5][url]'
|
||||
value="https://linuxfr.org/news/agenda-pour-la-semaine-#{(@week - 1.week).cweek}-de-l-annee-#{(@week - 1.week).year}")
|
||||
%input(type='hidden' name='news[links_attributes][5][lang]'
|
||||
value='fr' size='2')
|
||||
|
||||
.field.description
|
||||
%label(for='second_part') Seconde partie
|
||||
%textarea#second_part(name='news[wiki_second_part]')= second_part
|
||||
|
||||
.actions
|
||||
%button
|
||||
%em.fa.fa-check
|
||||
Prévisualiser
|
@ -3,7 +3,7 @@
|
||||
|
||||
- if params[:year]
|
||||
-# Whole year calendar
|
||||
- @events = @events.year params[:year].to_i
|
||||
- @events = @events.year params[:year]
|
||||
%header.calendar-header.year
|
||||
= link_to '<<', year: params[:year].to_i - 1, tag: params[:tag],
|
||||
region: params[:region]
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
- else
|
||||
-# One month calendar
|
||||
- @events = @events.month params[:start_date].try :to_date
|
||||
- @events = @events.month params[:start_date] ||= Time.zone.today
|
||||
= month_calendar do |date|
|
||||
- capture_haml do
|
||||
.day_number= date.day
|
||||
@ -54,8 +54,6 @@
|
||||
tag: params[:tag], format: :ics, region: params[:region]))
|
||||
|
||||
%a#banner(href='http://april.org/campagne')
|
||||
-# %img(src='http://www.april.org/campagne/images/priorite-logiciel-libre-je-soutiens-april.png'
|
||||
width='580' height='76' alt='Priorité au Logiciel Libre! Je soutiens l\'April.')
|
||||
= image_tag 'priorite-logiciel-libre-je-soutiens-april_2_m.png',
|
||||
width: '374', height: '48',
|
||||
alt: 'Priorité au Logiciel Libre! Je soutiens l\'April.'
|
||||
|
@ -16,6 +16,7 @@ Rails.application.routes.draw do
|
||||
get :validate, :refuse, on: :member
|
||||
put :accept, on: :member
|
||||
end
|
||||
resources :digests, only: [:index, :show]
|
||||
resources :regions, only: [:index]
|
||||
resources :tags, only: [:index, :show]
|
||||
resources :maps, only: [:index]
|
||||
|
Loading…
Reference in New Issue
Block a user