From 222a02564f4ea16bb73d5001431a3f570a5a75e7 Mon Sep 17 00:00:00 2001 From: Matteo Settenvini Date: Tue, 30 Mar 2021 00:01:53 +0200 Subject: [PATCH 1/3] Add label to slotDuration setting Add a label to slotDuration so that the user is not left wondering what the setting refers to. I remember being puzzled myself the first time I saw it. Signed-off-by: Matteo Settenvini --- css/app-settings.scss | 18 ++++++++++++++++-- src/components/AppNavigation/Settings.vue | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/css/app-settings.scss b/css/app-settings.scss index bec64f912..45905328f 100644 --- a/css/app-settings.scss +++ b/css/app-settings.scss @@ -54,10 +54,24 @@ background-position-x: 8px; } - &--slotDuration, + &--slotDuration { + display: table; + + label { + display: table-cell; + min-width: 50%; + vertical-align: middle; + } + + .multiselect { + display: table-cell; + width: 50%; + } + } + &--timezone { width: 100%; - + .multiselect { width: 100%; } diff --git a/src/components/AppNavigation/Settings.vue b/src/components/AppNavigation/Settings.vue index 0f4c21501..a2de67852 100644 --- a/src/components/AppNavigation/Settings.vue +++ b/src/components/AppNavigation/Settings.vue @@ -66,7 +66,9 @@ {{ $t('calendar', 'Show week numbers') }}
  • + Date: Tue, 30 Mar 2021 01:12:18 +0200 Subject: [PATCH 2/3] Add defaultReminder setting Add a setting to the app state that can be reused when creating new events to set a default alarm / reminder. Signed-off-by: Matteo Settenvini --- css/app-settings.scss | 3 +- lib/Controller/PublicViewController.php | 2 + lib/Controller/SettingsController.php | 29 ++++++++++ lib/Controller/ViewController.php | 3 + src/components/AppNavigation/Settings.vue | 56 +++++++++++++++++++ src/store/settings.js | 35 +++++++++++- src/views/Calendar.vue | 2 + tests/javascript/unit/store/settings.test.js | 46 +++++++++++++++ .../Controller/PublicViewControllerTest.php | 10 +++- .../Controller/SettingsControllerTest.php | 53 ++++++++++++++++++ .../unit/Controller/ViewControllerTest.php | 6 ++ 11 files changed, 240 insertions(+), 5 deletions(-) diff --git a/css/app-settings.scss b/css/app-settings.scss index 45905328f..49422f220 100644 --- a/css/app-settings.scss +++ b/css/app-settings.scss @@ -54,7 +54,8 @@ background-position-x: 8px; } - &--slotDuration { + &--slotDuration, + &--defaultReminder { display: table; label { diff --git a/lib/Controller/PublicViewController.php b/lib/Controller/PublicViewController.php index a8fd624bf..0e5271b98 100644 --- a/lib/Controller/PublicViewController.php +++ b/lib/Controller/PublicViewController.php @@ -120,6 +120,7 @@ class PublicViewController extends Controller { $defaultSkipPopover = $this->config->getAppValue($this->appName, 'skipPopover', 'yes'); $defaultTimezone = $this->config->getAppValue($this->appName, 'timezone', 'automatic'); $defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00'); + $defaultDefaultReminder = $this->config->getAppValue($this->appName, 'defaultReminder', 'none'); $defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); $appVersion = $this->config->getAppValue($this->appName, 'installed_version', null); @@ -134,6 +135,7 @@ class PublicViewController extends Controller { $this->initialStateService->provideInitialState($this->appName, 'talk_enabled', false); $this->initialStateService->provideInitialState($this->appName, 'timezone', $defaultTimezone); $this->initialStateService->provideInitialState($this->appName, 'slot_duration', $defaultSlotDuration); + $this->initialStateService->provideInitialState($this->appName, 'default_reminder', $defaultDefaultReminder); $this->initialStateService->provideInitialState($this->appName, 'show_tasks', $defaultShowTasks === 'yes'); $this->initialStateService->provideInitialState($this->appName, 'tasks_enabled', false); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 8a824cf7b..9d370a001 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -87,6 +87,8 @@ class SettingsController extends Controller { return $this->setEventLimit($value); case 'slotDuration': return $this->setSlotDuration($value); + case 'defaultReminder': + return $this->setDefaultReminder($value); case 'showTasks': return $this->setShowTasks($value); default: @@ -310,4 +312,31 @@ class SettingsController extends Controller { return new JSONResponse(); } + + /** + * sets defaultReminder for user + * + * @param string $value User-selected option for default_reminder in agenda view + * @return JSONResponse + */ + private function setDefaultReminder(string $value):JSONResponse { + if ($value !== 'none' && + filter_var($value, FILTER_VALIDATE_INT, + ['options' => ['max_range' => 0]]) === false) { + return new JSONResponse([], Http::STATUS_UNPROCESSABLE_ENTITY); + } + + try { + $this->config->setUserValue( + $this->userId, + $this->appName, + 'defaultReminder', + $value + ); + } catch (\Exception $e) { + return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); + } + + return new JSONResponse(); + } } diff --git a/lib/Controller/ViewController.php b/lib/Controller/ViewController.php index c0307e6d7..c7be99155 100644 --- a/lib/Controller/ViewController.php +++ b/lib/Controller/ViewController.php @@ -94,6 +94,7 @@ class ViewController extends Controller { $defaultSkipPopover = $this->config->getAppValue($this->appName, 'skipPopover', 'no'); $defaultTimezone = $this->config->getAppValue($this->appName, 'timezone', 'automatic'); $defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00'); + $defaultDefaultReminder = $this->config->getAppValue($this->appName, 'defaultReminder', 'none'); $defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); $appVersion = $this->config->getAppValue($this->appName, 'installed_version', null); @@ -105,6 +106,7 @@ class ViewController extends Controller { $skipPopover = $this->config->getUserValue($this->userId, $this->appName, 'skipPopover', $defaultSkipPopover) === 'yes'; $timezone = $this->config->getUserValue($this->userId, $this->appName, 'timezone', $defaultTimezone); $slotDuration = $this->config->getUserValue($this->userId, $this->appName, 'slotDuration', $defaultSlotDuration); + $defaultReminder = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminder', $defaultDefaultReminder); $showTasks = $this->config->getUserValue($this->userId, $this->appName, 'showTasks', $defaultShowTasks) === 'yes'; $talkEnabled = $this->appManager->isEnabledForUser('spreed'); @@ -120,6 +122,7 @@ class ViewController extends Controller { $this->initialStateService->provideInitialState($this->appName, 'talk_enabled', $talkEnabled); $this->initialStateService->provideInitialState($this->appName, 'timezone', $timezone); $this->initialStateService->provideInitialState($this->appName, 'slot_duration', $slotDuration); + $this->initialStateService->provideInitialState($this->appName, 'default_reminder', $defaultReminder); $this->initialStateService->provideInitialState($this->appName, 'show_tasks', $showTasks); $this->initialStateService->provideInitialState($this->appName, 'tasks_enabled', $tasksEnabled); diff --git a/src/components/AppNavigation/Settings.vue b/src/components/AppNavigation/Settings.vue index a2de67852..80e737740 100644 --- a/src/components/AppNavigation/Settings.vue +++ b/src/components/AppNavigation/Settings.vue @@ -77,6 +77,18 @@ label="label" @select="changeSlotDuration" />
  • +
  • + + +
  • {{ $t('calendar', 'Copy primary CalDAV address') }} @@ -126,6 +138,8 @@ import { IMPORT_STAGE_PROCESSING, } from '../../models/consts.js' +import { getDefaultAlarms } from '../../defaults/defaultAlarmProvider.js' + export default { name: 'Settings', components: { @@ -150,6 +164,7 @@ export default { savingTasks: false, savingPopover: false, savingSlotDuration: false, + savingDefaultReminder: false, savingWeekend: false, savingWeekNumber: false, displayKeyboardShortcuts: false, @@ -166,6 +181,7 @@ export default { showWeekends: state => state.settings.showWeekends, showWeekNumbers: state => state.settings.showWeekNumbers, slotDuration: state => state.settings.slotDuration, + defaultReminder: state => state.settings.defaultReminder, timezone: state => state.settings.timezone, locale: (state) => state.settings.momentLocale, }), @@ -211,6 +227,22 @@ export default { selectedDurationOption() { return this.slotDurationOptions.find(o => o.value === this.slotDuration) }, + defaultReminderOptions() { + const defaultAlarms = getDefaultAlarms().map(seconds => { + return { + label: moment.duration(Math.abs(seconds) * 1000).locale(this.locale).humanize(), + value: seconds.toString(), + } + }) + + return [{ + label: this.$t('calendar', 'No reminder'), + value: 'none', + }].concat(defaultAlarms) + }, + selectedDefaultReminderOption() { + return this.defaultReminderOptions.find(o => o.value === this.defaultReminder) + }, }, methods: { async toggleBirthdayEnabled() { @@ -312,6 +344,30 @@ export default { this.savingSlotDuration = false } }, + /** + * Updates the setting for the default reminder + * + * @param {Object} option The new selected value + */ + async changeDefaultReminder(option) { + if (!option) { + return + } + + // change to loading status + this.savingDefaultReminder = true + + try { + await this.$store.dispatch('setDefaultReminder', { + defaultReminder: option.value, + }) + this.savingDefaultReminder = false + } catch (error) { + console.error(error) + showError(this.$t('calendar', 'New setting was not saved successfully.')) + this.savingDefaultReminder = false + } + }, /** * Copies the primary CalDAV url to the user's clipboard. */ diff --git a/src/store/settings.js b/src/store/settings.js index 8cb597522..c64f7d113 100644 --- a/src/store/settings.js +++ b/src/store/settings.js @@ -38,6 +38,7 @@ const state = { showWeekNumbers: null, skipPopover: null, slotDuration: null, + defaultReminder: null, tasksEnabled: false, timezone: 'automatic', // user-defined Nextcloud settings @@ -102,6 +103,17 @@ const mutations = { state.slotDuration = slotDuration }, + /** + * Updates the user's preferred defaultReminder + * + * @param {Object} state The Vuex state + * @param {Object} data The destructuring object + * @param {String} data.defaultReminder The new default reminder length + */ + setDefaultReminder(state, { defaultReminder }) { + state.defaultReminder = defaultReminder + }, + /** * Updates the user's timezone * @@ -126,11 +138,12 @@ const mutations = { * @param {Boolean} data.showWeekends Whether or not to display weekends * @param {Boolean} data.skipPopover Whether or not to skip the simple event popover * @param {String} data.slotDuration The duration of one slot in the agendaView + * @param {String} data.defaultReminder The default reminder to set on newly created events * @param {Boolean} data.talkEnabled Whether or not the talk app is enabled * @param {Boolean} data.tasksEnabled Whether ot not the tasks app is enabled * @param {String} data.timezone The timezone to view the calendar in. Either an Olsen timezone or "automatic" */ - loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, talkEnabled, tasksEnabled, timezone }) { + loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone }) { logInfo(` Initial settings: - AppVersion: ${appVersion} @@ -141,6 +154,7 @@ Initial settings: - ShowWeekends: ${showWeekends} - SkipPopover: ${skipPopover} - SlotDuration: ${slotDuration} + - DefaultReminder: ${defaultReminder} - TalkEnabled: ${talkEnabled} - TasksEnabled: ${tasksEnabled} - Timezone: ${timezone} @@ -154,6 +168,7 @@ Initial settings: state.showWeekends = showWeekends state.skipPopover = skipPopover state.slotDuration = slotDuration + state.defaultReminder = defaultReminder state.talkEnabled = talkEnabled state.tasksEnabled = tasksEnabled state.timezone = timezone @@ -319,6 +334,24 @@ const actions = { commit('setSlotDuration', { slotDuration }) }, + /** + * Updates the user's preferred defaultReminder + * + * @param {Object} vuex The Vuex destructuring object + * @param {Object} vuex.state The Vuex state + * @param {Function} vuex.commit The Vuex commit Function + * @param {Object} data The destructuring object + * @param {String} data.defaultReminder The new default reminder + */ + async setDefaultReminder({ state, commit }, { defaultReminder }) { + if (state.defaultReminder === defaultReminder) { + return + } + + await setConfig('defaultReminder', defaultReminder) + commit('setDefaultReminder', { defaultReminder }) + }, + /** * Updates the user's timezone * diff --git a/src/views/Calendar.vue b/src/views/Calendar.vue index f29fc20cc..28ebdcd79 100644 --- a/src/views/Calendar.vue +++ b/src/views/Calendar.vue @@ -124,6 +124,7 @@ export default { showWeekends: state => state.settings.showWeekends, showWeekNumbers: state => state.settings.showWeekNumbers, slotDuration: state => state.settings.slotDuration, + defaultReminder: state => state.settings.defaultReminder, showTasks: state => state.settings.showTasks, timezone: state => state.settings.timezone, modificationCount: state => state.calendarObjects.modificationCount, @@ -191,6 +192,7 @@ export default { showWeekNumbers: loadState('calendar', 'show_week_numbers'), skipPopover: loadState('calendar', 'skip_popover'), slotDuration: loadState('calendar', 'slot_duration'), + defaultReminder: loadState('calendar', 'default_reminder'), talkEnabled: loadState('calendar', 'talk_enabled'), tasksEnabled: loadState('calendar', 'tasks_enabled'), timezone: loadState('calendar', 'timezone'), diff --git a/tests/javascript/unit/store/settings.test.js b/tests/javascript/unit/store/settings.test.js index b22577b2e..cbcc53477 100644 --- a/tests/javascript/unit/store/settings.test.js +++ b/tests/javascript/unit/store/settings.test.js @@ -56,6 +56,7 @@ describe('store/settings test suite', () => { showWeekNumbers: null, skipPopover: null, slotDuration: null, + defaultReminder: null, tasksEnabled: false, timezone: 'automatic', momentLocale: 'en', @@ -131,6 +132,15 @@ describe('store/settings test suite', () => { expect(state.slotDuration).toEqual('00:30:00') }) + it('should provide a mutation to set the default reminder duration setting', () => { + const state = { + defaultReminder: 'previousValue', + } + + settingsStore.mutations.setDefaultReminder(state, { defaultReminder: '-300' }) + expect(state.defaultReminder).toEqual('-300') + }) + it('should provide a mutation to set the timezone setting', () => { const state = { timezone: 'previousValue', @@ -151,6 +161,7 @@ describe('store/settings test suite', () => { showWeekNumbers: null, skipPopover: null, slotDuration: null, + defaultReminder: null, tasksEnabled: false, timezone: 'automatic', momentLocale: 'en', @@ -166,6 +177,7 @@ describe('store/settings test suite', () => { showWeekends: true, skipPopover: true, slotDuration: '00:30:00', + defaultReminder: '-600', talkEnabled: false, tasksEnabled: true, timezone: 'Europe/Berlin', @@ -185,6 +197,7 @@ Initial settings: - ShowWeekends: true - SkipPopover: true - SlotDuration: 00:30:00 + - DefaultReminder: -600 - TalkEnabled: false - TasksEnabled: true - Timezone: Europe/Berlin @@ -198,6 +211,7 @@ Initial settings: showWeekends: true, skipPopover: true, slotDuration: '00:30:00', + defaultReminder: '-600', talkEnabled: false, tasksEnabled: true, timezone: 'Europe/Berlin', @@ -535,6 +549,38 @@ Initial settings: expect(commit).toHaveBeenNthCalledWith(1, 'setSlotDuration', { slotDuration: '00:30:00' }) }) + it('should provide an action to set the default reminder setting - same value', async () => { + expect.assertions(2) + + const state = { + defaultReminder: 'none' + } + const commit = jest.fn() + + await settingsStore.actions.setDefaultReminder({ state, commit }, { defaultReminder: 'none' }) + + expect(setConfig).toHaveBeenCalledTimes(0) + expect(commit).toHaveBeenCalledTimes(0) + }) + + it('should provide an action to set the default reminder setting - different value', async () => { + expect.assertions(4) + + const state = { + defaultReminder: 'none' + } + const commit = jest.fn() + + setConfig.mockResolvedValueOnce() + + await settingsStore.actions.setDefaultReminder({ state, commit }, { defaultReminder: '00:10:00' }) + + expect(setConfig).toHaveBeenCalledTimes(1) + expect(setConfig).toHaveBeenNthCalledWith(1, 'defaultReminder', '00:10:00') + expect(commit).toHaveBeenCalledTimes(1) + expect(commit).toHaveBeenNthCalledWith(1, 'setDefaultReminder', { defaultReminder: '00:10:00' }) + }) + it('should provide an action to set the timezone setting - same value', async () => { expect.assertions(2) diff --git a/tests/php/unit/Controller/PublicViewControllerTest.php b/tests/php/unit/Controller/PublicViewControllerTest.php index df1ecd2b8..f74575c60 100644 --- a/tests/php/unit/Controller/PublicViewControllerTest.php +++ b/tests/php/unit/Controller/PublicViewControllerTest.php @@ -63,7 +63,7 @@ class PublicViewControllerTest extends TestCase { } public function testPublicIndexWithBranding():void { - $this->config->expects(self::exactly(9)) + $this->config->expects(self::exactly(10)) ->method('getAppValue') ->willReturnMap([ ['calendar', 'eventLimit', 'yes', 'no'], @@ -73,6 +73,7 @@ class PublicViewControllerTest extends TestCase { ['calendar', 'skipPopover', 'yes', 'yes'], ['calendar', 'timezone', 'automatic', 'defaultTimezone'], ['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'], + ['calendar', 'defaultReminder', 'none', 'defaultDefaultReminder'], ['calendar', 'showTasks', 'yes', 'yes'], ['calendar', 'installed_version', null, '1.0.0'] ]); @@ -99,7 +100,7 @@ class PublicViewControllerTest extends TestCase { ->with('imagePath456') ->willReturn('absoluteImagePath456'); - $this->initialStateService->expects(self::exactly(12)) + $this->initialStateService->expects(self::exactly(13)) ->method('provideInitialState') ->withConsecutive( ['calendar', 'app_version', '1.0.0'], @@ -112,6 +113,7 @@ class PublicViewControllerTest extends TestCase { ['calendar', 'talk_enabled', false], ['calendar', 'timezone', 'defaultTimezone'], ['calendar', 'slot_duration', 'defaultSlotDuration'], + ['calendar', 'default_reminder', 'defaultDefaultReminder'], ['calendar', 'show_tasks', true], ['calendar', 'tasks_enabled', false] ); @@ -138,6 +140,7 @@ class PublicViewControllerTest extends TestCase { ['calendar', 'skipPopover', 'yes', 'yes'], ['calendar', 'timezone', 'automatic', 'defaultTimezone'], ['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'], + ['calendar', 'defaultReminder', 'none', 'defaultDefaultReminder'], ['calendar', 'showTasks', 'yes', 'defaultShowTasks'], ['calendar', 'installed_version', null, '1.0.0'] ]); @@ -163,7 +166,7 @@ class PublicViewControllerTest extends TestCase { ->with('imagePath456') ->willReturn('absoluteImagePath456'); - $this->initialStateService->expects(self::exactly(12)) + $this->initialStateService->expects(self::exactly(13)) ->method('provideInitialState') ->withConsecutive( ['calendar', 'app_version', '1.0.0'], @@ -176,6 +179,7 @@ class PublicViewControllerTest extends TestCase { ['calendar', 'talk_enabled', false], ['calendar', 'timezone', 'defaultTimezone'], ['calendar', 'slot_duration', 'defaultSlotDuration'], + ['calendar', 'default_reminder', 'defaultDefaultReminder'], ['calendar', 'show_tasks', false], ['calendar', 'tasks_enabled', false] ); diff --git a/tests/php/unit/Controller/SettingsControllerTest.php b/tests/php/unit/Controller/SettingsControllerTest.php index ff7554ffb..35e9705ed 100755 --- a/tests/php/unit/Controller/SettingsControllerTest.php +++ b/tests/php/unit/Controller/SettingsControllerTest.php @@ -370,6 +370,59 @@ class SettingsControllerTest extends TestCase { $this->assertEquals(500, $actual->getStatus()); } + /** + * @param string $value + * @param int $expectedStatusCode + * + * @dataProvider setDefaultReminderWithAllowedValueDataProvider + */ + public function testSetDefaultReminderWithAllowedValue(string $value, + int $expectedStatusCode):void { + if ($expectedStatusCode === 200) { + $this->config->expects($this->once()) + ->method('setUserValue') + ->with('user123', $this->appName, 'defaultReminder', $value); + } + + $actual = $this->controller->setConfig('defaultReminder', $value); + + $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); + $this->assertEquals([], $actual->getData()); + $this->assertEquals($expectedStatusCode, $actual->getStatus()); + } + + public function setDefaultReminderWithAllowedValueDataProvider():array { + return [ + ['none', 200], + ['-0', 200], + ['0', 200], + ['-300', 200], + ['-600', 200], + ['-900', 200], + ['-1200', 200], + ['-2400', 200], + ['-2400', 200], + ['not-none', 422], + ['NaN', 422], + ['0.1', 422], + ['1', 422], + ['300', 422], + ]; + } + + public function testSetDefaultReminderWithException():void { + $this->config->expects($this->once()) + ->method('setUserValue') + ->with('user123', $this->appName, 'defaultReminder', 'none') + ->will($this->throwException(new \Exception)); + + $actual = $this->controller->setConfig('defaultReminder', 'none'); + + $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); + $this->assertEquals([], $actual->getData()); + $this->assertEquals(500, $actual->getStatus()); + } + public function testSetNotExistingConfig():void { $actual = $this->controller->setConfig('foo', 'bar'); diff --git a/tests/php/unit/Controller/ViewControllerTest.php b/tests/php/unit/Controller/ViewControllerTest.php index f8f92b604..10ea3fcdf 100755 --- a/tests/php/unit/Controller/ViewControllerTest.php +++ b/tests/php/unit/Controller/ViewControllerTest.php @@ -78,6 +78,7 @@ class ViewControllerTest extends TestCase { ['calendar', 'skipPopover', 'no', 'defaultSkipPopover'], ['calendar', 'timezone', 'automatic', 'defaultTimezone'], ['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'], + ['calendar', 'defaultReminder', 'none', 'defaultDefaultReminder'], ['calendar', 'showTasks', 'yes', 'defaultShowTasks'], ['calendar', 'installed_version', null, '1.0.0'], ]); @@ -92,6 +93,7 @@ class ViewControllerTest extends TestCase { ['user123', 'calendar', 'skipPopover', 'defaultSkipPopover', 'yes'], ['user123', 'calendar', 'timezone', 'defaultTimezone', 'Europe/Berlin'], ['user123', 'calendar', 'slotDuration', 'defaultSlotDuration', '00:15:00'], + ['user123', 'calendar', 'defaultReminder', 'defaultDefaultReminder', '00:10:00'], ['user123', 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'], ]); $this->appManager @@ -114,6 +116,7 @@ class ViewControllerTest extends TestCase { ['calendar', 'talk_enabled', true], ['calendar', 'timezone', 'Europe/Berlin'], ['calendar', 'slot_duration', '00:15:00'], + ['calendar', 'default_reminder', '00:10:00'], ['calendar', 'show_tasks', false], ['calendar', 'tasks_enabled', true] ); @@ -143,6 +146,7 @@ class ViewControllerTest extends TestCase { ['calendar', 'skipPopover', 'no', 'defaultSkipPopover'], ['calendar', 'timezone', 'automatic', 'defaultTimezone'], ['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'], + ['calendar', 'defaultReminder', 'none', 'defaultDefaultReminder'], ['calendar', 'showTasks', 'yes', 'defaultShowTasks'], ['calendar', 'installed_version', null, '1.0.0'], ]); @@ -157,6 +161,7 @@ class ViewControllerTest extends TestCase { ['user123', 'calendar', 'skipPopover', 'defaultSkipPopover', 'yes'], ['user123', 'calendar', 'timezone', 'defaultTimezone', 'Europe/Berlin'], ['user123', 'calendar', 'slotDuration', 'defaultSlotDuration', '00:15:00'], + ['user123', 'calendar', 'defaultReminder', 'defaultDefaultReminder', '00:10:00'], ['user123', 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'], ]); $this->appManager @@ -179,6 +184,7 @@ class ViewControllerTest extends TestCase { ['calendar', 'talk_enabled', true], ['calendar', 'timezone', 'Europe/Berlin'], ['calendar', 'slot_duration', '00:15:00'], + ['calendar', 'default_reminder', '00:10:00'], ['calendar', 'show_tasks', false], ['calendar', 'tasks_enabled', false] ); From 9e6b1c753682f4380885b09f8cf3e73692d69f91 Mon Sep 17 00:00:00 2001 From: Matteo Settenvini Date: Wed, 31 Mar 2021 20:53:33 +0200 Subject: [PATCH 3/3] Add user default reminder to new events Take the value from the saved settings for the default reminder, and if it is a valid amount of seconds, add a new alarm to newly created events. Signed-off-by: Matteo Settenvini --- src/store/calendarObjectInstance.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/store/calendarObjectInstance.js b/src/store/calendarObjectInstance.js index 49ed0a81b..fedfc768f 100644 --- a/src/store/calendarObjectInstance.js +++ b/src/store/calendarObjectInstance.js @@ -45,6 +45,8 @@ import { } from '../utils/color.js' import { mapAlarmComponentToAlarmObject } from '../models/alarm.js' import { getObjectAtRecurrenceId } from '../utils/calendarObject.js' +import logger from '../utils/logger.js' +import settings from './settings.js' const state = { isNew: null, @@ -1430,6 +1432,18 @@ const actions = { const eventComponent = getObjectAtRecurrenceId(calendarObject, startDate) const calendarObjectInstance = mapEventComponentToEventObject(eventComponent) + // Add an alarm if the user set a default one in the settings. If + // not, defaultReminder will not be a number (rather the string "none"). + const defaultReminder = parseInt(settings.state.defaultReminder) + if (!isNaN(defaultReminder)) { + commit('addAlarmToCalendarObjectInstance', { + calendarObjectInstance: calendarObjectInstance, + type: 'DISPLAY', + totalSeconds: defaultReminder, + }) + logger.debug(`Added defaultReminder (${defaultReminder}s) to newly created event`) + } + commit('setCalendarObjectInstanceForNewEvent', { calendarObject, calendarObjectInstance,