From 13bc5334cc99fe1c1c3af3f358d3d636ec1a2e62 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 29 Sep 2020 09:39:32 +0200 Subject: [PATCH] ability to configure until when the events are shown on the home page --- CHANGELOG.md | 2 ++ app/assets/javascripts/router.js.erb | 2 +- app/assets/templates/admin/settings/home_page.html | 12 ++++++++++++ app/controllers/api/events_controller.rb | 10 +++++++++- app/models/setting.rb | 3 ++- config/locales/app.admin.en.yml | 7 +++++++ config/locales/app.admin.fr.yml | 7 +++++++ db/seeds.rb | 3 ++- 8 files changed, 42 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9468f9e46..f71aac4a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog Fab-manager +- Ability to configure until when the events are shown on the home page - Fix a bug: managers cannot see passed events +- [TODO DEPLOY] `rails db:seed` ## v4.5.8 2020 Septembre 28 diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb index fe3e7aa14..d14428204 100644 --- a/app/assets/javascripts/router.js.erb +++ b/app/assets/javascripts/router.js.erb @@ -1043,7 +1043,7 @@ angular.module('application.router', ['ui.router']) 'fablab_name', 'name_genre', 'reminder_enable', 'plans_module', 'confirmation_required', \ 'reminder_delay', 'visibility_yearly', 'visibility_others', 'wallet_module', \ 'display_name_enable', 'machines_sort_by', 'fab_analytics', 'statistics_module', \ - 'link_name', 'home_content', 'home_css', 'phone_required']` }).$promise; + 'link_name', 'home_content', 'home_css', 'phone_required', 'upcoming_events_shown']` }).$promise; }], privacyDraftsPromise: ['Setting', function (Setting) { return Setting.get({ name: 'privacy_draft', history: true }).$promise; }], cguFile: ['CustomAsset', function (CustomAsset) { return CustomAsset.get({ name: 'cgu-file' }).$promise; }], diff --git a/app/assets/templates/admin/settings/home_page.html b/app/assets/templates/admin/settings/home_page.html index 2e25386ce..40de310f7 100644 --- a/app/assets/templates/admin/settings/home_page.html +++ b/app/assets/templates/admin/settings/home_page.html @@ -27,6 +27,18 @@ +
+
+ + +
+
diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index e86703835..3c145cb0f 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -36,9 +36,17 @@ class API::EventsController < API::ApiController limit = params[:limit] @events = Event.includes(:event_image, :event_files, :availability, :category) .where('events.nb_total_places != -1 OR events.nb_total_places IS NULL') - .where('availabilities.start_at >= ?', DateTime.current) .order('availabilities.start_at ASC').references(:availabilities) .limit(limit) + + @events = case Setting.get('upcoming_events_shown') + when 'until_start' + @events.where('availabilities.start_at >= ?', DateTime.current) + when '2h_before_end' + @events.where('availabilities.end_at >= ?', DateTime.current + 2.hours) + else + @events.where('availabilities.end_at >= ?', DateTime.current) + end end def show; end diff --git a/app/models/setting.rb b/app/models/setting.rb index d89391f65..7b49466f0 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -105,7 +105,8 @@ class Setting < ApplicationRecord invoice_prefix confirmation_required wallet_module - statistics_module] } + statistics_module + upcoming_events_shown] } # WARNING: when adding a new key, you may also want to add it in app/policies/setting_policy.rb#public_whitelist def value diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 3f9be08be..ce6e9656e 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -1112,6 +1112,7 @@ en: confirmation_is_required: "Confirmation required" wallet_module: "wallet module" statistics_module: "statistics module" + upcoming_events_shown: "display limit for upcoming events" general: general: "General" title: "Title" @@ -1151,6 +1152,12 @@ en: statistics: "Statistics" statistics_info_html: "

Enable or disable the statistics module.

If enabled, every nights, the data of the day just passed will be consolidated in the database of a powerful analysis engine. Then, every administrators will be able to browse statistical charts and tables in the corresponding section.

" enable_statistics: "Enable statistics" + home: + show_upcoming_events: "Show upcoming events" + upcoming_events: + until_start: "Until they start" + 2h_before_end: "Until 2 hours before they end" + until_end: "Until they end" privacy: title: "Privacy" privacy_policy: "Privacy policy" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index a96687d9a..086c7017c 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -1112,6 +1112,7 @@ fr: confirmation_is_required: "Confirmation requise" wallet_module: "module porte-monnaie" statistics_module: "module de statistiques" + upcoming_events_shown: "la limite d'affichage des événements à venir" general: general: "Général" title: "Titre" @@ -1151,6 +1152,12 @@ fr: statistics: "Statistiques" statistics_info_html: "

Activer ou désactiver le module de statistiques.

Si activé, chaque nuit, les données de la journée qui vient de s'écouler seront consolidées dans la base de données d'un puissant moteur d'analyse. Ensuite, chaque administrateur pourra parcourir les tableaux et graphiques statistiques dans la section correspondante.

" enable_statistics: "Activer les statistiques" + home: + show_upcoming_events: "Afficher les prochains événements" + upcoming_events: + until_start: "Jusqu'à ce qu'ils commencent" + 2h_before_end: "Jusqu'à 2 heures avant la fin" + until_end: "Jusqu'à ce qu'ils finissent" privacy: title: "Confidentialité" privacy_policy: "Politique de confidentialité" diff --git a/db/seeds.rb b/db/seeds.rb index 99d950073..a257f13b4 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true if StatisticIndex.count.zero? StatisticIndex.create!([ @@ -892,6 +891,8 @@ Setting.set('wallet_module', true) unless Setting.find_by(name: 'wallet_module') Setting.set('statistics_module', true) unless Setting.find_by(name: 'statistics_module').try(:value) +Setting.set('upcoming_events_shown', 'until_start') unless Setting.find_by(name: 'upcoming_events_shown').try(:value) + if StatisticCustomAggregation.count.zero? # available reservations hours for machines machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: 2)