Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings.js « store « src - github.com/nextcloud/calendar.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ffc937171c1e7bd33b27fea4d1b03b1c919cf77 (plain)
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
/**
 * @copyright Copyright (c) 2020 Georg Ehrke
 * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
 *
 * @author Georg Ehrke <oc.list@georgehrke.com>
 *
 * @license AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
import { enableBirthdayCalendar } from '../services/caldavService.js'
import { mapDavCollectionToCalendar } from '../models/calendar.js'
import { detectTimezone } from '../services/timezoneDetectionService.js'
import { setConfig as setCalendarJsConfig } from '@nextcloud/calendar-js'
import { setConfig } from '../services/settings.js'
import { logInfo } from '../utils/logger.js'
import getTimezoneManager from '../services/timezoneDataProviderService.js'

const state = {
	// env
	appVersion: null,
	firstRun: null,
	talkEnabled: false,
	disableAppointments: false,
	// user-defined calendar settings
	eventLimit: null,
	showTasks: null,
	showWeekends: null,
	showWeekNumbers: null,
	skipPopover: null,
	slotDuration: null,
	defaultReminder: null,
	tasksEnabled: false,
	timezone: 'automatic',
	hideEventExport: false,
	forceEventAlarmType: false,
	canSubscribeLink: true,
	// user-defined Nextcloud settings
	momentLocale: 'en',
}

const mutations = {

	/**
	 * Updates the user's setting for event limit
	 *
	 * @param {object} state The Vuex state
	 */
	toggleEventLimitEnabled(state) {
		state.eventLimit = !state.eventLimit
	},

	/**
	 * Updates the user's setting for visibility of event popover
	 *
	 * @param {object} state The Vuex state
	 */
	togglePopoverEnabled(state) {
		state.skipPopover = !state.skipPopover
	},

	/**
	 * Updates the user's setting for visibility of weekends
	 *
	 * @param {object} state The Vuex state
	 */
	toggleTasksEnabled(state) {
		state.showTasks = !state.showTasks
	},

	/**
	 * Updates the user's setting for visibility of weekends
	 *
	 * @param {object} state The Vuex state
	 */
	toggleWeekendsEnabled(state) {
		state.showWeekends = !state.showWeekends
	},

	/**
	 * Updates the user's setting for visibility of week numbers
	 *
	 * @param {object} state The Vuex state
	 */
	toggleWeekNumberEnabled(state) {
		state.showWeekNumbers = !state.showWeekNumbers
	},

	/**
	 * Updates the user's preferred slotDuration
	 *
	 * @param {object} state The Vuex state
	 * @param {object} data The destructuring object
	 * @param {string} data.slotDuration The new slot duration
	 */
	setSlotDuration(state, { slotDuration }) {
		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
	 *
	 * @param {object} state The Vuex state
	 * @param {object} data The destructuring object
	 * @param {string} data.timezoneId The new timezone
	 */
	setTimezone(state, { timezoneId }) {
		state.timezone = timezoneId
	},

	/**
	 * Initialize settings
	 *
	 * @param {object} state The Vuex state
	 * @param {object} data The destructuring object
	 * @param {string} data.appVersion The version of the Nextcloud app
	 * @param {boolean} data.eventLimit Whether or not to limit number of visible events in grid view
	 * @param {boolean} data.firstRun Whether or not this is the first run
	 * @param {boolean} data.showWeekNumbers Whether or not to show week numbers
	 * @param {boolean} data.showTasks Whether or not to display tasks with a due-date
	 * @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"
	 * @param {boolean} data.hideEventExport
	 * @param {string} data.forceEventAlarmType
	 * @param {boolean} data.disableAppointments Allow to disable the appointments feature
	 * @param {boolean} data.canSubscribeLink
	 */
	loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, canSubscribeLink }) {
		logInfo(`
Initial settings:
	- AppVersion: ${appVersion}
	- EventLimit: ${eventLimit}
	- FirstRun: ${firstRun}
	- ShowWeekNumbers: ${showWeekNumbers}
	- ShowTasks: ${showTasks}
	- ShowWeekends: ${showWeekends}
	- SkipPopover: ${skipPopover}
	- SlotDuration: ${slotDuration}
	- DefaultReminder: ${defaultReminder}
	- TalkEnabled: ${talkEnabled}
	- TasksEnabled: ${tasksEnabled}
	- Timezone: ${timezone}
	- HideEventExport: ${hideEventExport}
	- ForceEventAlarmType: ${forceEventAlarmType}
	- disableAppointments: ${disableAppointments}
	- CanSubscribeLink: ${canSubscribeLink}
`)

		state.appVersion = appVersion
		state.eventLimit = eventLimit
		state.firstRun = firstRun
		state.showWeekNumbers = showWeekNumbers
		state.showTasks = showTasks
		state.showWeekends = showWeekends
		state.skipPopover = skipPopover
		state.slotDuration = slotDuration
		state.defaultReminder = defaultReminder
		state.talkEnabled = talkEnabled
		state.tasksEnabled = tasksEnabled
		state.timezone = timezone
		state.hideEventExport = hideEventExport
		state.forceEventAlarmType = forceEventAlarmType
		state.disableAppointments = disableAppointments
		state.canSubscribeLink = canSubscribeLink
	},

	/**
	 * Sets the name of the moment.js locale to be used
	 *
	 * @param {object} state The Vuex state
	 * @param {object} data The destructuring object
	 * @param {string} data.locale The moment.js locale to be used
	 */
	setMomentLocale(state, { locale }) {
		logInfo(`Updated moment locale: ${locale}`)

		state.momentLocale = locale
	},
}

const getters = {

	/**
	 * Gets the resolved timezone.
	 * If the timezone is set to automatic, it returns the user's current timezone
	 * Otherwise, it returns the Olsen timezone stored
	 *
	 * @param {object} state The Vuex state
	 * @return {string}
	 */
	getResolvedTimezone: (state) => state.timezone === 'automatic'
		? detectTimezone()
		: state.timezone,

	/**
	 * Gets the resolved timezone object.
	 * Falls back to UTC if timezone is invalid.
	 *
	 * @param {object} state The Vuex state
	 * @param {object} getters The vuex getters
	 * @return {object} The calendar-js timezone object
	 */
	getResolvedTimezoneObject: (state, getters) => {
		const timezone = getters.getResolvedTimezone
		let timezoneObject = getTimezoneManager().getTimezoneForId(timezone)
		if (!timezoneObject) {
			timezoneObject = getTimezoneManager().getTimezoneForId('UTC')
		}
		return timezoneObject
	},
}

const actions = {

	/**
	 * Updates the user's setting for visibility of birthday calendar
	 *
	 * @param {object} vuex The Vuex destructuring object
	 * @param {object} vuex.getters The Vuex Getters
	 * @param {Function} vuex.commit The Vuex commit Function
	 * @param {Function} vuex.dispatch The Vuex dispatch Function
	 * @return {Promise<void>}
	 */
	async toggleBirthdayCalendarEnabled({ getters, commit, dispatch }) {
		if (getters.hasBirthdayCalendar) {
			const calendar = getters.getBirthdayCalendar
			await dispatch('deleteCalendar', { calendar })
		} else {
			const davCalendar = await enableBirthdayCalendar()
			const calendar = mapDavCollectionToCalendar(davCalendar)
			commit('addCalendar', { calendar })
		}
	},

	/**
	 * Updates the user's setting for event limit
	 *
	 * @param {object} vuex The Vuex destructuring object
	 * @param {object} vuex.state The Vuex state
	 * @param {Function} vuex.commit The Vuex commit Function
	 * @return {Promise<void>}
	 */
	async toggleEventLimitEnabled({ state, commit }) {
		const newState = !state.eventLimit
		const value = newState ? 'yes' : 'no'

		await setConfig('eventLimit', value)
		commit('toggleEventLimitEnabled')
	},

	/**
	 * Updates the user's setting for visibility of event popover
	 *
	 * @param {object} context The Vuex context
	 * @param {object} context.state The store state
	 * @param {object} context.commit The store mutations
	 * @return {Promise<void>}
	 */
	async togglePopoverEnabled({ state, commit }) {
		const newState = !state.skipPopover
		const value = newState ? 'yes' : 'no'

		await setConfig('skipPopover', value)
		commit('togglePopoverEnabled')
	},

	/**
	 * Updates the user's setting for visibility of weekends
	 *
	 * @param {object} context The Vuex context
	 * @param {object} context.state The store state
	 * @param {object} context.commit The store mutations
	 * @return {Promise<void>}
	 */
	async toggleWeekendsEnabled({ state, commit }) {
		const newState = !state.showWeekends
		const value = newState ? 'yes' : 'no'

		await setConfig('showWeekends', value)
		commit('toggleWeekendsEnabled')
	},

	/**
	 * Updates the user's setting for visibility of tasks
	 *
	 * @param {object} vuex The Vuex destructuring object
	 * @param {object} vuex.state The Vuex state
	 * @param {Function} vuex.commit The Vuex commit Function
	 * @return {Promise<void>}
	 */
	async toggleTasksEnabled({ state, commit }) {
		const newState = !state.showTasks
		const value = newState ? 'yes' : 'no'

		await setConfig('showTasks', value)
		commit('toggleTasksEnabled')
		commit('clearFetchedTimeRanges')
		commit('incrementModificationCount')
	},

	/**
	 * Updates the user's setting for visibility of week numbers
	 *
	 * @param {object} vuex The Vuex destructuring object
	 * @param {object} vuex.state The Vuex state
	 * @param {Function} vuex.commit The Vuex commit Function
	 * @return {Promise<void>}
	 */
	async toggleWeekNumberEnabled({ state, commit }) {
		const newState = !state.showWeekNumbers
		const value = newState ? 'yes' : 'no'

		await setConfig('showWeekNr', value)
		commit('toggleWeekNumberEnabled')
	},

	/**
	 * Updates the view to be used as initial view when opening
	 * the calendar app again
	 *
	 * @param {object} context The Vuex destructuring object
	 * @param {object} data The destructuring object
	 * @param {string} data.initialView New view to be used as initial view
	 * @return {Promise<void>}
	 */
	async setInitialView(context, { initialView }) {
		await setConfig('view', initialView)
	},

	/**
	 * Updates the user's preferred slotDuration
	 *
	 * @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.slotDuration The new slot duration
	 */
	async setSlotDuration({ state, commit }, { slotDuration }) {
		if (state.slotDuration === slotDuration) {
			return
		}

		await setConfig('slotDuration', slotDuration)
		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
	 *
	 * @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.timezoneId The new timezone
	 * @return {Promise<void>}
	 */
	async setTimezone({ state, commit }, { timezoneId }) {
		if (state.timezone === timezoneId) {
			return
		}

		await setConfig('timezone', timezoneId)
		commit('setTimezone', { timezoneId })
	},

	/**
	 * Initializes the calendar-js configuration
	 *
	 * @param {object} vuex The Vuex destructuring object
	 * @param {object} vuex.state The Vuex state
	 */
	initializeCalendarJsConfig({ state }) {
		setCalendarJsConfig('PRODID', `-//IDN nextcloud.com//Calendar app ${state.appVersion}//EN`)
		setCalendarJsConfig('property-list-significant-change', [
			'SUMMARY',
			'LOCATION',
			'DESCRIPTION',
		])
	},
}

export default { state, mutations, getters, actions }