2021-10-26 20:58:02 +00:00
|
|
|
<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 18:32:57 +01:00
|
|
|
@click="copy(caldavUrl)"
|
|
|
|
:shadow="false"
|
|
|
|
v-tooltip="$t('misc.copy')"
|
|
|
|
icon="paste"
|
2021-10-26 20:58:02 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-12 18:28:14 +01:00
|
|
|
|
|
|
|
<p class="my-4 has-text-weight-bold">
|
|
|
|
{{ $t('user.settings.caldav.tokens') }}
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
2021-12-12 18:39:17 +01:00
|
|
|
{{ 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 18:28:14 +01:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<table class="table" v-if="tokens.length > 0">
|
|
|
|
<tr>
|
|
|
|
<th>{{ $t('misc.id') }}</th>
|
|
|
|
<th>{{ $t('misc.created') }}</th>
|
2021-12-12 18:32:32 +01:00
|
|
|
<th class="has-text-right">{{ $t('misc.actions') }}</th>
|
2021-12-12 18:28:14 +01:00
|
|
|
</tr>
|
2021-12-14 21:39:16 +01:00
|
|
|
<tr v-for="tk in tokens" :key="tk.id">
|
2021-12-12 18:28:14 +01:00
|
|
|
<td>{{ tk.id }}</td>
|
|
|
|
<td>{{ formatDateShort(tk.created) }}</td>
|
2021-12-12 18:32:32 +01:00
|
|
|
<td class="has-text-right">
|
2021-12-12 18:28:14 +01: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>
|
|
|
|
|
2021-10-26 20:58:02 +00:00
|
|
|
<p>
|
2021-12-12 18:01:51 +01:00
|
|
|
<a :href="CALDAV_DOCS" rel="noreferrer noopener nofollow" target="_blank">
|
2021-10-26 20:58:02 +00:00
|
|
|
{{ $t('user.settings.caldav.more') }}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</card>
|
|
|
|
</template>
|
|
|
|
|
2021-12-12 18:01:51 +01:00
|
|
|
<script lang="ts" setup>
|
2021-10-26 20:58:02 +00:00
|
|
|
import copy from 'copy-to-clipboard'
|
2021-12-12 18:28:14 +01:00
|
|
|
import {computed, ref} from 'vue'
|
2021-12-12 18:01:51 +01:00
|
|
|
import {useI18n} from 'vue-i18n'
|
|
|
|
import {useStore} from 'vuex'
|
|
|
|
|
2021-10-26 20:58:02 +00:00
|
|
|
import {CALDAV_DOCS} from '@/urls'
|
2021-12-12 18:01:51 +01:00
|
|
|
import {useTitle} from '@/composables/useTitle'
|
2021-12-12 18:28:14 +01:00
|
|
|
import {success} from '@/message'
|
2021-12-14 21:27:16 +01:00
|
|
|
import Message from '@/components/misc/message.vue'
|
|
|
|
import CaldavTokenService from '@/services/caldavToken'
|
|
|
|
import CaldavTokenModel from '@/models/caldavToken'
|
2021-12-12 18:01:51 +01:00
|
|
|
|
2021-12-14 21:36:42 +01:00
|
|
|
const service = new CaldavTokenService()
|
|
|
|
|
2021-12-20 18:32:32 +01:00
|
|
|
async function useToken(): ref<CaldavTokenModel[]> {
|
2021-12-14 21:36:42 +01:00
|
|
|
const tokens = ref<CaldavTokenModel[]>([])
|
|
|
|
tokens.value = await service.getAll()
|
|
|
|
return tokens
|
|
|
|
}
|
|
|
|
|
|
|
|
const tokens = useToken()
|
|
|
|
|
2021-12-12 18:01:51 +01:00
|
|
|
const store = useStore()
|
|
|
|
const {t} = useI18n()
|
|
|
|
|
|
|
|
useTitle(() => `${t('user.settings.caldav.title')} - ${t('user.settings.title')}`)
|
2021-10-26 20:58:02 +00:00
|
|
|
|
2021-12-12 18:01:51 +01:00
|
|
|
const caldavUrl = computed(() => `${store.getters['config/apiBase']}/dav/principals/${store.state.auth.info.username}/`)
|
|
|
|
const caldavEnabled = computed(() => store.state.config.caldavEnabled)
|
2021-12-12 18:39:17 +01:00
|
|
|
const isLocalUser = computed(() => store.state.auth.info?.isLocalUser)
|
|
|
|
const username = computed(() => store.state.auth.info?.username)
|
2021-12-12 18:28:14 +01:00
|
|
|
|
|
|
|
const newToken = ref(null)
|
2021-12-20 18:39:01 +01:00
|
|
|
|
|
|
|
async function createToken() {
|
2021-12-14 21:31:25 +01:00
|
|
|
const r = await service.create({})
|
|
|
|
tokens.value.push(r)
|
|
|
|
newToken.value = r
|
2021-12-12 18:28:14 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 18:39:01 +01:00
|
|
|
async function deleteToken(token: CaldavTokenModel) {
|
2021-12-14 21:31:25 +01:00
|
|
|
const r = await service.delete(token)
|
|
|
|
const i = tokens.value.findIndex(v => v.id === token.id)
|
2021-12-20 18:32:57 +01:00
|
|
|
if (i === -1) {
|
|
|
|
return
|
|
|
|
}
|
2021-12-14 21:31:25 +01:00
|
|
|
tokens.value.splice(i, 1)
|
2021-12-26 11:30:44 +01:00
|
|
|
success(r)
|
2021-12-12 18:28:14 +01:00
|
|
|
}
|
2021-10-26 20:58:02 +00:00
|
|
|
</script>
|