From 53b5b36b68e7b660128c2c7e1d6e3d572c3f694e Mon Sep 17 00:00:00 2001 From: Du Peng Date: Fri, 17 May 2024 18:52:02 +0200 Subject: [PATCH] (bug) unable to update availability slot end time for training --- CHANGELOG.md | 2 ++ .../javascript/controllers/admin/calendar.js | 21 ++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd73ae363..7e4624d33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Next release +- Fix a bug: unable to update availability slot end time for training + ## v6.3.22 2024 Avril 29 - Fix a security issue: updated rails to 7.0.8.1 to fix [CVE-2024-26143](https://github.com/rails/rails/security/advisories/GHSA-9822-6m93-xqf4) diff --git a/app/frontend/src/javascript/controllers/admin/calendar.js b/app/frontend/src/javascript/controllers/admin/calendar.js index e90236798..a766991fc 100644 --- a/app/frontend/src/javascript/controllers/admin/calendar.js +++ b/app/frontend/src/javascript/controllers/admin/calendar.js @@ -1009,18 +1009,6 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui $scope.availability.start_at = $scope.start; }); - // Maintain consistency between the end time and the date object in the availability object - $scope.$watch('end', function (newValue, oldValue, scope) { - if (newValue.valueOf() !== oldValue.valueOf()) { - // we prevent the admin from setting the end of the availability before its beginning - if (moment($scope.start).add($scope.availability.slot_duration, 'minutes').isAfter(newValue)) { - $scope.end = oldValue; - } - // update availability object - $scope.availability.end_at = $scope.end; - } - }); - $scope.$watch('startTime', function (newValue, oldValue, scope) { // adjust the start/endTime const start = moment($scope.start); @@ -1031,6 +1019,15 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui $scope.start = start.toDate(); $scope.endTime = endTime.toDate(); }); + + $scope.$watch('endTime', function (newValue, oldValue, scope) { + // adjust the start/endTime + const end = moment($scope.end); + const diff = moment.tz(newValue, moment.tz.guess()).diff(moment.tz(oldValue, moment.tz.guess())); + end.add(diff, 'milliseconds'); + $scope.end = end.toDate(); + $scope.availability.end_at = $scope.end; + }); }; /*