From ea6694837b0a01e0d762c796b148121e8c4967fc Mon Sep 17 00:00:00 2001 From: echarp Date: Wed, 1 Jan 2014 21:26:35 +0100 Subject: [PATCH] =?UTF-8?q?Proposer=20un=20=C3=A9v=C3=A9nement=20est=20fon?= =?UTF-8?q?ctionnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 6 +- Guardfile | 2 + app/assets/stylesheets/all.css.sass | 14 +- app/assets/stylesheets/events.css.sass | 163 ++++++++++++++------- app/assets/stylesheets/scaffolds.css.scss | 69 --------- app/controllers/events_controller.rb | 58 +++++++- app/models/event.rb | 10 ++ app/views/events/_form.html.haml | 115 ++++++++++----- app/views/events/edit.html.haml | 4 +- app/views/events/new.html.haml | 4 +- app/views/events/show.html.haml | 24 +-- config/initializers/mime_types.rb | 2 +- config/locales/en.yml | 4 + config/locales/fr.yml | 22 +++ test/controllers/events_controller_test.rb | 54 ++++++- test/fixtures/events.yml | 6 +- test/fixtures/regions.yml | 4 +- 18 files changed, 361 insertions(+), 201 deletions(-) delete mode 100644 app/assets/stylesheets/scaffolds.css.scss diff --git a/Gemfile b/Gemfile index 96adedd1..d5adae23 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ gem 'font-awesome-rails' gem 'compass-rails', "~> 2.0.alpha.0" gem 'has_scope' gem 'simple_calendar', github: 'echarp/simple_calendar' +gem 'redcarpet' group :development do gem 'guard-livereload' diff --git a/Gemfile.lock b/Gemfile.lock index a240bff6..ce254c53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: git://github.com/gregbell/active_admin.git - revision: 5e4fe269a32e491d8454ed586a5321a6cfc088cd + revision: 0f333d3a0236de1b13e1cd8cda35f1406c0ceba8 specs: activeadmin (1.0.0.pre) arbre (~> 1.0) @@ -188,11 +188,12 @@ GEM actionpack (>= 3.0) activerecord (>= 3.0) polyamorous (~> 0.6.0) - rb-fsevent (0.9.3) + rb-fsevent (0.9.4) rb-inotify (0.9.3) ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) + redcarpet (3.0.0) responders (1.0.0) railties (>= 3.2, < 5) sass (3.2.13) @@ -250,6 +251,7 @@ DEPENDENCIES mysql2 rails rails-i18n + redcarpet sass-rails sdoc simple_calendar! diff --git a/Guardfile b/Guardfile index b0eb7e6a..77e13b7d 100644 --- a/Guardfile +++ b/Guardfile @@ -25,3 +25,5 @@ guard :minitest do watch(%r{^test/.+_test\.rb}) watch(%r{^test/test_helper\.rb}) { 'test' } end + +notification :notifysend diff --git a/app/assets/stylesheets/all.css.sass b/app/assets/stylesheets/all.css.sass index 60da2d3b..b6358895 100644 --- a/app/assets/stylesheets/all.css.sass +++ b/app/assets/stylesheets/all.css.sass @@ -43,22 +43,22 @@ header.top letter-spacing: 2px h2 font-size: 0.8em - margin-top: 12px + margin-top: 0.9em font-style: italic font-weight: normal padding-bottom: 5px ul.countries top: -8px - right: 0.6em + right: 0.5em position: absolute font-size: 0.7em list-style-type: none li text-align: left - line-height: 1.2em + line-height: 1.3em img - margin-right: 0.6em + margin-right: 0.65em vertical-align: middle main @@ -78,12 +78,14 @@ main margin-left: 2em line-height: 1.3em p - margin: 0.9em 0 + margin: 0.95em 0 line-height: 1.3em text-align: justify + hr + margin: 10px 20px footer.bottom nav - margin: 29px auto -3px + margin: 18px auto -3px font-size: smaller a + a:before color: black diff --git a/app/assets/stylesheets/events.css.sass b/app/assets/stylesheets/events.css.sass index 7a51d9c9..6918d03f 100644 --- a/app/assets/stylesheets/events.css.sass +++ b/app/assets/stylesheets/events.css.sass @@ -1,27 +1,28 @@ @import "compass" form.region_selector - width: 98.4% + width: 98% position: absolute margin-top: 2.6em label display: none main form.region_selector + h2 + width: 100% margin-top: 1.1em - margin-bottom: 2.5em + margin-bottom: 2.32em a font-weight: normal &.previous-month - margin-right: 0.33em + margin-right: 8px &.next-month - margin-left: 0.33em + margin-left: 8px // For whole year calendar main form.region_selector + h2 + h2 - padding: 1px 0 0 + padding: 6px 0 0 font-size: 1.2em - margin-bottom: 19px + margin-bottom: 0.8em table.calendar + h2 margin: 1em @@ -32,59 +33,71 @@ table.calendar margin: 0 auto padding: 0 border-spacing: 2px - th - padding: 0 0 5px 0 - text-transform: capitalize - td - width: 14% !important - height: 4.8em - border: 1px solid #89B7E5 - vertical-align: top - background-color: #A1C3E7 - &.not-current-month - border: none - background-color: #ededed - li - color: #555 - .event - a:link, a:visited - color: #888 - &.today - border: 1px solid #FFB578 - background-color: #ffe0c7 + tr + th + padding-bottom: 0.35em + text-transform: capitalize + td + width: 14% !important + height: 4.8em + border: 1px solid #89B7E5 + vertical-align: top + background-color: #A1C3E7 + &.today + border: 1px solid #FFB578 + background-color: #ffe0c7 + .day_number + color: #544f32 + font-size: 0.8em + margin-top: -1px + &.future + border-color: rgb(150, 207, 255) + background-color: #C6E5FF + .day_number + font-size: 0.8em + margin-top: -1px + &.not-current-month + border: none + background-color: #ededed + li + color: #555 + .event + a:link, a:visited + color: #888 + .day_number - color: #544f32 - font-size: 0.8em + float: left + color: #727070 + margin: 0 1px 3px 1px + font-size: 0.6em + font-weight: bolder + line-height: 1.2em + letter-spacing: 2px + &:hover .day_number + color: black - .day_number - float: left - color: #727070 - margin: 0 1px 3px 1px - font-size: 0.6em - font-weight: bolder - line-height: 1.2em - letter-spacing: 2px - ul - clear: left - margin-left: 0 - padding-left: 15px - list-style-type: circle - li - color: #444 - padding: 0 - margin-bottom: 5px + ul + clear: left + margin-left: 0 + padding-left: 15px + list-style-type: circle + li + color: #444 + margin: 0 + padding: 0 + margin-bottom: 5px - .event - font-size: smaller - line-height: 1.1em - strong:after - content: ':' - margin-right: -1px - a:link, a:visited - color: #666 - font-weight: normal - &:hover - color: black + .event + font-size: smaller + line-height: 1.1em + strong:after + content: ':' + margin-right: -1px + a:link, a:visited + color: #666 + font-weight: normal + &:hover + color: black .formats width: 90% @@ -114,3 +127,41 @@ table.calendar li margin-left: 2em line-height: 1.3em + +#advises + border: 1px solid #FFB578 + margin: 10px 100px 20px 100px + text-align: left + padding-left: 10px + padding-right: 10px + background-color: #ffe0c7 + h1 + font-size: 1.9em + text-align: center + font-weight: normal + a + color: #8F4900 + +form + .field, .actions + text-align: left + margin-left: 2px + margin-bottom: 2px !important + * + vertical-align: middle + p.helper + margin: 1px 5px 1px 6.6em + line-height: 0.9em + label + width: 6.3em + display: inline-block + &:after + content: ':' + input, textarea, select + margin: 3px 0 + border: 1px solid #868686 + &:focus + background-color: #F0F8FF + .actions + margin-left: 6.75em + margin-bottom: 10px diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss deleted file mode 100644 index 6ec6a8ff..00000000 --- a/app/assets/stylesheets/scaffolds.css.scss +++ /dev/null @@ -1,69 +0,0 @@ -body { - background-color: #fff; - color: #333; - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - &:visited { - color: #666; - } - &:hover { - color: #fff; - background-color: #000; - } -} - -div { - &.field, &.actions { - margin-bottom: 10px; - } -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px; - padding-bottom: 0; - margin-bottom: 20px; - background-color: #f0f0f0; - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - margin-bottom: 0px; - background-color: #c00; - color: #fff; - } - ul li { - font-size: 12px; - list-style: square; - } -} diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index de009e5b..764d33d0 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,4 +1,6 @@ class EventsController < InheritedResources::Base + before_action :set_event, only: [:show, :edit, :update, :destroy] + def index respond_to do |format| format.html { @@ -28,8 +30,58 @@ class EventsController < InheritedResources::Base end end + # POST /events + # POST /events.json + def create + @event = Event.new(event_params) + # This is a special case, required to handle the region attribute with same foreign key name + @event.region = Region.find(params[:event][:region]) + + if (params[:visu]) + logger.info 'XXXXXXXXXXXXXXX' + render action: 'new' + return + end + + respond_to do |format| + if @event.save + format.html { redirect_to @event, notice: 'Event was successfully created.' } + format.json { render action: 'show', status: :created, location: @event } + else + format.html { render action: 'new' } + format.json { render json: @event.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /events/1 + # PATCH/PUT /events/1.json + def update + respond_to do |format| + # This is a special case, required to handle the region attribute with same foreign key name + @event.region = Region.find(params[:event][:region]) + if @event.update(event_params) + format.html { redirect_to @event, notice: 'Event was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @event.errors, status: :unprocessable_entity } + end + end + end + private - def permitted_params - params.permit city: [:name, :majname, :postalcode, :inseecode, :regioncode, :latitude, :longitude] - end + def permitted_params + params.permit event: [:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags] + end + + # Use callbacks to share common setup or constraints between actions. + def set_event + @event = Event.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def event_params + params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags) + end end diff --git a/app/models/event.rb b/app/models/event.rb index 5a66ea92..1b29676a 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,6 +1,10 @@ class Event < ActiveRecord::Base belongs_to :region, foreign_key: 'region' + validates_presence_of :region + + default_scope { where moderated: 1 } + scope :year, -> year { where "end_time >= ? and start_time < ?", "#{year}-1-1", "#{year.to_i+1}-1-1" @@ -12,6 +16,12 @@ class Event < ActiveRecord::Base scope :region, -> region { where region: region } scope :tag, -> tag { where "tags like ?", "%#{tag}%" } + before_validation(on: :create) do + self.submission_time = Date.today + self.decision_time = Date.today + end + + def same_day? start_time.to_date == end_time.to_date end diff --git a/app/views/events/_form.html.haml b/app/views/events/_form.html.haml index 47d5bb27..3c0509fe 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -1,3 +1,8 @@ +- if @event && params[:visu] + %hr/ + = render file: '/events/show' + %hr/ + = form_for @event do |f| - if @event.errors.any? #error_explanation @@ -6,59 +11,91 @@ - @event.errors.full_messages.each do |msg| %li= msg + :markdown + Cette page permet de soumettre un évènement dans l'Agenda du Libre. Celui-ci n'apparaîtra pas automatiquement dans l'Agenda, il sera tout d'abord validé par un modérateur. Un courrier électronique vous sera envoyé à l'adresse e-mail de contact donnée ci-dessous lorsque l'évènement aura été modéré. + + #advises + %h1 Recommandations importantes + + :markdown + Ces quelques recommandations vous permettront de proposer un évènement qui sera validé plus rapidement, et dont la lisibilité sera meilleure pour les utilisateurs de l'Agenda du Libre. + + * L'évènement doit concerner le **Logiciel Libre**. L'agenda n'a pas vocation à publier d'autres types d'évènements. + * Le texte des évènements doit être rédigé en français, en **évitant les fautes de grammaire et d'orthographe**. + * Donnez une description **rédigée** de l'évènement, avec des phrases, plutôt qu'un style télégraphique. + * Commencez la description de votre évènement par une phrase reprenant les informations principales, telle que : _« L'association [Zorglub](http://www.asso-zorglub.org) organise une conférence sur le thème des **modèles économiques du Logiciel Libre** le samedi 21 mars de 18h à 20h à la médiathèque Champillion de Montpellier. »_ + * Pensez que le lecteur peut ne pas connaître votre association, le logiciel dont il sera question, etc., donc donnez à chaque fois toutes les informations nécessaires. Rappelez **le principe de l'évènement, le public visé, le lieu exact, la date, l'heure**, même si il est régulier (repas, rencontre régulière, etc.) et que vous avez déjà soumis un évènement du même type dans l'Agenda. + * **Égayez au maximum la description** de votre évènement: lien vers le site de votre association, vers le logiciel ou le langage dont il sera question, vers les organismes partenaires, etc. Pour cela, utilisez les balises HTML pour mettre en gras, en italique, faire des paragraphes et des liens. + * Ne mettez pas l'intégralité des mots en majuscule, que ce soit dans le titre, le nom de la ville ou la description. + * Donnez l'**adresse directe** d'un site Web donnant plus d'informations sur l'évènement. Si l'adresse est la page d'accueil du site de votre organisation, veillez à ce que l'évènement soit clairement visible, et que le lecteur n'ait pas à chercher trop longtemps avant de trouver l'information qu'il cherche. + * La description de l'évènement ne doit pas ressembler à une publicité éhontée pour votre entreprise, projet ou logiciel. Le ton d'un communiqué de presse, par exemple, ne convient pas pour l'Agenda du Libre. + * Les évènements de type professionnel sont acceptés dès lors qu'ils sont accessibles et ouverts à tous. Les évènements payants sont acceptés si le prix de l'entrée ne réserve pas l'évènement à un public uniquement professionnel. + + L'équipe de modération se réserve le droit de modifier la description de l'évènement pour la rendre plus complète, plus lisible ou plus attrayante. + + Si vous soumettez souvent un évènement régulier dans l'Agenda du Libre, vous pouvez automatiser cette procédure à l'aide d'un [script que nous vous proposons](http://agendadulibre.org/submit-script-doc.php). + .field + %p.helper + %strong Décrivez en moins de 5 mots votre évènement, sans y indiquer le lieu, la ville ou la date. = f.label :title - = f.text_field :title + = f.text_field :title, size: 70 .field - = f.label :description - = f.text_area :description - .field - = f.label :start_time + = f.label Event.human_attribute_name :start_time = f.datetime_select :start_time .field - = f.label :end_time + = f.label Event.human_attribute_name :end_time = f.datetime_select :end_time .field - = f.label :city - = f.text_field :city + %p.helper + %strong Décrivez de la manière la plus complète possible votre évènement. + %p.helper + %em + :escaped + Les balises HTML autorisées sont

, , ,