From 22251e65164ad4d5ac5a977031e3989a9fd99465 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 12 Nov 2019 16:28:10 +0100 Subject: [PATCH] summary screen TODO: eventModal.html.erb:167 --- .../controllers/admin/calendar.js.erb | 63 ++++++++++++++++++- .../admin/calendar/eventModal.html.erb | 13 +++- config/locales/app.admin.en.yml | 4 ++ config/locales/app.admin.es.yml | 4 ++ config/locales/app.admin.fr.yml | 4 ++ config/locales/app.admin.pt.yml | 4 ++ config/locales/app.shared.en.yml | 1 + config/locales/app.shared.es.yml | 1 + config/locales/app.shared.fr.yml | 1 + config/locales/app.shared.pt.yml | 1 + 10 files changed, 92 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/controllers/admin/calendar.js.erb b/app/assets/javascripts/controllers/admin/calendar.js.erb index 538e4e755..5cb50c0aa 100644 --- a/app/assets/javascripts/controllers/admin/calendar.js.erb +++ b/app/assets/javascripts/controllers/admin/calendar.js.erb @@ -378,8 +378,8 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state /** * Controller used in the slot creation modal window */ -Application.Controllers.controller('CreateEventModalController', ['$scope', '$uibModalInstance', 'moment', 'start', 'end', 'machinesPromise', 'Availability', 'trainingsPromise', 'spacesPromise', 'Tag', 'growl', '_t', - function ($scope, $uibModalInstance, moment, start, end, machinesPromise, Availability, trainingsPromise, spacesPromise, Tag, growl, _t) { +Application.Controllers.controller('CreateEventModalController', ['$scope', '$uibModalInstance', '$sce', 'moment', 'start', 'end', 'machinesPromise', 'Availability', 'trainingsPromise', 'spacesPromise', 'Tag', 'growl', '_t', + function ($scope, $uibModalInstance, $sce, moment, start, end, machinesPromise, Availability, trainingsPromise, spacesPromise, Tag, growl, _t) { // $uibModal parameter $scope.start = start; @@ -426,9 +426,19 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui $scope.availability = { start_at: start, end_at: end, - available_type: 'machines' // default + available_type: 'machines', // default + is_recurrent: false, + period: 'week', + nb_periods: 1, + end_date: undefined // recurrence end }; + // recurrent slots + $scope.occurrences = []; + + // localized name(s) of the reservable item(s) + $scope.reservableName = ''; + /** * Adds or removes the provided machine from the current slot * @param machine {Object} @@ -583,9 +593,56 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui return growl.error(_t('admin_calendar.select_end_date')); } } + // settings are ok + computeOccurrences(); + computeName(); $scope.step++; }; + /** + * Compute the various occurrences of the availability, according to the recurrence settings + */ + const computeOccurrences = function () { + $scope.occurrences = []; + + if ($scope.availability.is_recurrent) { + const date = moment($scope.availability.start_at); + const diff = moment($scope.availability.start_at).diff($scope.availability.end_at); + const end = moment($scope.availability.end_date).endOf('day'); + while (date.isBefore(end)) { + const occur_end = moment(date).add(diff, 'ms'); + $scope.occurrences.push({ + start_at: date.toDate(), + end_at: occur_end.toDate() + }); + date.add($scope.availability.nb_periods, $scope.availability.period); + } + } else { + $scope.occurrences.push({ + start_at: $scope.availability.start_at, + end_at: $scope.availability.end_at + }); + } + }; + + const computeName = function () { + $scope.reservableName = ''; + switch ($scope.availability.available_type) { + case 'machines': + const reservableNames = $scope.selectedMachines.map(function (m) { return $sce.trustAsHtml(`${m.name}`); }); + $scope.reservableName = reservableNames.slice(0, -1).join(', ') + ` ${_t('and')} ` + reservableNames[reservableNames.length - 1]; + break; + case 'training': + $scope.reservableName = $scope.selectedTraining.name; + break; + case 'space': + $scope.reservableName = $scope.selectedSpace.name; + break; + default: + $scope.reservableName = ''; + } + } + // !!! MUST BE CALLED AT THE END of the controller return initialize(); } diff --git a/app/assets/templates/admin/calendar/eventModal.html.erb b/app/assets/templates/admin/calendar/eventModal.html.erb index 03477cb5c..867468330 100644 --- a/app/assets/templates/admin/calendar/eventModal.html.erb +++ b/app/assets/templates/admin/calendar/eventModal.html.erb @@ -154,7 +154,18 @@

{{ 'admin_calendar.summary' }}

- lorem ipsum + {{ 'admin_calendar.about_to_create' | translate:{NUMBER:occurrences.length,TYPE:availability.available_type}:'messageformat'}} +
    +
  • {{slot.start_at | amDateFormat:'L LT'}} - {{slot.end_at | amDateFormat:'LT'}}
  • +
+
+ {{ 'admin_calendar.reservable' }} + +
+
+ {{ 'admin_calendar.labels' }} + {{availability.tag_ids.join(', ') || ('admin_calendar.none' | translate)}} +
diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 1fc01beb8..d298da152 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -55,6 +55,10 @@ en: select_period: "Please select a period for the recurrence" select_nb_period: "Please select a number of periods for the recurrence" select_end_date: "Please select the date of the last occurrence" + about_to_create: "You are about to create the following {TYPE, select, machines{machine} training{training} space{space} other{other}} {NUMBER, plural, one{slot} other{slots}}, {NAME}:" # messageFormat interpolation + reservable: "Reservable(s):" + labels: "Label(s):" + none: "None" the_slot_START-END_has_been_successfully_deleted: "The slot {{START}} - {{END}} has been successfully deleted" # angular interpolation unable_to_delete_the_slot_START-END_because_it_s_already_reserved_by_a_member: "Unable to delete the slot {{START}} - {{END}} because it's already reserved by a member" # angular interpolation you_should_select_at_least_a_machine: "You should select at least one machine on this slot." diff --git a/config/locales/app.admin.es.yml b/config/locales/app.admin.es.yml index 5809dba58..024c73127 100644 --- a/config/locales/app.admin.es.yml +++ b/config/locales/app.admin.es.yml @@ -55,6 +55,10 @@ es: select_period: "Please select a period for the recurrence" # translation_missing select_nb_period: "Please select a number of periods for the recurrence" # translation_missing select_end_date: "Please select the date of the last occurrence" # translation_missing + about_to_create: "You are about to create the following {TYPE, select, machines{machine} training{training} space{space} other{other}} {NUMBER, plural, one{slot} other{slots}}, {NAME}:" # messageFormat interpolation # translation_missing + reservable: "Reservable(s):" # translation_missing + labels: "Etiqueta(s):" + none: "Ninguna" the_slot_START-END_has_been_successfully_deleted: "La ranura {{START}} - {{END}} se ha eliminado correctamente" # angular interpolation unable_to_delete_the_slot_START-END_because_it_s_already_reserved_by_a_member: "No se puede eliminar la ranura {{START}} - {{END}} porque ya está reservada por un miembror" # angular interpolation you_should_select_at_least_a_machine: "Debe seleccionar al menos una máquina en esta ranura." diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 2c939bcf9..2015b063c 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -55,6 +55,10 @@ fr: select_period: "Veuillez choisir une période pour la récurrence" select_nb_period: "Veuillez choisir un nombre de périodes pour la récurrence" select_end_date: "Veuillez choisir la date de dernière occurrence" + about_to_create: "Vous vous apprêtez à créer {NUMBER, plural, one{le créneau} other{les créneaux}} {TYPE, select, machines{machine} training{formation} space{espace} other{autre}} {NAME} suivant :" # messageFormat interpolation + reservable: "Réservable(s) :" + labels: "Étiquette(s) :" + none: "Aucune" the_slot_START-END_has_been_successfully_deleted: "Le créneau {{START}} - {{END}} a bien été supprimé" # angular interpolation unable_to_delete_the_slot_START-END_because_it_s_already_reserved_by_a_member: "Le créneau {{START}} - {{END}} n'a pu être supprimé car il est déjà réservé par un membre" # angular interpolation you_should_select_at_least_a_machine: "Vous devriez sélectionner au moins une machine pour ce créneau." diff --git a/config/locales/app.admin.pt.yml b/config/locales/app.admin.pt.yml index 1b4322461..a3e330dee 100755 --- a/config/locales/app.admin.pt.yml +++ b/config/locales/app.admin.pt.yml @@ -55,6 +55,10 @@ pt: select_period: "Please select a period for the recurrence" # translation_missing select_nb_period: "Please select a number of periods for the recurrence" # translation_missing select_end_date: "Please select the date of the last occurrence" # translation_missing + about_to_create: "You are about to create the following {TYPE, select, machines{machine} training{training} space{space} other{other}} {NUMBER, plural, one{slot} other{slots}}, {NAME}:" # messageFormat interpolation # translation_missing + reservable: "Reservable(s) :" # translation_missing + labels: "Etiqueta(s):" + none: "Nenhuma" the_slot_START-END_has_been_successfully_deleted: "O slot {{START}} - {{END}} foi deletado com sucesso" # angular interpolation unable_to_delete_the_slot_START-END_because_it_s_already_reserved_by_a_member: "Não é possível deletar o slot {{START}} - {{END}} porque já foi reservado por um membro" # angular interpolation you_should_select_at_least_a_machine: "Você deveria selecionar a última máquina neste slot." diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index a35125a9d..efd840816 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -79,6 +79,7 @@ en: to_date: "to" # context: date. eg: "from 01/01 to 01/05" to_time: "to" # context: time. eg. "from 18:00 to 21:00" or: "or" + and: "and" change_my_data: "Change my data" sync_my_profile: "Sync my profile" once_your_data_are_up_to_date_: "Once your data are up to date," diff --git a/config/locales/app.shared.es.yml b/config/locales/app.shared.es.yml index 4b61ef146..4f3bbb25a 100644 --- a/config/locales/app.shared.es.yml +++ b/config/locales/app.shared.es.yml @@ -79,6 +79,7 @@ es: to_date: "Hasta" # context: date. eg: "Hasta 01/01 to 01/05" to_time: "Hasta" # context: time. eg. "Hasta 18:00 to 21:00" or: "ó" + and: "y" change_my_data: "Cambiar mis datos" sync_my_profile: "Sincronizar mi perfil" once_your_data_are_up_to_date_: "Una vez sus datos hayan sido actualizados," diff --git a/config/locales/app.shared.fr.yml b/config/locales/app.shared.fr.yml index f5de76751..9116b6daf 100644 --- a/config/locales/app.shared.fr.yml +++ b/config/locales/app.shared.fr.yml @@ -79,6 +79,7 @@ fr: to_date: "au" # context: date. eg: "from 01/01 to 01/05" to_time: "à" # context: time. eg. "from 18:00 to 21:00" or: "ou" + and: "et" change_my_data: "Modifier mes données" sync_my_profile: "Synchroniser mon profil" once_your_data_are_up_to_date_: "Une fois vos données à jour," diff --git a/config/locales/app.shared.pt.yml b/config/locales/app.shared.pt.yml index fd38215bd..725f06c58 100755 --- a/config/locales/app.shared.pt.yml +++ b/config/locales/app.shared.pt.yml @@ -79,6 +79,7 @@ pt: to_date: "até" # context: date. eg: "from 01/01 to 01/05" to_time: "até" # context: time. eg. "from 18:00 to 21:00" or: "ou" + and: "e" change_my_data: "Alterar meus dados" sync_my_profile: "Sincronizar meu perfil" once_your_data_are_up_to_date_: "Uma vez que seus dados estão atualizados,"