Skip to content

Commit

Permalink
Allow admins to force an event type
Browse files Browse the repository at this point in the history
Any other value set by another client still shows up. This only
"enforces" the alarm type for those who only use the Calendar app.

Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Mar 3, 2022
1 parent d46acc5 commit d90c27c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IRequest;
use function in_array;

class ViewController extends Controller {

Expand Down Expand Up @@ -94,6 +95,10 @@ public function index():TemplateResponse {
$defaultReminder = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminder', $defaultDefaultReminder);
$showTasks = $this->config->getUserValue($this->userId, $this->appName, 'showTasks', $defaultShowTasks) === 'yes';
$hideEventExport = $this->config->getAppValue($this->appName, 'hideEventExport', 'no') === 'yes';
$forceEventAlarmType = $this->config->getAppValue($this->appName, 'forceEventAlarmType', '');
if (!in_array($forceEventAlarmType, ['DISPLAY', 'EMAIL'], true)) {
$forceEventAlarmType = null;
}

$talkEnabled = $this->appManager->isEnabledForUser('spreed');
$talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1';
Expand All @@ -114,6 +119,7 @@ public function index():TemplateResponse {
$this->initialStateService->provideInitialState('show_tasks', $showTasks);
$this->initialStateService->provideInitialState('tasks_enabled', $tasksEnabled);
$this->initialStateService->provideInitialState('hide_event_export', $hideEventExport);
$this->initialStateService->provideInitialState('force_event_alarm_type', $forceEventAlarmType);
$this->initialStateService->provideInitialState('appointmentConfigs',$this->appointmentConfigService->getAllAppointmentConfigurations($this->userId));

return new TemplateResponse($this->appName, 'main');
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editor/Alarm/AlarmList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<script>
import AlarmListNew from './AlarmListNew'
import AlarmListItem from './AlarmListItem'
import { mapState } from 'vuex'

export default {
name: 'AlarmList',
Expand All @@ -61,6 +62,9 @@ export default {
},
},
computed: {
...mapState({
forceEventAlarmType: (state) => state.settings.forceEventAlarmType,
}),
alarms() {
return this.calendarObjectInstance.alarms
},
Expand All @@ -74,7 +78,7 @@ export default {
addAlarm(totalSeconds) {
this.$store.commit('addAlarmToCalendarObjectInstance', {
calendarObjectInstance: this.calendarObjectInstance,
type: 'DISPLAY',
type: this.forceEventAlarmType ?? 'DISPLAY',
totalSeconds,
})
},
Expand Down
12 changes: 9 additions & 3 deletions src/components/Editor/Alarm/AlarmListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,35 @@
class="property-alarm-item__options">
<Actions>
<ActionRadio
v-if="canChangeAlarmType && (isAlarmTypeDisplay || forceEventAlarmType === null || forceEventAlarmType === 'DISPLAY')"
:name="alarmTypeName"
:checked="isAlarmTypeDisplay"
@change="changeType('DISPLAY')">
{{ $t('calendar', 'Notification') }}
</ActionRadio>
<ActionRadio
v-if="canChangeAlarmType && (isAlarmTypeEmail || forceEventAlarmType === null || forceEventAlarmType === 'EMAIL')"
:name="alarmTypeName"
:checked="isAlarmTypeEmail"
@change="changeType('EMAIL')">
{{ $t('calendar', 'Email') }}
</ActionRadio>
<ActionRadio
v-if="isAlarmTypeAudio"
v-if="canChangeAlarmType && isAlarmTypeAudio"
:name="alarmTypeName"
:checked="isAlarmTypeAudio"
@change="changeType('AUDIO')">
{{ $t('calendar', 'Audio notification') }}
</ActionRadio>
<ActionRadio
v-if="isAlarmTypeOther"
v-if="canChangeAlarmType && isAlarmTypeOther"
:name="alarmTypeName"
:checked="isAlarmTypeOther"
@change="changeType(alarm.type)">
{{ $t('calendar', 'Other notification') }}
</ActionRadio>

<ActionSeparator v-if="!isRecurring" />
<ActionSeparator v-if="canChangeAlarmType && !isRecurring" />

<ActionRadio
v-if="!isRecurring"
Expand Down Expand Up @@ -236,6 +238,7 @@ export default {
computed: {
...mapState({
locale: (state) => state.settings.momentLocale,
forceEventAlarmType: (state) => state.settings.forceEventAlarmType,
}),
canEdit() {
// You can always edit an alarm if it's absolute
Expand Down Expand Up @@ -263,6 +266,9 @@ export default {

return true
},
canChangeAlarmType() {
return this.forceEventAlarmType !== null && this.alarm.type !== this.forceEventAlarmType
},
alarmTypeName() {
return this._uid + '-radio-type-name'
},
Expand Down
7 changes: 5 additions & 2 deletions src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const state = {
tasksEnabled: false,
timezone: 'automatic',
hideEventExport: false,
forceEventAlarmType: null,
// user-defined Nextcloud settings
momentLocale: 'en',
}
Expand Down Expand Up @@ -143,9 +144,10 @@ const mutations = {
* @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"
* @param data.hideEventExport
* @param {boolean} data.hideEventExport
* @param {string} data.forceEventAlarmType
*/
loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport }) {
loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType }) {
logInfo(`
Initial settings:
- AppVersion: ${appVersion}
Expand Down Expand Up @@ -175,6 +177,7 @@ Initial settings:
state.tasksEnabled = tasksEnabled
state.timezone = timezone
state.hideEventExport = hideEventExport
state.forceEventAlarmType = forceEventAlarmType
},

/**
Expand Down
1 change: 1 addition & 0 deletions src/views/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export default {
timezone: loadState('calendar', 'timezone'),
showTasks: loadState('calendar', 'show_tasks'),
hideEventExport: loadState('calendar', 'hide_event_export'),
forceEventAlarmType: loadState('calendar', 'force_event_alarm_type', null),
})
this.$store.dispatch('initializeCalendarJsConfig')

Expand Down

0 comments on commit d90c27c

Please sign in to comment.