Skip to content

Commit d85b63e

Browse files
fix: monthly recurrance type and bymonthday selection
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 4fac1f2 commit d85b63e

File tree

5 files changed

+52
-57
lines changed

5 files changed

+52
-57
lines changed

src/components/Editor/Repeat/Repeat.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@change-by-day="setByDay"
4444
@change-by-set-position="setBySetPosition"
4545
@change-to-by-set-position="changeToBySetPositionMonthly"
46-
@change-to-by-day="changeToByDayMonthly" />
46+
@change-to-by-month-day="changeToByDayMonthly" />
4747
<RepeatFreqYearlyOptions v-if="isFreqYearly && !isRecurrenceException && !isReadOnly"
4848
:by-day="recurrenceRule.byDay"
4949
:by-month="recurrenceRule.byMonth"

src/components/Editor/Repeat/RepeatFreqMonthlyOptions.vue

+17-13
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
<template>
77
<div class="repeat-option-set repeat-option-set--monthly">
88
<div class="repeat-option-set-section">
9-
<ActionRadio class="repeat-option-set-section__title"
9+
<NcCheckboxRadioSwitch class="repeat-option-set-section__title"
10+
type="radio"
1011
:name="radioInputId"
11-
:checked="byMonthDayEnabled"
12-
@change="enableByMonthDay">
12+
:modelValue="byMonthDayEnabled"
13+
@update:modelValue="enableByMonthDay"
14+
@update:model-value="enableByMonthDay">
1315
{{ $t('calendar', 'By day of the month') }}
14-
</ActionRadio>
16+
</NcCheckboxRadioSwitch>
1517
<div class="repeat-option-set-section__grid">
1618
<NcButton v-for="option in byMonthDayOptions"
1719
:key="option.value"
@@ -24,12 +26,14 @@
2426
</div>
2527
</div>
2628
<div class="repeat-option-set-section repeat-option-set-section--on-the-select">
27-
<ActionRadio class="repeat-option-set-section__title"
29+
<NcCheckboxRadioSwitch class="repeat-option-set-section__title"
30+
type="radio"
2831
:name="radioInputId"
29-
:checked="!byMonthDayEnabled"
30-
@change="enableBySetPosition">
32+
:modelValue="!byMonthDayEnabled"
33+
@update:modelValue="enableBySetPosition"
34+
@update:model-value="enableBySetPosition">
3135
{{ $t('calendar', 'On the') }}
32-
</ActionRadio>
36+
</NcCheckboxRadioSwitch>
3337
<RepeatFirstLastSelect :by-set-position="bySetPosition"
3438
:disabled="byMonthDayEnabled"
3539
@change="changeBySetPosition" />
@@ -43,7 +47,7 @@
4347
<script>
4448
import {
4549
NcButton,
46-
NcActionRadio as ActionRadio,
50+
NcCheckboxRadioSwitch,
4751
} from '@nextcloud/vue'
4852
import RepeatFirstLastSelect from './RepeatFirstLastSelect.vue'
4953
import RepeatOnTheSelect from './RepeatOnTheSelect.vue'
@@ -52,9 +56,9 @@ export default {
5256
name: 'RepeatFreqMonthlyOptions',
5357
components: {
5458
NcButton,
59+
NcCheckboxRadioSwitch,
5560
RepeatOnTheSelect,
5661
RepeatFirstLastSelect,
57-
ActionRadio,
5862
},
5963
props: {
6064
/**
@@ -89,8 +93,8 @@ export default {
8993
for (let i = 1; i <= 31; i++) {
9094
options.push({
9195
label: i,
92-
value: String(i),
93-
selected: this.byMonthDay.indexOf(String(i)) !== -1,
96+
value: i,
97+
selected: this.byMonthDay.indexOf(i) !== -1,
9498
})
9599
}
96100

@@ -128,7 +132,7 @@ export default {
128132
return
129133
}
130134

131-
this.$emit('change-to-by-day')
135+
this.$emit('change-to-by-month-day')
132136
},
133137
enableBySetPosition() {
134138
if (!this.byMonthDayEnabled) {

src/models/recurrenceRule.js

+14-23
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,14 @@ const SUPPORTED_BY_DAY_WEEKLY = [
111111
'SA',
112112
]
113113

114-
/**
115-
* Get all numbers between start and end as strings
116-
*
117-
* @param {number} start Lower end of range
118-
* @param {number} end Upper end of range
119-
* @return {string[]}
120-
*/
121-
const getRangeAsStrings = (start, end) => {
122-
return Array
123-
.apply(null, Array((end - start) + 1))
124-
.map((_, n) => n + start)
125-
.map((s) => s.toString())
126-
}
127-
128-
const SUPPORTED_BY_MONTHDAY_MONTHLY = getRangeAsStrings(1, 31)
114+
const SUPPORTED_BY_MONTHDAY_MONTHLY = [
115+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
116+
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
117+
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
118+
31
119+
]
129120

130-
const SUPPORTED_BY_MONTH_YEARLY = getRangeAsStrings(1, 12)
121+
const SUPPORTED_BY_MONTH_YEARLY = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
131122

132123
/**
133124
* Maps a daily calendar-js recurrence-rule-value to an recurrence-rule-object
@@ -230,12 +221,12 @@ const mapMonthlyRuleValueToRecurrenceRuleObject = (recurrenceRuleValue, baseDate
230221
}
231222

232223
const containsInvalidByMonthDay = recurrenceRuleValue.getComponent('BYMONTHDAY')
233-
.some((monthDay) => !SUPPORTED_BY_MONTHDAY_MONTHLY.includes(monthDay.toString()))
224+
.some((monthDay) => !SUPPORTED_BY_MONTHDAY_MONTHLY.includes(monthDay))
234225
isUnsupported = isUnsupported || containsInvalidByMonthDay
235226

236227
byMonthDay = recurrenceRuleValue.getComponent('BYMONTHDAY')
237-
.filter((monthDay) => SUPPORTED_BY_MONTHDAY_MONTHLY.includes(monthDay.toString()))
238-
.map((monthDay) => monthDay.toString())
228+
.filter((monthDay) => SUPPORTED_BY_MONTHDAY_MONTHLY.includes(monthDay))
229+
.map((monthDay) => monthDay)
239230

240231
// This handles cases where we have both BYDAY and BYSETPOS
241232
} else if (containsRecurrenceComponent(recurrenceRuleValue, ['BYDAY']) && containsRecurrenceComponent(recurrenceRuleValue, ['BYSETPOS'])) {
@@ -332,14 +323,14 @@ const mapYearlyRuleValueToRecurrenceRuleObject = (recurrenceRuleValue, baseDate)
332323

333324
if (containsRecurrenceComponent(recurrenceRuleValue, ['BYMONTH'])) {
334325
const containsInvalidByMonthDay = recurrenceRuleValue.getComponent('BYMONTH')
335-
.some((month) => !SUPPORTED_BY_MONTH_YEARLY.includes(month.toString()))
326+
.some((month) => !SUPPORTED_BY_MONTH_YEARLY.includes(month))
336327
isUnsupported = isUnsupported || containsInvalidByMonthDay
337328

338329
byMonth = recurrenceRuleValue.getComponent('BYMONTH')
339-
.filter((monthDay) => SUPPORTED_BY_MONTH_YEARLY.includes(monthDay.toString()))
340-
.map((month) => month.toString())
330+
.filter((monthDay) => SUPPORTED_BY_MONTH_YEARLY.includes(monthDay))
331+
.map((month) => month)
341332
} else {
342-
byMonth.push(baseDate.month.toString())
333+
byMonth.push(baseDate.month)
343334
}
344335

345336
if (containsRecurrenceComponent(recurrenceRuleValue, ['BYDAY']) && containsRecurrenceComponent(recurrenceRuleValue, ['BYSETPOS'])) {

src/store/calendarObjectInstance.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ export default defineStore('calendarObjectInstance', {
17711771
this.resetRecurrenceByParts({ recurrenceRule })
17721772

17731773
if (recurrenceRule.recurrenceRuleValue) {
1774-
const byMonthDay = calendarObjectInstance.startDate.getDate().toString()
1774+
const byMonthDay = calendarObjectInstance.startDate.getDate()
17751775
recurrenceRule.recurrenceRuleValue.setComponent('BYMONTHDAY', [byMonthDay])
17761776
recurrenceRule.byMonthDay.push(byMonthDay)
17771777

tests/javascript/unit/models/recurrenceRule.test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
287287
until: null,
288288
byDay: [],
289289
byMonth: [],
290-
byMonthDay: ['15'],
290+
byMonthDay: [15],
291291
bySetPosition: null,
292292
isUnsupported: false,
293293
})
@@ -311,7 +311,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
311311
until: null,
312312
byDay: [],
313313
byMonth: [],
314-
byMonthDay: ['1', '2', '3', '30', '31'],
314+
byMonthDay: [1, 2, 3, 30, 31],
315315
bySetPosition: null,
316316
isUnsupported: false,
317317
})
@@ -335,7 +335,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
335335
until: null,
336336
byDay: [],
337337
byMonth: [],
338-
byMonthDay: ['2', '30', '31'],
338+
byMonthDay: [2, 30, 31],
339339
bySetPosition: null,
340340
isUnsupported: true,
341341
})
@@ -359,7 +359,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
359359
until: null,
360360
byDay: [],
361361
byMonth: [],
362-
byMonthDay: ['1', '2', '3', '30', '31'],
362+
byMonthDay: [1, 2, 3, 30, 31],
363363
bySetPosition: null,
364364
isUnsupported: true,
365365
})
@@ -478,7 +478,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
478478
count: null,
479479
until: null,
480480
byDay: [],
481-
byMonth: ['3'],
481+
byMonth: [3],
482482
byMonthDay: [],
483483
bySetPosition: null,
484484
isUnsupported: false,
@@ -502,7 +502,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
502502
count: null,
503503
until: null,
504504
byDay: [],
505-
byMonth: ['1', '2', '3'],
505+
byMonth: [1, 2, 3],
506506
byMonthDay: [],
507507
bySetPosition: null,
508508
isUnsupported: false,
@@ -532,7 +532,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
532532
count: null,
533533
until: null,
534534
byDay: ['MO'],
535-
byMonth: ['3'],
535+
byMonth: [3],
536536
byMonthDay: [],
537537
bySetPosition: 3,
538538
isUnsupported: false,
@@ -556,7 +556,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
556556
count: null,
557557
until: null,
558558
byDay: ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'],
559-
byMonth: ['3'],
559+
byMonth: [3],
560560
byMonthDay: [],
561561
bySetPosition: 3,
562562
isUnsupported: true,
@@ -580,7 +580,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
580580
count: null,
581581
until: null,
582582
byDay: ['MO'],
583-
byMonth: ['3'],
583+
byMonth: [3],
584584
byMonthDay: [],
585585
bySetPosition: 1,
586586
isUnsupported: true,
@@ -604,7 +604,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
604604
count: null,
605605
until: null,
606606
byDay: ['MO'],
607-
byMonth: ['3'],
607+
byMonth: [3],
608608
byMonthDay: [],
609609
bySetPosition: 1,
610610
isUnsupported: true,
@@ -629,7 +629,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
629629
until: null,
630630
byDay: [],
631631
byMonth: [],
632-
byMonthDay: ['15'],
632+
byMonthDay: [15],
633633
bySetPosition: null,
634634
isUnsupported: true,
635635
})
@@ -701,7 +701,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
701701
until: null,
702702
byDay: [],
703703
byMonth: [],
704-
byMonthDay: ['15'],
704+
byMonthDay: [15],
705705
bySetPosition: null,
706706
isUnsupported: true,
707707
})
@@ -724,7 +724,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
724724
count: null,
725725
until: null,
726726
byDay: [],
727-
byMonth: ['3'],
727+
byMonth: [3],
728728
byMonthDay: [],
729729
bySetPosition: null,
730730
isUnsupported: true,
@@ -748,7 +748,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
748748
count: null,
749749
until: null,
750750
byDay: ['MO'],
751-
byMonth: ['3'],
751+
byMonth: [3],
752752
byMonthDay: [],
753753
bySetPosition: 3,
754754
isUnsupported: false,
@@ -772,7 +772,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
772772
count: null,
773773
until: null,
774774
byDay: ['MO'],
775-
byMonth: ['3'],
775+
byMonth: [3],
776776
byMonthDay: [],
777777
bySetPosition: 1,
778778
isUnsupported: true,
@@ -796,7 +796,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
796796
count: null,
797797
until: null,
798798
byDay: [],
799-
byMonth: ['3'],
799+
byMonth: [3],
800800
byMonthDay: [],
801801
bySetPosition: null,
802802
isUnsupported: true,
@@ -821,7 +821,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
821821
until: null,
822822
byDay: [],
823823
byMonth: [],
824-
byMonthDay: ['15'],
824+
byMonthDay: [15],
825825
bySetPosition: null,
826826
isUnsupported: false,
827827
})
@@ -849,7 +849,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
849849
until: mockDate,
850850
byDay: [],
851851
byMonth: [],
852-
byMonthDay: ['15'],
852+
byMonthDay: [15],
853853
bySetPosition: null,
854854
isUnsupported: false,
855855
})
@@ -881,7 +881,7 @@ describe('Test suite: Recurrence Rule model (models/recurrenceRule.js)', () => {
881881
until: mockDate,
882882
byDay: [],
883883
byMonth: [],
884-
byMonthDay: ['15'],
884+
byMonthDay: [15],
885885
bySetPosition: null,
886886
isUnsupported: true,
887887
})

0 commit comments

Comments
 (0)