Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 87e85869 authored by Christoph Wurst's avatar Christoph Wurst
Browse files

Fetch the appointment availability default from caldav, if possible

parent f88e39f5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ export default {
		defaultConfig() {
			return AppointmentConfig.createDefault(
				this.calendarUrlToUri(this.$store.getters.sortedCalendars[0].url),
				this.$store.getters.scheduleInbox,
				this.$store.getters.getResolvedTimezone,
			)
		},
+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ export default {
		defaultConfig() {
			return AppointmentConfig.createDefault(
				this.calendarUrlToUri(this.$store.getters.sortedCalendars[0].url),
				this.$store.getters.scheduleInbox,
				this.$store.getters.getResolvedTimezone,
			)
		},
+20 −11
Original line number Diff line number Diff line
@@ -21,7 +21,10 @@
 */

import { generateUrl } from '@nextcloud/router'
import { getEmptySlots } from '@nextcloud/calendar-availability-vue'
import {
	getEmptySlots,
	vavailabilityToSlots,
} from '@nextcloud/calendar-availability-vue'

/** @class */
export default class AppointmentConfig {
@@ -114,18 +117,24 @@ export default class AppointmentConfig {
	 * Create a default appointment config instance
	 *
	 * @param {string} targetCalendarUri
	 * @param {string} timezoneId
	 * @param {ScheduleInbox} scheduleInbox
	 * @param {string} timezoneId fallback time zone when no schedule inbox availability is set
	 * @return {AppointmentConfig} Default appointment config instance
	 */
	static createDefault(targetCalendarUri, timezoneId) {
	static createDefault(targetCalendarUri, scheduleInbox, timezoneId) {
		let slots = getEmptySlots()
		if (scheduleInbox && scheduleInbox.availability) {
			const converted = vavailabilityToSlots(scheduleInbox.availability)
			slots = converted.slots
			timezoneId = slots.timezoneId
		} else {
			// Set default availability to Mo-Fr 9-5
		// TODO: fetch user's working hours if possible
		const tsAtTime = (hours, minutes) => Math.round((new Date()).setHours(hours, minutes, 0, 0) / 1000)
		const slots = getEmptySlots();
			const tsAtTime = (hours, minutes) => Math.round((new Date()).setHours(hours, minutes, 0, 0) / 1000);
			['MO', 'TU', 'WE', 'TH', 'FR'].forEach(day => slots[day].push({
				start: tsAtTime(9, 0),
				end: tsAtTime(17, 0),
			}))
		}

		return new AppointmentConfig({
			name: '',
+13 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import {
const state = {
	calendars: [],
	trashBin: undefined,
	scheduleInbox: undefined,
	deletedCalendars: [],
	deletedCalendarObjects: [],
	calendarsById: {},
@@ -80,6 +81,10 @@ const mutations = {
		state.trashBin = trashBin
	},

	addScheduleInbox(state, { scheduleInbox }) {
		state.scheduleInbox = scheduleInbox
	},

	/**
	 * Adds deleted calendar into state
	 *
@@ -412,6 +417,10 @@ const getters = {
		return state.trashBin
	},

	scheduleInbox: (state) => {
		return state.scheduleInbox
	},

	/**
	 * List of deleted sorted calendars
	 *
@@ -546,7 +555,7 @@ const actions = {
	 * @return {Promise<object>} the results
	 */
	async loadCollections({ commit, state, getters }) {
		const { calendars, trashBins } = await findAll()
		const { calendars, trashBins, scheduleInboxes } = await findAll()
		console.info('calendar home scanned', calendars, trashBins)
		calendars.map((calendar) => mapDavCollectionToCalendar(calendar, getters.getCurrentUserPrincipal)).forEach(calendar => {
			commit('addCalendar', { calendar })
@@ -554,6 +563,9 @@ const actions = {
		if (trashBins.length) {
			commit('addTrashBin', { trashBin: trashBins[0] })
		}
		if (scheduleInboxes.length) {
			commit('addScheduleInbox', { scheduleInbox: scheduleInboxes[0] })
		}

		commit('initialCalendarsLoaded')
		return {