From bf3cb560111f3e2b23120321444a71b2301bee12 Mon Sep 17 00:00:00 2001 From: Lukas Boersma Date: Sat, 13 Jun 2020 12:45:01 +0200 Subject: [PATCH 1/5] Add a setting for the default calendar when creating new events Signed-off-by: Lukas Boersma --- css/app-settings.scss | 5 +- lib/Controller/PublicViewController.php | 2 + lib/Controller/SettingsController.php | 23 +++++++++ lib/Controller/ViewController.php | 3 ++ src/components/AppNavigation/Settings.vue | 58 +++++++++++++++++++++++ src/components/CalendarGrid.vue | 2 + src/components/Shared/CalendarPicker.vue | 10 ++-- src/mixins/EditorMixin.js | 3 +- src/store/calendarObjectInstance.js | 4 +- src/store/calendarObjects.js | 5 +- src/store/settings.js | 31 ++++++++++++ src/views/Calendar.vue | 2 + 12 files changed, 137 insertions(+), 11 deletions(-) diff --git a/css/app-settings.scss b/css/app-settings.scss index cb36c2301d..b497441901 100644 --- a/css/app-settings.scss +++ b/css/app-settings.scss @@ -76,8 +76,9 @@ width: 50%; } } - - &--timezone { + + &--timezone, + &--default-calendar { width: 100%; .multiselect { diff --git a/lib/Controller/PublicViewController.php b/lib/Controller/PublicViewController.php index 168625c483..b058f0f5a4 100644 --- a/lib/Controller/PublicViewController.php +++ b/lib/Controller/PublicViewController.php @@ -127,6 +127,7 @@ private function publicIndex(string $token, $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'); + $defaultCalendarId = $this->config->getAppValue($this->appName, 'defaultCalendarId', 'none'); $defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); $appVersion = $this->config->getAppValue($this->appName, 'installed_version', null); @@ -143,6 +144,7 @@ private function publicIndex(string $token, $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, 'default_calendar_id', $defaultCalendarId); $this->initialStateService->provideInitialState($this->appName, 'show_tasks', $defaultShowTasks === 'yes'); $this->initialStateService->provideInitialState($this->appName, 'tasks_enabled', false); $this->initialStateService->provideInitialState($this->appName, 'hide_event_export', false); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 9d370a0011..f63e103079 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -89,6 +89,8 @@ public function setConfig(string $key, return $this->setSlotDuration($value); case 'defaultReminder': return $this->setDefaultReminder($value); + case 'defaultCalendarId': + return $this->setDefaultCalendarId($value); case 'showTasks': return $this->setShowTasks($value); default: @@ -339,4 +341,25 @@ private function setDefaultReminder(string $value):JSONResponse { return new JSONResponse(); } + + /** + * sets defaultCalendarId for user + * + * @param string $value User-selected option for default calendar when creating new events + * @return JSONResponse + */ + private function setDefaultCalendarId(string $value):JSONResponse { + try { + $this->config->setUserValue( + $this->userId, + $this->appName, + 'defaultCalendarId', + $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 2cbf8335c4..de19c50ae6 100644 --- a/lib/Controller/ViewController.php +++ b/lib/Controller/ViewController.php @@ -81,6 +81,7 @@ public function index():TemplateResponse { $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'); + $defaultCalendarIdGlobal = $this->config->getAppValue($this->appName, 'defaultCalendarId', ''); $defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); $appVersion = $this->config->getAppValue($this->appName, 'installed_version', null); @@ -93,6 +94,7 @@ public function index():TemplateResponse { $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); + $defaultCalendarIdUser = $this->config->getUserValue($this->userId, $this->appName, 'defaultCalendarId', $defaultCalendarId); $showTasks = $this->config->getUserValue($this->userId, $this->appName, 'showTasks', $defaultShowTasks) === 'yes'; $hideEventExport = $this->config->getAppValue($this->appName, 'hideEventExport', 'no') === 'yes'; $disableAppointments = $this->config->getAppValue($this->appName, 'disableAppointments', 'no') === 'yes'; @@ -117,6 +119,7 @@ public function index():TemplateResponse { $this->initialStateService->provideInitialState('timezone', $timezone); $this->initialStateService->provideInitialState('slot_duration', $slotDuration); $this->initialStateService->provideInitialState('default_reminder', $defaultReminder); + $this->initialStateService->provideInitialState($this->appName, 'default_calendar_id', $defaultCalendarIdUser); $this->initialStateService->provideInitialState('show_tasks', $showTasks); $this->initialStateService->provideInitialState('tasks_enabled', $tasksEnabled); $this->initialStateService->provideInitialState('hide_event_export', $hideEventExport); diff --git a/src/components/AppNavigation/Settings.vue b/src/components/AppNavigation/Settings.vue index 52f7c9c223..fe9faddb86 100644 --- a/src/components/AppNavigation/Settings.vue +++ b/src/components/AppNavigation/Settings.vue @@ -82,6 +82,16 @@ @select="changeDefaultReminder" /> +
  • + +