From 4a78fdc6a8bb098d6763980b6fa54a59afe7338d Mon Sep 17 00:00:00 2001 From: Khaled Ferjani Date: Mon, 15 Nov 2021 15:39:31 +0100 Subject: [PATCH] #613 set user availability when creating an event (#614) --- src/esn.calendar.libs/app/app.constants.js | 13 +++++++++++++ .../event/form/event-form.controller.js | 4 ++++ .../app/components/event/form/event-form.pug | 13 +++++++++++-- .../app/services/shells/calendar-shell.js | 8 ++++++++ .../services/shells/calendar-shell.spec.js | 19 +++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/esn.calendar.libs/app/app.constants.js b/src/esn.calendar.libs/app/app.constants.js index 91748687..1a140f36 100644 --- a/src/esn.calendar.libs/app/app.constants.js +++ b/src/esn.calendar.libs/app/app.constants.js @@ -296,6 +296,19 @@ label: 'Private' } ] + }, + availability: { + default: 'OPAQUE', + values: [ + { + value: 'OPAQUE', + label: 'Busy' + }, + { + value: 'TRANSPARENT', + label: 'Free' + } + ] } }) diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.controller.js b/src/esn.calendar.libs/app/components/event/form/event-form.controller.js index 9d9b908c..adac164e 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.controller.js +++ b/src/esn.calendar.libs/app/components/event/form/event-form.controller.js @@ -196,6 +196,10 @@ function CalEventFormController( $scope.editedEvent.class = CAL_EVENT_FORM.class.default; } + if (!$scope.editedEvent.availability) { + $scope.editedEvent.availability = CAL_EVENT_FORM.availability.default; + } + $scope.displayParticipationButton = displayParticipationButton(); $scope.displayCalMailToAttendeesButton = displayCalMailToAttendeesButton; $scope.$watch('selectedCalendar.uniqueId', setExcludeCurrentUser); diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.pug b/src/esn.calendar.libs/app/components/event/form/event-form.pug index 93eb6bfd..d5efb1f1 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.pug +++ b/src/esn.calendar.libs/app/components/event/form/event-form.pug @@ -131,7 +131,7 @@ form.event-form(role="form", name="form", aria-hidden="true", ng-class="{ 'reado event-recurrence-edition(ng-click="changeBackdropZIndex()", event="editedEvent", can-modify-event-recurrence='canModifyEventRecurrence') .col-xs-12 cal-event-alarm-edition(ng-click="changeBackdropZIndex()", event="editedEvent", can-modify-event= "canModifyEvent") - .col-xs-12 + div(ng-class="isOrganizer ? 'col-xs-6' : 'col-xs-12'") .form-group .input-group span.input-group-addon @@ -139,7 +139,16 @@ form.event-form(role="form", name="form", aria-hidden="true", ng-class="{ 'reado .fg-line md-input-container(ng-click="changeBackdropZIndex()") md-select(ng-disabled="!canModifyEvent", ng-model='editedEvent.class', md-container-class="cal-select-dropdown", aria-label="visibility") - md-option(ng-value='class.value', ng-repeat="class in CAL_EVENT_FORM.class.values") {{class.label | translate}} + md-option(ng-value='class.value', ng-repeat="class in CAL_EVENT_FORM.class.values") {{class.label | translate}} + div(ng-class="isOrganizer ? 'col-xs-6' : 'col-xs-12'", ng-if="isOrganizer") + .form-group + .input-group + span.input-group-addon + i.mdi.mdi-eye + .fg-line + md-input-container(ng-click="changeBackdropZIndex()") + md-select(ng-disabled="!canModifyEvent", ng-model='editedEvent.availability', md-container-class="cal-select-dropdown", aria-label="availability") + md-option(ng-value='availability.value', ng-repeat="availability in CAL_EVENT_FORM.availability.values") {{ availability.label | translate }} .modal-footer.flex .flex-vertical-centered.flex-start diff --git a/src/esn.calendar.libs/app/services/shells/calendar-shell.js b/src/esn.calendar.libs/app/services/shells/calendar-shell.js index d8557286..c5d7707f 100644 --- a/src/esn.calendar.libs/app/services/shells/calendar-shell.js +++ b/src/esn.calendar.libs/app/services/shells/calendar-shell.js @@ -456,6 +456,14 @@ require('./valarm-shell.js'); vevent.updatePropertyWithValue('class', value); }); this.ensureAlarmCoherence(); + }, + + get availability() { + return this.vevent.getFirstPropertyValue('transp'); + }, + + set availability(value) { + this.vevent.updatePropertyWithValue('transp', value); } }; diff --git a/src/esn.calendar.libs/app/services/shells/calendar-shell.spec.js b/src/esn.calendar.libs/app/services/shells/calendar-shell.spec.js index becbb33a..1609a85c 100644 --- a/src/esn.calendar.libs/app/services/shells/calendar-shell.spec.js +++ b/src/esn.calendar.libs/app/services/shells/calendar-shell.spec.js @@ -2234,4 +2234,23 @@ describe('CalendarShell factory', function() { expect((new CalendarShell(newVCalendar)).dtstamp).to.be.null; }); }); + + describe('the availability setter', () => { + it('should set the event availability', () => { + const vcalendar = ICAL.Component.fromString(__FIXTURES__['src/linagora.esn.calendar/app/fixtures/calendar/event.ics']); + const calendarShell = new CalendarShell(vcalendar); + + calendarShell.availability = 'TRANSPARENT'; + expect(calendarShell.vevent.getFirstPropertyValue('transp')).to.equal('TRANSPARENT'); + }); + }); + + describe('the availability getter', () => { + it('should return the event availability', () => { + const vcalendar = ICAL.Component.fromString(__FIXTURES__['src/linagora.esn.calendar/app/fixtures/calendar/event.ics']); + const calendarShell = new CalendarShell(vcalendar); + + expect(calendarShell.availability).to.equal('OPAQUE'); + }); + }); });