From 9e2134c9cfc8d2ee8ce57e552a8a4f5fc535b7b4 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 27 Nov 2019 16:17:32 +0100 Subject: [PATCH] ics sources configuration interface --- .../controllers/admin/calendar.js.erb | 54 ++++++++++++ .../javascripts/controllers/calendar.js | 2 +- app/assets/javascripts/router.js.erb | 12 +++ app/assets/stylesheets/app.components.scss | 1 + app/assets/stylesheets/app.utilities.scss | 1 + app/assets/stylesheets/application.scss.erb | 6 +- app/assets/stylesheets/modules/icalendar.scss | 10 +++ .../admin/calendar/calendar.html.erb | 12 +-- .../templates/admin/calendar/icalendar.html | 87 +++++++++++++++++++ .../templates/admin/settings/general.html | 4 +- config/locales/app.admin.fr.yml | 14 +++ 11 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 app/assets/stylesheets/modules/icalendar.scss create mode 100644 app/assets/templates/admin/calendar/icalendar.html diff --git a/app/assets/javascripts/controllers/admin/calendar.js.erb b/app/assets/javascripts/controllers/admin/calendar.js.erb index 5b7979642..569d7a35d 100644 --- a/app/assets/javascripts/controllers/admin/calendar.js.erb +++ b/app/assets/javascripts/controllers/admin/calendar.js.erb @@ -755,3 +755,57 @@ Application.Controllers.controller('DeleteRecurrentAvailabilityController', ['$s } } ]); + + + +/** + * Controller used in the iCalendar (ICS) imports management page + */ + +Application.Controllers.controller('AdminICalendarController', ['$scope', + function ($scope) { + // list of ICS sources + $scope.calendars = []; + + // configuration of a new ICS source + $scope.newCalendar = { + color: undefined, + textColor: undefined, + url: undefined, + textHidden: false + }; + + /** + * Save the new iCalendar in database + */ + $scope.save = function () { + $scope.calendars.push(Object.assign({}, $scope.newCalendar)); + $scope.newCalendar.url = undefined; + $scope.newCalendar.color = null; + $scope.newCalendar.textColor = null; + $scope.newCalendar.textHidden = false; + } + + /** + * Return a CSS-like style of the given calendar configuration + * @param calendar + */ + $scope.calendarStyle = function (calendar) { + return { + 'border-color': calendar.color, + 'color': calendar.textColor, + 'width': calendar.textHidden ? '50px' : 'auto', + 'height': calendar.textHidden ? '21px' : 'auto' + }; + } + + /** + * Delete the given calendar from the database + * @param calendar + */ + $scope.delete = function (calendar) { + const idx = $scope.calendars.indexOf(calendar); + $scope.calendars.splice(idx, 1); + } + } +]); diff --git a/app/assets/javascripts/controllers/calendar.js b/app/assets/javascripts/controllers/calendar.js index 43f0542a3..e46eb8db1 100644 --- a/app/assets/javascripts/controllers/calendar.js +++ b/app/assets/javascripts/controllers/calendar.js @@ -170,7 +170,7 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ }; const eventRenderCb = function (event, element) { - if (event.tags.length > 0) { + if (event.tags && event.tags.length > 0) { let html = ''; for (let tag of Array.from(event.tags)) { html += `${tag.name} `; diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb index 12cad9d20..f0476c79c 100644 --- a/app/assets/javascripts/router.js.erb +++ b/app/assets/javascripts/router.js.erb @@ -659,6 +659,18 @@ angular.module('application.router', ['ui.router']) translations: ['Translations', function (Translations) { return Translations.query('app.admin.calendar').$promise; }] } }) + .state('app.admin.calendar.icalendar', { + url: '/admin/calendar/icalendar', + views: { + 'main@': { + templateUrl: '<%= asset_path "admin/calendar/icalendar.html" %>', + controller: 'AdminICalendarController' + } + }, + resolve: { + translations: ['Translations', function (Translations) { return Translations.query('app.admin.icalendar').$promise; }] + } + }) // project's elements .state('app.admin.project_elements', { diff --git a/app/assets/stylesheets/app.components.scss b/app/assets/stylesheets/app.components.scss index 6a1659507..e550aa8ea 100644 --- a/app/assets/stylesheets/app.components.scss +++ b/app/assets/stylesheets/app.components.scss @@ -670,5 +670,6 @@ padding: 10px; font-size: 10px; padding: 2px; margin-left: 10px; + display: inline-block; } } diff --git a/app/assets/stylesheets/app.utilities.scss b/app/assets/stylesheets/app.utilities.scss index 7b6349c1d..ad1d4241c 100644 --- a/app/assets/stylesheets/app.utilities.scss +++ b/app/assets/stylesheets/app.utilities.scss @@ -102,6 +102,7 @@ p, .widget p { .text-italic { font-style: italic; } +.text-left { text-align: left !important; } .text-center { text-align: center; } .text-right { text-align: right; } diff --git a/app/assets/stylesheets/application.scss.erb b/app/assets/stylesheets/application.scss.erb index ada57aaa4..b87230fd9 100644 --- a/app/assets/stylesheets/application.scss.erb +++ b/app/assets/stylesheets/application.scss.erb @@ -32,11 +32,7 @@ @import "app.buttons"; @import "app.components"; @import "app.plugins"; -@import "modules/invoice"; -@import "modules/signup"; -@import "modules/abuses"; -@import "modules/cookies"; -@import "modules/stripe"; +@import "modules/*"; @import "app.responsive"; diff --git a/app/assets/stylesheets/modules/icalendar.scss b/app/assets/stylesheets/modules/icalendar.scss new file mode 100644 index 000000000..a36dafa74 --- /dev/null +++ b/app/assets/stylesheets/modules/icalendar.scss @@ -0,0 +1,10 @@ +.calendar-form { + margin : 2em; + border: 1px solid #ddd; + border-radius: 3px; + padding: 1em; + + & > .input-group, & > .minicolors { + margin-top: 1em; + } +} diff --git a/app/assets/templates/admin/calendar/calendar.html.erb b/app/assets/templates/admin/calendar/calendar.html.erb index f1666a628..ef3345004 100644 --- a/app/assets/templates/admin/calendar/calendar.html.erb +++ b/app/assets/templates/admin/calendar/calendar.html.erb @@ -5,15 +5,17 @@ -
+

{{ 'admin_calendar.calendar_management' }}

-
-
- +
+
+ + +
@@ -28,7 +30,7 @@

{{ 'admin_calendar.legend' }}

- {{ 'admin_calendar.trainings' }}
+ {{ 'admin_calendar.trainings' }}
{{ 'admin_calendar.machines' }}
{{ 'admin_calendar.spaces' }} {{ 'admin_calendar.events' }} diff --git a/app/assets/templates/admin/calendar/icalendar.html b/app/assets/templates/admin/calendar/icalendar.html new file mode 100644 index 000000000..70faf8f5f --- /dev/null +++ b/app/assets/templates/admin/calendar/icalendar.html @@ -0,0 +1,87 @@ +
+
+
+
+ +
+
+
+
+

{{ 'icalendar.icalendar_import' }}

+
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
+ {{ 'icalendar.intro' }} +
+
+ + + + + + + + + + + + + + +
{{ 'icalendar.url' }}{{ 'icalendar.display' }}
{{calendar.url}} {{ calendar.textHidden ? '' : 'icalendar.example' }} + + +
+
+

{{ 'icalendar.new_import' }}

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +
+
+ +
+
+
+
+
diff --git a/app/assets/templates/admin/settings/general.html b/app/assets/templates/admin/settings/general.html index 2822ad1ba..f4f9c0514 100644 --- a/app/assets/templates/admin/settings/general.html +++ b/app/assets/templates/admin/settings/general.html @@ -341,7 +341,9 @@
-
+
+
+
diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index c55d89754..576cada15 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -88,6 +88,20 @@ fr: view_reservations: "Voir les réservations" legend: "Légende" + icalendar: + icalendar: + icalendar_import: "Import iCalendar" + intro: "Fab-manager vous permet d'importer automatiquement des évènements de calendrier, au format iCalendar RFC 5545, depuis des URL externes. Ces URL seront synchronisée toutes les nuits et les évènements seront affichés dans le calendrier publique." + new_import: "Nouvel import ICS" + color: "Couleur" + text_color: "Couleur du texte" + url: "URL" + example: "Exemple" + display: "Affichage" + hide_text: "Cacher le texte" + hidden: "Caché" + shown: "Affiché" + project_elements: # gestion des éléments constituant les projets project_elements: