-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathcalendarObjectInstance.js
2046 lines (1826 loc) Β· 65.8 KB
/
calendarObjectInstance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import getTimezoneManager from '../services/timezoneDataProviderService.js'
import {
getDateFromDateTimeValue,
} from '../utils/date.js'
import { AttendeeProperty, Property, DateTimeValue, DurationValue, RecurValue, AttachmentProperty, Parameter } from '@nextcloud/calendar-js'
import { getBySetPositionAndBySetFromDate, getWeekDayFromDate } from '../utils/recurrence.js'
import {
copyCalendarObjectInstanceIntoEventComponent,
getDefaultEventObject,
mapEventComponentToEventObject,
} from '../models/event.js'
import {
getAmountAndUnitForTimedEvents,
getAmountHoursMinutesAndUnitForAllDayEvents,
getTotalSecondsFromAmountAndUnitForTimedEvents,
getTotalSecondsFromAmountHourMinutesAndUnitForAllDayEvents,
updateAlarms,
} from '../utils/alarms.js'
import { mapAlarmComponentToAlarmObject } from '../models/alarm.js'
import { getObjectAtRecurrenceId } from '../utils/calendarObject.js'
import logger from '../utils/logger.js'
import { getRFCProperties } from '../models/rfcProps.js'
import { generateUrl } from '@nextcloud/router'
import { updateTalkParticipants } from '../services/talkService.js'
import useCalendarObjectsStore from './calendarObjects.js'
import useCalendarsStore from './calendars.js'
import useSettingsStore from './settings.js'
import { getClosestCSS3ColorNameForHex, getHexForColorName } from '../utils/color.js'
import { defineStore } from 'pinia'
import Vue from 'vue'
export default defineStore('calendarObjectInstance', {
state: () => {
return {
isNew: null,
calendarObject: null,
calendarObjectInstance: null,
existingEvent: {
objectId: null,
recurrenceId: null,
},
}
},
actions: {
/**
* Set a calendar-object-instance that will be opened in the editor (existing event)
*
* @param {object} data The destructuring object
* @param {object} data.calendarObject The calendar-object currently being edited
* @param {object} data.calendarObjectInstance The calendar-object-instance currently being edited
* @param {string} data.objectId The objectId of the calendar-object
* @param {number} data.recurrenceId The recurrence-id of the calendar-object-instance
*/
setCalendarObjectInstanceForExistingEvent({
calendarObject,
calendarObjectInstance,
objectId,
recurrenceId,
}) {
this.isNew = false
this.calendarObject = calendarObject
this.calendarObjectInstance = calendarObjectInstance
this.existingEvent.objectId = objectId
this.existingEvent.recurrenceId = recurrenceId
},
/**
* Set a calendar-object-instance that will be opened in the editor (new event)
*
* @param {object} data The destructuring object
* @param {object} data.calendarObject The calendar-object currently being created
* @param {object} data.calendarObjectInstance The calendar-object-instance currently being crated
*/
setCalendarObjectInstanceForNewEvent({
calendarObject,
calendarObjectInstance,
}) {
this.isNew = true
this.calendarObject = calendarObject
this.calendarObjectInstance = calendarObjectInstance
this.existingEvent.objectId = null
this.existingEvent.recurrenceId = null
},
resetCalendarObjectInstanceObjectIdAndRecurrenceId() {
this.isNew = false
this.calendarObject = null
this.calendarObjectInstance = null
this.existingEvent.objectId = null
this.existingEvent.recurrenceId = null
},
/**
* Change the title of the event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.title The new Title
*/
changeTitle({ calendarObjectInstance, title }) {
calendarObjectInstance.eventComponent.title = title
calendarObjectInstance.title = title
},
/**
* Change the event's start
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {Date} data.startDate New start date to set
*/
changeStartDateMutation({
calendarObjectInstance,
startDate,
}) {
calendarObjectInstance.eventComponent.startDate.year = startDate.getFullYear()
calendarObjectInstance.eventComponent.startDate.month = startDate.getMonth() + 1
calendarObjectInstance.eventComponent.startDate.day = startDate.getDate()
calendarObjectInstance.eventComponent.startDate.hour = startDate.getHours()
calendarObjectInstance.eventComponent.startDate.minute = startDate.getMinutes()
calendarObjectInstance.eventComponent.startDate.second = 0
const isAllDay = calendarObjectInstance.eventComponent.isAllDay()
const endDateObj = calendarObjectInstance.eventComponent.endDate.clone()
const startDateObj = calendarObjectInstance.eventComponent.startDate.clone()
if (isAllDay) {
endDateObj.addDuration(DurationValue.fromSeconds(-1 * 60 * 60 * 24))
if (endDateObj.compare(startDateObj) === -1) {
const timezone = getTimezoneManager().getTimezoneForId(endDateObj.timezoneId)
calendarObjectInstance.eventComponent.endDate
= calendarObjectInstance.eventComponent.startDate.getInTimezone(timezone)
calendarObjectInstance.endDate = getDateFromDateTimeValue(calendarObjectInstance.eventComponent.endDate)
calendarObjectInstance.eventComponent.endDate.addDuration(DurationValue.fromSeconds(60 * 60 * 24))
}
} else {
if (endDateObj.compare(startDateObj) === -1) {
const timezone = getTimezoneManager().getTimezoneForId(endDateObj.timezoneId)
calendarObjectInstance.eventComponent.endDate
= calendarObjectInstance.eventComponent.startDate.getInTimezone(timezone)
calendarObjectInstance.endDate = getDateFromDateTimeValue(calendarObjectInstance.eventComponent.endDate)
}
}
calendarObjectInstance.startDate = startDate
},
/**
* Change the timezone of the event's start
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.startTimezone New timezone to set for start
*/
changeStartTimezoneMutation({
calendarObjectInstance,
startTimezone,
}) {
const timezone = getTimezoneManager().getTimezoneForId(startTimezone)
calendarObjectInstance.eventComponent.startDate.replaceTimezone(timezone)
calendarObjectInstance.startTimezoneId = startTimezone
// Either both are floating or both have a timezone, but it can't be mixed
if (startTimezone === 'floating' || calendarObjectInstance.endTimezoneId === 'floating') {
calendarObjectInstance.eventComponent.endDate.replaceTimezone(timezone)
calendarObjectInstance.endTimezoneId = startTimezone
}
},
/**
* Change the event's end
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {Date} data.endDate New end date to set
*/
changeEndDateMutation({
calendarObjectInstance,
endDate,
}) {
// If the event is using DURATION, endDate is dynamically generated.
// In order to alter it, we need to explicitly set DTEND
const endDateObject = calendarObjectInstance.eventComponent.endDate
calendarObjectInstance.eventComponent.endDate = endDateObject
calendarObjectInstance.eventComponent.endDate.year = endDate.getFullYear()
calendarObjectInstance.eventComponent.endDate.month = endDate.getMonth() + 1
calendarObjectInstance.eventComponent.endDate.day = endDate.getDate()
calendarObjectInstance.eventComponent.endDate.hour = endDate.getHours()
calendarObjectInstance.eventComponent.endDate.minute = endDate.getMinutes()
calendarObjectInstance.eventComponent.endDate.second = 0
const isAllDay = calendarObjectInstance.eventComponent.isAllDay()
const endDateObj = calendarObjectInstance.eventComponent.endDate.clone()
const startDateObj = calendarObjectInstance.eventComponent.startDate.clone()
if (isAllDay) {
if (endDateObj.compare(startDateObj) === -1) {
const timezone = getTimezoneManager().getTimezoneForId(startDateObj.timezoneId)
calendarObjectInstance.eventComponent.startDate
= calendarObjectInstance.eventComponent.endDate.getInTimezone(timezone)
calendarObjectInstance.startDate = getDateFromDateTimeValue(calendarObjectInstance.eventComponent.startDate)
}
// endDate is inclusive, but DTEND needs to be exclusive, so always add one day
calendarObjectInstance.eventComponent.endDate.addDuration(DurationValue.fromSeconds(60 * 60 * 24))
} else {
// Is end before start?
if (endDateObj.compare(startDateObj) === -1) {
// Is end more than one day before start?
endDateObj.addDuration(DurationValue.fromSeconds(60 * 60 * 24))
if (endDateObj.compare(startDateObj) === -1) {
const timezone = getTimezoneManager().getTimezoneForId(startDateObj.timezoneId)
calendarObjectInstance.eventComponent.startDate
= calendarObjectInstance.eventComponent.endDate.getInTimezone(timezone)
calendarObjectInstance.startDate = getDateFromDateTimeValue(calendarObjectInstance.eventComponent.startDate)
} else {
// add one day to endDate if the endDate is before the startDate which allows to easily create events that reach over or to 0:00
calendarObjectInstance.eventComponent.endDate.addDuration(DurationValue.fromSeconds(60 * 60 * 24))
endDate = new Date(endDate.getTime() + 24 * 60 * 60 * 1000)
}
}
}
calendarObjectInstance.endDate = endDate
},
/**
* Change the timezone of the event's end
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.endTimezone New timezone to set for end
*/
changeEndTimezoneMutation({
calendarObjectInstance,
endTimezone,
}) {
const timezone = getTimezoneManager().getTimezoneForId(endTimezone)
calendarObjectInstance.eventComponent.endDate.replaceTimezone(timezone)
calendarObjectInstance.endTimezoneId = endTimezone
// Either both are floating or both have a timezone, but it can't be mixed
if (endTimezone === 'floating' || calendarObjectInstance.startTimezoneId === 'floating') {
calendarObjectInstance.eventComponent.startDate.replaceTimezone(timezone)
calendarObjectInstance.startTimezoneId = endTimezone
}
},
/**
* Switch from a timed event to allday or vice versa
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
*/
toggleAllDayMutation({ calendarObjectInstance }) {
if (!calendarObjectInstance.eventComponent.canModifyAllDay()) {
return
}
const isAllDay = calendarObjectInstance.eventComponent.isAllDay()
calendarObjectInstance.eventComponent.startDate.isDate = !isAllDay
calendarObjectInstance.eventComponent.endDate.isDate = !isAllDay
calendarObjectInstance.isAllDay = calendarObjectInstance.eventComponent.isAllDay()
// isAllDay = old value
if (isAllDay) {
calendarObjectInstance.eventComponent.endDate.addDuration(DurationValue.fromSeconds(-1 * 60 * 60 * 24))
} else {
calendarObjectInstance.eventComponent.endDate.addDuration(DurationValue.fromSeconds(60 * 60 * 24))
}
},
/**
* Changes the time of a timed event to the default values
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
*/
changeTimeToDefaultForTimedEvents({ calendarObjectInstance }) {
const startDate = calendarObjectInstance.eventComponent.startDate
const endDate = calendarObjectInstance.eventComponent.endDate
if (startDate.hour === 0 && startDate.minute === 0 && endDate.hour === 0 && endDate.minute === 0) {
startDate.hour = 10
endDate.hour = 11
calendarObjectInstance.startDate = getDateFromDateTimeValue(startDate)
calendarObjectInstance.endDate = getDateFromDateTimeValue(endDate)
}
},
/**
* Change the location of an event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.location New location to set
*/
changeLocation({
calendarObjectInstance,
location,
}) {
// Special case: delete Apple-specific location property to avoid inconsistencies
calendarObjectInstance.eventComponent.deleteAllProperties('X-APPLE-STRUCTURED-LOCATION')
calendarObjectInstance.eventComponent.location = location
calendarObjectInstance.location = location
},
/**
* Change the description of an event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.description New description to set
*/
changeDescription({
calendarObjectInstance,
description,
}) {
// To avoid inconsistencies (bug #3863), remove all parameters (e.g., ALTREP) upon modification
const descriptionProperty = calendarObjectInstance.eventComponent.getFirstProperty('Description')
if (descriptionProperty) {
for (const parameter of descriptionProperty.getParametersIterator()) {
descriptionProperty.deleteParameter(parameter.name)
}
}
// Delete custom description properties
calendarObjectInstance.eventComponent.deleteAllProperties('X-ALT-DESC')
calendarObjectInstance.eventComponent.description = description
calendarObjectInstance.description = description
},
/**
* Change the access class of an event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.accessClass New access class to set
*/
changeAccessClass({ calendarObjectInstance, accessClass }) {
calendarObjectInstance.eventComponent.accessClass = accessClass
calendarObjectInstance.accessClass = accessClass
},
/**
* Change the status of an event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.status New status to set
*/
changeStatus({ calendarObjectInstance, status }) {
calendarObjectInstance.eventComponent.status = status
calendarObjectInstance.status = status
},
/**
* Change the time-transparency of an event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.timeTransparency New time-transparency to set
*/
changeTimeTransparency({ calendarObjectInstance, timeTransparency }) {
calendarObjectInstance.eventComponent.timeTransparency = timeTransparency
calendarObjectInstance.timeTransparency = timeTransparency
},
/**
* Change the customized color of an event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string | null} data.customColor New color to set
*/
changeCustomColor({ calendarObjectInstance, customColor }) {
if (customColor === null) {
calendarObjectInstance.eventComponent.deleteAllProperties('COLOR')
// TODO: get rid of Vue.set in Vue 3
Vue.set(calendarObjectInstance, 'customColor', null)
return
}
const cssColorName = getClosestCSS3ColorNameForHex(customColor)
const hexColorOfCssName = getHexForColorName(cssColorName)
// Abort if either is undefined
if (!cssColorName || !hexColorOfCssName) {
console.error('Setting custom color failed')
console.error('customColor: ', customColor)
console.error('cssColorName: ', cssColorName)
console.error('hexColorOfCssName: ', hexColorOfCssName)
return
}
calendarObjectInstance.eventComponent.color = cssColorName
// TODO: get rid of Vue.set in Vue 3
Vue.set(calendarObjectInstance, 'customColor', hexColorOfCssName)
},
/**
* Adds an attendee to the event and sets the organizer if not present already
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.commonName Displayname of attendee
* @param {string} data.uri Email address of attendee
* @param {string} data.calendarUserType Calendar-user-type of attendee (INDIVIDUAL, GROUP, RESOURCE, ROOM)
* @param {string} data.participationStatus Participation Status of attendee
* @param {string} data.role Role of Attendee
* @param {boolean} data.rsvp Whether or not to request a response from the attendee
* @param {string=} data.language Preferred language of the attendee
* @param {string=} data.timezoneId Preferred timezone of the attendee
* @param {object=} data.organizer Principal of the organizer to be set if not present
* @param {string | Array} data.member Group membership(s)
*/
addAttendee({
calendarObjectInstance,
commonName,
uri,
calendarUserType = null,
participationStatus = null,
role = null,
rsvp = null,
language = null,
timezoneId = null,
organizer = null,
member = null,
}) {
const attendee = AttendeeProperty.fromNameAndEMail(commonName, uri)
if (calendarUserType !== null) {
attendee.userType = calendarUserType
}
if (participationStatus !== null) {
attendee.participationStatus = participationStatus
}
if (role !== null) {
attendee.role = role
}
if (rsvp !== null) {
attendee.rsvp = rsvp
}
if (language !== null) {
attendee.language = language
}
if (timezoneId !== null) {
attendee.updateParameterIfExist('TZID', timezoneId)
}
if (member !== null) {
attendee.updateParameterIfExist('MEMBER', member)
}
// TODO - use real addAttendeeFrom method
calendarObjectInstance.eventComponent.addProperty(attendee)
calendarObjectInstance.attendees.push({
commonName,
participationStatus,
role,
rsvp,
uri,
attendeeProperty: attendee,
})
if (!calendarObjectInstance.organizer && organizer) {
this.setOrganizer({
calendarObjectInstance,
commonName: organizer.displayname,
email: organizer.emailAddress,
})
}
},
/**
* Removes an attendee from the event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {object} data.attendee The attendee object to remove
*/
removeAttendee({
calendarObjectInstance,
attendee,
}) {
calendarObjectInstance.eventComponent.removeAttendee(attendee.attendeeProperty)
// Also remove members if attendee is a group
if (attendee.attendeeProperty.userType === 'GROUP') {
attendee.members.forEach(function(member) {
if (Array.isArray(member.attendeeProperty.member) && member.attendeeProperty.member.length > 1) {
const removeIndex = member.attendeeProperty.member.findIndex(function(groupname) {
if (groupname === attendee.uri) {
return true
}
return false
})
if (removeIndex !== -1) {
member.attendeeProperty.member.splice(removeIndex, 1)
}
} else {
calendarObjectInstance.eventComponent.removeAttendee(member.attendeeProperty)
const index = calendarObjectInstance.attendees.indexOf(member)
if (index !== -1) {
calendarObjectInstance.attendees.splice(index, 1)
}
}
})
}
const index = calendarObjectInstance.attendees.indexOf(attendee)
if (index !== -1) {
calendarObjectInstance.attendees.splice(index, 1)
}
},
/**
* Changes an attendees' participation status
*
* @param {object} data The destructuring object
* @param {object} data.attendee The attendee object
* @param {string} data.participationStatus New Participation Status of attendee
*/
changeAttendeesParticipationStatus({
attendee,
participationStatus,
}) {
attendee.attendeeProperty.participationStatus = participationStatus
attendee.participationStatus = participationStatus
},
/**
* Changes an attendees' role
*
* @param {object} data The destructuring object
* @param {object} data.attendee The attendee object
* @param {string} data.role New role of attendee
*/
changeAttendeesRole({
attendee,
role,
}) {
attendee.attendeeProperty.role = role
attendee.role = role
},
/**
* Changes an attendees' RVSP
*
* @param {object} data The destructuring object
* @param {object} data.attendee The attendee object
*/
toggleAttendeeRSVP({ attendee }) {
const oldRSVP = attendee.attendeeProperty.rsvp
attendee.attendeeProperty.rsvp = !oldRSVP
attendee.rsvp = !oldRSVP
},
/**
* Set the event's organizer
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string=} data.commonName Displayname of organizer
* @param {string} data.email Email-address of organizer
*/
setOrganizer({ calendarObjectInstance, commonName = null, email }) {
calendarObjectInstance.eventComponent.setOrganizerFromNameAndEMail(commonName, email)
Vue.set(calendarObjectInstance, 'organizer', {
commonName,
uri: email,
attendeeProperty: calendarObjectInstance.eventComponent.getFirstProperty('ORGANIZER'),
})
},
/**
* Adds a category to the event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.category Category to add
*/
addCategory({ calendarObjectInstance, category }) {
calendarObjectInstance.eventComponent.addCategory(category)
calendarObjectInstance.categories.push(category)
},
/**
* Removes a category from the event
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {string} data.category Category to remove
*/
removeCategory({ calendarObjectInstance, category }) {
calendarObjectInstance.eventComponent.removeCategory(category)
const index = calendarObjectInstance.categories.indexOf(category)
if (index !== -1) {
calendarObjectInstance.categories.splice(index, 1)
}
},
/**
* Change the interval of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.interval The new interval to set
*/
changeRecurrenceInterval({
recurrenceRule,
interval,
}) {
if (recurrenceRule.recurrenceRuleValue) {
recurrenceRule.recurrenceRuleValue.interval = interval
recurrenceRule.interval = interval
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the frequency of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.frequency The new frequency to set
*/
changeRecurrenceFrequencyMutation({
recurrenceRule,
frequency,
}) {
if (recurrenceRule.recurrenceRuleValue) {
recurrenceRule.recurrenceRuleValue.frequency = frequency
recurrenceRule.frequency = frequency
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the count limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.count The new count to set
*/
changeRecurrenceCount({
recurrenceRule,
count,
}) {
if (recurrenceRule.recurrenceRuleValue) {
recurrenceRule.recurrenceRuleValue.count = count
recurrenceRule.count = count
recurrenceRule.until = null
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {Date} data.until The new until to set
*/
changeRecurrenceUntil({
calendarObjectInstance,
recurrenceRule,
until,
}) {
if (recurrenceRule.recurrenceRuleValue) {
// RFC 5545, setion 3.3.10: until must be in UTC if the start time is timezone-aware
if (calendarObjectInstance.startTimezoneId !== 'floating') {
recurrenceRule.recurrenceRuleValue.until = DateTimeValue.fromJSDate(until, { zone: 'utc' })
} else {
recurrenceRule.recurrenceRuleValue.until = DateTimeValue.fromJSDate(until)
}
recurrenceRule.until = until
recurrenceRule.count = null
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Changes the recurrence-rule to never end
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
*/
changeRecurrenceToInfinite({ recurrenceRule }) {
if (recurrenceRule.recurrenceRuleValue) {
recurrenceRule.recurrenceRuleValue.setToInfinite()
recurrenceRule.until = null
recurrenceRule.count = null
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Reset the By-parts of the recurrence rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
*/
resetRecurrenceByParts({ recurrenceRule }) {
if (recurrenceRule.recurrenceRuleValue) {
const parts = [
'BYSECOND',
'BYMINUTE',
'BYHOUR',
'BYDAY',
'BYMONTHDAY',
'BYYEARDAY',
'BYWEEKNO',
'BYMONTH',
'BYSETPOS',
]
for (const part of parts) {
recurrenceRule.recurrenceRuleValue.setComponent(part, [])
}
/* TODO
recurrenceRule.byDay = []
recurrenceRule.byMonth = []
recurrenceRule.byMonthDay = []
recurrenceRule.bySetPosition = null
*/
Vue.set(recurrenceRule, 'byDay', [])
Vue.set(recurrenceRule, 'byMonth', [])
Vue.set(recurrenceRule, 'byMonthDay', [])
Vue.set(recurrenceRule, 'bySetPosition', null)
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
*
* @param {object} data The destructuring object
* @param {object} data.calendarObjectInstance The calendarObjectInstance object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
*/
setDefaultRecurrenceByPartsForMonthlyBySetPosition({
calendarObjectInstance,
recurrenceRule,
}) {
if (recurrenceRule.recurrenceRuleValue) {
const {
byDay,
bySetPosition,
} = getBySetPositionAndBySetFromDate(calendarObjectInstance.startDate)
recurrenceRule.recurrenceRuleValue.setComponent('BYDAY', [byDay])
recurrenceRule.recurrenceRuleValue.setComponent('BYSETPOS', [bySetPosition])
recurrenceRule.byDay.push(byDay)
recurrenceRule.bySetPosition = bySetPosition
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.byDay The new until to set
*/
addByDayToRecurrenceRule({
recurrenceRule,
byDay,
}) {
if (recurrenceRule.recurrenceRuleValue) {
const byDayList = recurrenceRule.recurrenceRuleValue.getComponent('BYDAY')
const index = byDayList.indexOf(byDay)
if (index === -1) {
byDayList.push(byDay)
recurrenceRule.recurrenceRuleValue.setComponent('BYDAY', byDayList)
}
const index2 = recurrenceRule.byDay.indexOf(byDay)
if (index2 === -1) {
recurrenceRule.byDay.push(byDay)
}
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.byDay The new until to set
*/
removeByDayFromRecurrenceRule({
recurrenceRule,
byDay,
}) {
if (recurrenceRule.recurrenceRuleValue) {
const byDayList = recurrenceRule.recurrenceRuleValue.getComponent('BYDAY')
const index = byDayList.indexOf(byDay)
if (index !== -1) {
byDayList.splice(index, 1)
recurrenceRule.recurrenceRuleValue.setComponent('BYDAY', byDayList)
}
const index2 = recurrenceRule.byDay.indexOf(byDay)
if (index2 !== -1) {
recurrenceRule.byDay.splice(index2, 1)
}
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.byMonthDay The new until to set
*/
addByMonthDayToRecurrenceRule({
recurrenceRule,
byMonthDay,
}) {
if (recurrenceRule.recurrenceRuleValue) {
const byMonthDayList = recurrenceRule.recurrenceRuleValue.getComponent('BYMONTHDAY')
const index = byMonthDayList.indexOf(byMonthDay)
if (index === -1) {
byMonthDayList.push(byMonthDay)
recurrenceRule.recurrenceRuleValue.setComponent('BYMONTHDAY', byMonthDayList)
}
const index2 = recurrenceRule.byMonthDay.indexOf(byMonthDay)
if (index2 === -1) {
recurrenceRule.byMonthDay.push(byMonthDay)
}
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.byMonthDay The new until to set
*/
removeByMonthDayFromRecurrenceRule({
recurrenceRule,
byMonthDay,
}) {
if (recurrenceRule.recurrenceRuleValue) {
const byMonthDayList = recurrenceRule.recurrenceRuleValue.getComponent('BYMONTHDAY')
const index = byMonthDayList.indexOf(byMonthDay)
if (index !== -1) {
byMonthDayList.splice(index, 1)
recurrenceRule.recurrenceRuleValue.setComponent('BYMONTHDAY', byMonthDayList)
}
const index2 = recurrenceRule.byMonthDay.indexOf(byMonthDay)
if (index2 !== -1) {
recurrenceRule.byMonthDay.splice(index2, 1)
}
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.byMonth The new until to set
*/
addByMonthToRecurrenceRule({
recurrenceRule,
byMonth,
}) {
if (recurrenceRule.recurrenceRuleValue) {
console.debug('addByMonthToRecurrenceRule', byMonth)
const byMonthList = recurrenceRule.recurrenceRuleValue.getComponent('BYMONTH')
const index = byMonthList.indexOf(byMonth)
if (index === -1) {
byMonthList.push(byMonth)
recurrenceRule.recurrenceRuleValue.setComponent('BYMONTH', byMonthList)
}
const index2 = recurrenceRule.byMonth.indexOf(byMonth)
if (index2 === -1) {
recurrenceRule.byMonth.push(byMonth)
}
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.byMonth The new until to set
*/
removeByMonthFromRecurrenceRule({
recurrenceRule,
byMonth,
}) {
if (recurrenceRule.recurrenceRuleValue) {
console.debug('removeByMonthFromRecurrenceRule', byMonth)
const byMonthList = recurrenceRule.recurrenceRuleValue.getComponent('BYMONTH')
const index = byMonthList.indexOf(byMonth)
if (index !== -1) {
byMonthList.splice(index, 1)
recurrenceRule.recurrenceRuleValue.setComponent('BYMONTH', byMonthList)
}
const index2 = recurrenceRule.byMonth.indexOf(byMonth)
if (index2 !== -1) {
recurrenceRule.byMonth.splice(index2, 1)
}
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string[]} data.byDay The new until to set
*/
changeRecurrenceByDay({
recurrenceRule,
byDay,
}) {
if (recurrenceRule.recurrenceRuleValue) {
recurrenceRule.recurrenceRuleValue.setComponent('BYDAY', byDay)
// TODO recurrenceRule.byDay = byDay
Vue.set(recurrenceRule, 'byDay', byDay)
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
* Change the until limit of the recurrence-rule
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
* @param {string} data.bySetPosition The new until to set
*/
changeRecurrenceBySetPosition({
recurrenceRule,
bySetPosition,
}) {
if (recurrenceRule.recurrenceRuleValue) {
recurrenceRule.recurrenceRuleValue.setComponent('BYSETPOS', [bySetPosition])
/// TODO recurrenceRule.bySetPosition = bySetPosition
Vue.set(recurrenceRule, 'bySetPosition', bySetPosition)
console.debug(recurrenceRule.recurrenceRuleValue._innerValue.toString())
}
},
/**
*
* @param {object} data The destructuring object
* @param {object} data.recurrenceRule The recurrenceRule object to modify
*/
markRecurrenceRuleAsSupported({ recurrenceRule }) {
recurrenceRule.isUnsupported = false
},
/**
*
* @param {object} data The destructuring object
* @param {object} data.alarm The alarm object
* @param {string} data.type New type of alarm