This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/views/user/settings/Caldav.vue

113 lines
3.4 KiB
Vue
Raw Normal View History

<template>
<card v-if="caldavEnabled" :title="$t('user.settings.caldav.title')">
<p>
{{ $t('user.settings.caldav.howTo') }}
</p>
<div class="field has-addons no-input-mobile">
<div class="control is-expanded">
<input type="text" v-model="caldavUrl" class="input" readonly/>
</div>
<div class="control">
<x-button
2021-12-20 17:32:57 +00:00
@click="copy(caldavUrl)"
:shadow="false"
v-tooltip="$t('misc.copy')"
icon="paste"
/>
</div>
</div>
2021-12-12 17:28:14 +00:00
2021-12-26 10:36:54 +00:00
<h5 class="mt-5 mb-4 has-text-weight-bold">
2021-12-12 17:28:14 +00:00
{{ $t('user.settings.caldav.tokens') }}
2021-12-26 10:36:54 +00:00
</h5>
2021-12-12 17:28:14 +00:00
<p>
{{ isLocalUser ? $t('user.settings.caldav.tokensHowTo') : $t('user.settings.caldav.mustUseToken') }}
<template v-if="!isLocalUser">
<br/>
<i18n-t keypath="user.settings.caldav.usernameIs">
<strong>{{ username }}</strong>
</i18n-t>
</template>
2021-12-12 17:28:14 +00:00
</p>
<table class="table" v-if="tokens.length > 0">
<tr>
<th>{{ $t('misc.id') }}</th>
<th>{{ $t('misc.created') }}</th>
2021-12-12 17:32:32 +00:00
<th class="has-text-right">{{ $t('misc.actions') }}</th>
2021-12-12 17:28:14 +00:00
</tr>
2021-12-14 20:39:16 +00:00
<tr v-for="tk in tokens" :key="tk.id">
2021-12-12 17:28:14 +00:00
<td>{{ tk.id }}</td>
<td>{{ formatDateShort(tk.created) }}</td>
2021-12-12 17:32:32 +00:00
<td class="has-text-right">
2021-12-12 17:28:14 +00:00
<x-button type="secondary" @click="deleteToken(tk)">
{{ $t('misc.delete') }}
</x-button>
</td>
</tr>
</table>
<Message v-if="newToken" class="mb-4">
{{ $t('user.settings.caldav.tokenCreated', {token: newToken.token}) }}<br/>
{{ $t('user.settings.caldav.wontSeeItAgain') }}
</Message>
<x-button icon="plus" class="mb-4" @click="createToken" :loading="service.loading">
{{ $t('user.settings.caldav.createToken') }}
</x-button>
<p>
2022-02-13 20:54:40 +00:00
<BaseButton :href="CALDAV_DOCS" target="_blank">
{{ $t('user.settings.caldav.more') }}
2022-01-04 23:13:16 +00:00
</BaseButton>
</p>
</card>
</template>
2021-12-12 17:01:51 +00:00
<script lang="ts" setup>
2022-01-04 23:13:08 +00:00
import {computed, ref, shallowReactive} from 'vue'
2021-12-12 17:01:51 +00:00
import {useI18n} from 'vue-i18n'
2022-07-21 16:45:58 +00:00
import {useStore} from '@/store'
2021-12-12 17:01:51 +00:00
import {CALDAV_DOCS} from '@/urls'
2021-12-12 17:01:51 +00:00
import {useTitle} from '@/composables/useTitle'
import {useCopyToClipboard} from '@/composables/useCopyToClipboard'
2021-12-12 17:28:14 +00:00
import {success} from '@/message'
2022-01-04 23:13:16 +00:00
import BaseButton from '@/components/base/BaseButton.vue'
2021-12-14 20:27:16 +00:00
import Message from '@/components/misc/message.vue'
import CaldavTokenService from '@/services/caldavToken'
2022-06-23 00:58:00 +00:00
import { formatDateShort } from '@/helpers/time/formatDate'
2022-07-20 22:42:36 +00:00
import type { ICaldavToken } from '@/models/caldavToken'
2021-12-12 17:01:51 +00:00
const copy = useCopyToClipboard()
const {t} = useI18n({useScope: 'global'})
2021-12-12 17:01:51 +00:00
useTitle(() => `${t('user.settings.caldav.title')} - ${t('user.settings.title')}`)
2022-01-04 23:13:08 +00:00
const service = shallowReactive(new CaldavTokenService())
2022-07-20 22:42:36 +00:00
const tokens = ref<ICaldavToken[]>([])
2021-12-12 17:28:14 +00:00
2022-07-20 22:42:36 +00:00
service.getAll().then((result: ICaldavToken[]) => {
2022-01-04 23:13:08 +00:00
tokens.value = result
})
2022-07-20 22:42:36 +00:00
const newToken = ref<ICaldavToken>()
async function createToken() {
2022-07-20 22:42:36 +00:00
newToken.value = await service.create({}) as ICaldavToken
2021-12-26 10:54:27 +00:00
tokens.value.push(newToken.value)
2021-12-12 17:28:14 +00:00
}
2022-07-20 22:42:36 +00:00
async function deleteToken(token: ICaldavToken) {
2021-12-14 20:31:25 +00:00
const r = await service.delete(token)
2022-01-04 23:13:08 +00:00
tokens.value = tokens.value.filter(({id}) => id !== token.id)
success(r)
2021-12-12 17:28:14 +00:00
}
2022-01-04 23:13:08 +00:00
const store = useStore()
const username = computed(() => store.state.auth.info?.username)
const caldavUrl = computed(() => `${store.getters['config/apiBase']}/dav/principals/${username.value}/`)
const caldavEnabled = computed(() => store.state.config.caldavEnabled)
const isLocalUser = computed(() => store.state.auth.info?.isLocalUser)
</script>