use two different entry points

Signed-off-by: escoand <escoand@users.noreply.github.com>
This commit is contained in:
escoand 2023-12-12 08:58:20 +01:00
parent 42cc59bd42
commit 5ac3078e6d
7 changed files with 84 additions and 31 deletions

View File

@ -120,6 +120,7 @@ class ViewController extends Controller {
}
$canSubscribeLink = $this->config->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes';
$showResources = $this->config->getAppValue($this->appName, 'showResources', 'yes') === 'yes';
$publicCalendars = $this->config->getAppValue($this->appName, 'publicCalendars', '');
$talkEnabled = $this->appManager->isEnabledForUser('spreed');
$talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1';
@ -152,6 +153,7 @@ class ViewController extends Controller {
$this->initialStateService->provideInitialState('can_subscribe_link', $canSubscribeLink);
$this->initialStateService->provideInitialState('show_resources', $showResources);
$this->initialStateService->provideInitialState('isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible);
$this->initialStateService->provideInitialState('publicCalendars', $publicCalendars);
return new TemplateResponse($this->appName, 'main');
}

View File

@ -98,9 +98,19 @@
<Web :size="20" decorative />
</template>
</ActionButton>
<ActionButton v-if="hasPublicCalendars" @click="showPublicCalendarSubscriptionPicker = true">
{{ t('calendar', 'Add custom public calendar') }}
<template #icon>
<Web :size="20" decorative />
</template>
</ActionButton>
</template>
<template #extra>
<HolidaySubscriptionPicker v-if="showHolidaySubscriptionPicker" @close="showHolidaySubscriptionPicker = false" />
<PublicCalendarSubscriptionPicker v-if="showHolidaySubscriptionPicker"
:show-holidays="true"
@close="showHolidaySubscriptionPicker = false" />
<PublicCalendarSubscriptionPicker v-if="showPublicCalendarSubscriptionPicker"
@close="showPublicCalendarSubscriptionPicker = false" />
</template>
</AppNavigationItem>
</template>
@ -136,7 +146,7 @@ export default {
AppNavigationItem,
CalendarBlank,
CalendarCheck,
HolidaySubscriptionPicker: () => import(/* webpackChunkName: "holiday-subscription-picker" */ '../../Subscription/HolidaySubscriptionPicker.vue'),
PublicCalendarSubscriptionPicker: () => import(/* webpackChunkName: "public-calendar-subscription-picker" */ '../../Subscription/PublicCalendarSubscriptionPicker.vue'),
LinkVariant,
Plus,
Web,
@ -158,11 +168,13 @@ export default {
showCreateSubscriptionInput: false,
showCreateSubscriptionSaving: false,
showHolidaySubscriptionPicker: false,
showPublicCalendarSubscriptionPicker: false,
}
},
computed: {
...mapState({
canSubscribeLink: state => state.settings.canSubscribeLink,
hasPublicCalendars: state => Boolean(state.settings.publicCalendars),
}),
},
watch: {

View File

@ -21,22 +21,29 @@
<template>
<NcModal @close="$emit('close', $event)">
<div class="holiday-subscription-picker">
<h2>{{ t('calendar', 'Public holiday calendars') }}</h2>
<p class="holiday-subscription-picker__attribution">
{{ t('calendar', 'Public holiday calendars are provided by Thunderbird. Calendar data will be downloaded from {website}', { website: 'thunderbird.net' }) }}
<div class="public-calendar-subscription-picker">
<h2 v-if="showHolidays">
{{ t('calendar', 'Public holiday calendars') }}
</h2>
<h2 v-else>
{{ t('calendar', 'Public calendars') }}
</h2>
<p v-if="showHolidays" class="holiday-subscription-picker__attribution">
{{ t('calendar',
'Public holiday calendars are provided by Thunderbird. Calendar data will be downloaded from {website}',
{ website: 'thunderbird.net' }) }}
</p>
<div v-for="calendar in calendars" :key="calendar.source" class="holiday-subscription-picker__region">
<div class="holiday-subscription-picker__region__name">
<h3>{{ calendar.country }}</h3>
<div class="holiday-subscription-picker__region__name__subline">
{{ calendar.datespan }}
<div v-for="calendar in calendars" :key="calendar.source" class="public-calendar-subscription-picker__region">
<div class="public-calendar-subscription-picker__region__name">
<h3>{{ calendar.name }}</h3>
<div v-if="calendar.description" class="public-calendar-subscription-picker__region__name__subline">
{{ calendar.description }}
</div>
<div class="holiday-subscription-picker__region__name__subline">
<div v-if="calendar.authors" class="public-calendar-subscription-picker__region__name__subline">
{{ t('calendar', 'By {authors}', { authors: calendar.authors }) }}
</div>
</div>
<div class="holiday-subscription-picker__region__subcribe">
<div class="public-calendar-subscription-picker__region__subcribe">
<NcButton :disabled="loading || subscribing[calendar.source] || subscribed[calendar.source]"
@click="subscribe(calendar)">
{{ subscribed[calendar.source] ? t('calendar', 'Subscribed') : t('calendar', 'Subscribe') }}
@ -55,18 +62,38 @@ import { mapGetters } from 'vuex'
import { findAllSubscriptions } from '../../services/caldavService.js'
import holidayCalendars from '../../resources/holiday_calendars.json'
import { uidToHexColor } from '../../utils/color.js'
import { loadState } from '@nextcloud/initial-state'
export default {
name: 'HolidaySubscriptionPicker',
name: 'PublicCalendarSubscriptionPicker',
components: {
NcButton,
NcModal,
},
props: {
showHolidays: Boolean,
},
data() {
const calendars = holidayCalendars.map(calendar => ({
...calendar,
source: 'https://www.thunderbird.net/media/caldata/' + calendar.filename,
}))
let calendars = []
if (this.showHolidays) {
calendars = holidayCalendars.map(calendar => ({
...calendar,
displayName: t('calendar', 'Holidays in {region}', {
region: calendar.country,
}),
name: calendar.country,
description: calendar.datespan,
source: 'https://www.thunderbird.net/media/caldata/' + calendar.filename,
}))
} else {
try {
const state = loadState('calendar', 'publicCalendars')
calendars = JSON.parse(state)
} catch (error) {
console.error('Could not read public calendars', error)
showError(this.$t('calendar', 'An error occurred, unable to read public calendars.'))
}
}
const subscribing = {}
const subscribed = {}
calendars.forEach(calendar => {
@ -92,21 +119,19 @@ export default {
this.loading = false
},
methods: {
async subscribe(calendar) {
async subscribe(calendar) {
try {
this.subscribing[calendar.source] = true
this.subscribing[calendar.source] = true
await this.$store.dispatch('appendSubscription', {
displayName: t('calendar', 'Holidays in {region}', {
region: calendar.country,
}),
displayName: calendar.displayName || calendar.name,
color: uidToHexColor(calendar.source),
source: calendar.source,
})
this.subscribed[calendar.source] = true
} catch (error) {
console.error('Could not add holiday subscription', error)
showError(this.$t('calendar', 'An error occurred, unable to create the public holiday calendar.'))
console.error('Could not add calendar subscription', error)
showError(this.$t('calendar', 'An error occurred, unable to subscribe to calendar.'))
} finally {
this.subscribing[calendar.source] = false
}
@ -116,7 +141,7 @@ export default {
</script>
<style lang="scss" scoped>
.holiday-subscription-picker {
.public-calendar-subscription-picker {
padding: 20px;
&__attribution {

View File

@ -34,6 +34,7 @@ const state = {
firstRun: null,
talkEnabled: false,
disableAppointments: false,
publicCalendars: null,
// user-defined calendar settings
eventLimit: null,
showTasks: null,
@ -167,8 +168,9 @@ const mutations = {
* @param {boolean} data.canSubscribeLink
* @param {string} data.attachmentsFolder Default user's attachments folder
* @param {boolean} data.showResources Show or hide the resources tab
* @param {string} data.publicCalendars
*/
loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, canSubscribeLink, attachmentsFolder, showResources }) {
loadSettingsFromServer(state, { appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, canSubscribeLink, attachmentsFolder, showResources, publicCalendars }) {
logInfo(`
Initial settings:
- AppVersion: ${appVersion}
@ -189,6 +191,7 @@ Initial settings:
- CanSubscribeLink: ${canSubscribeLink}
- attachmentsFolder: ${attachmentsFolder}
- ShowResources: ${showResources}
- PublicCalendars: ${publicCalendars}
`)
state.appVersion = appVersion
@ -209,6 +212,7 @@ Initial settings:
state.canSubscribeLink = canSubscribeLink
state.attachmentsFolder = attachmentsFolder
state.showResources = showResources
state.publicCalendars = publicCalendars
},
/**

View File

@ -225,6 +225,7 @@ export default {
canSubscribeLink: loadState('calendar', 'can_subscribe_link', false),
attachmentsFolder: loadState('calendar', 'attachments_folder', false),
showResources: loadState('calendar', 'show_resources', true),
publicCalendars: loadState('calendar', 'publicCalendars'),
})
this.$store.dispatch('initializeCalendarJsConfig')

View File

@ -67,6 +67,7 @@ describe('store/settings test suite', () => {
canSubscribeLink: true,
attachmentsFolder: '/Calendar',
showResources: true,
publicCalendars: null,
})
})
@ -179,6 +180,7 @@ describe('store/settings test suite', () => {
canSubscribeLink: true,
attachmentsFolder: '/Calendar',
showResources: true,
publicCalendars: null,
}
const settings = {
@ -201,6 +203,7 @@ describe('store/settings test suite', () => {
canSubscribeLink: true,
attachmentsFolder: '/Attachments',
showResources: true,
publicCalendars: null,
}
settingsStore.mutations.loadSettingsFromServer(state, settings)
@ -226,6 +229,7 @@ Initial settings:
- CanSubscribeLink: true
- attachmentsFolder: /Attachments
- ShowResources: true
- PublicCalendars: null
`)
expect(state).toEqual({
appVersion: '2.1.0',
@ -248,6 +252,7 @@ Initial settings:
canSubscribeLink: true,
attachmentsFolder: '/Attachments',
showResources: true,
publicCalendars: null,
})
})

View File

@ -94,7 +94,7 @@ class ViewControllerTest extends TestCase {
}
public function testIndex(): void {
$this->config->expects(self::exactly(15))
$this->config->expects(self::exactly(16))
->method('getAppValue')
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'defaultEventLimit'],
@ -112,6 +112,7 @@ class ViewControllerTest extends TestCase {
['calendar', 'forceEventAlarmType', '', 'forceEventAlarmType'],
['dav', 'allow_calendar_link_subscriptions', 'yes', 'no'],
['calendar', 'showResources', 'yes', 'yes'],
['calendar', 'publicCalendars', ''],
]);
$this->config->expects(self::exactly(11))
->method('getUserValue')
@ -145,7 +146,7 @@ class ViewControllerTest extends TestCase {
->method('getAllAppointmentConfigurations')
->with($this->userId)
->willReturn([new AppointmentConfig()]);
$this->initialStateService->expects(self::exactly(22))
$this->initialStateService->expects(self::exactly(23))
->method('provideInitialState')
->withConsecutive(
['app_version', '1.0.0'],
@ -170,6 +171,7 @@ class ViewControllerTest extends TestCase {
['can_subscribe_link', false],
['show_resources', true],
['isCirclesEnabled', false],
['publicCalendars', null],
);
$response = $this->controller->index();
@ -187,7 +189,7 @@ class ViewControllerTest extends TestCase {
* @param string $expectedView
*/
public function testIndexViewFix(string $savedView, string $expectedView): void {
$this->config->expects(self::exactly(15))
$this->config->expects(self::exactly(16))
->method('getAppValue')
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'defaultEventLimit'],
@ -205,6 +207,7 @@ class ViewControllerTest extends TestCase {
['calendar', 'forceEventAlarmType', '', 'forceEventAlarmType'],
['dav', 'allow_calendar_link_subscriptions', 'yes', 'no'],
['calendar', 'showResources', 'yes', 'yes'],
['calendar', 'publicCalendars', ''],
]);
$this->config->expects(self::exactly(11))
->method('getUserValue')
@ -238,7 +241,7 @@ class ViewControllerTest extends TestCase {
->method('getAllAppointmentConfigurations')
->with($this->userId)
->willReturn([new AppointmentConfig()]);
$this->initialStateService->expects(self::exactly(22))
$this->initialStateService->expects(self::exactly(23))
->method('provideInitialState')
->withConsecutive(
['app_version', '1.0.0'],
@ -263,6 +266,7 @@ class ViewControllerTest extends TestCase {
['can_subscribe_link', false],
['show_resources', true],
['isCirclesEnabled', false],
['publicCalendars', null],
);
$response = $this->controller->index();