|
| 1 | +<!-- |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<script setup lang="ts"> |
| 7 | +import type { ITrustedServer } from '../services/api.ts' |
| 8 | +
|
| 9 | +import { mdiCheckNetworkOutline, mdiCloseNetworkOutline, mdiHelpNetworkOutline, mdiTrashCanOutline } from '@mdi/js' |
| 10 | +import { showError } from '@nextcloud/dialogs' |
| 11 | +import { t } from '@nextcloud/l10n' |
| 12 | +import { computed, ref } from 'vue' |
| 13 | +import NcButton from '@nextcloud/vue/components/NcButton' |
| 14 | +import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper' |
| 15 | +import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon' |
| 16 | +import { TrustedServerStatus } from '../services/api.ts' |
| 17 | +import { deleteServer } from '../services/api.ts' |
| 18 | +import { logger } from '../services/logger.ts' |
| 19 | +
|
| 20 | +const props = defineProps<{ |
| 21 | + server: ITrustedServer |
| 22 | +}>() |
| 23 | +
|
| 24 | +const emit = defineEmits<{ |
| 25 | + delete: [ITrustedServer] |
| 26 | +}>() |
| 27 | +
|
| 28 | +const isLoading = ref(false) |
| 29 | +
|
| 30 | +const hasError = computed(() => props.server.status === TrustedServerStatus.STATUS_FAILURE) |
| 31 | +const serverIcon = computed(() => { |
| 32 | + switch (props.server.status) { |
| 33 | + case TrustedServerStatus.STATUS_OK: |
| 34 | + return mdiCheckNetworkOutline |
| 35 | + case TrustedServerStatus.STATUS_PENDING: |
| 36 | + case TrustedServerStatus.STATUS_ACCESS_REVOKED: |
| 37 | + return mdiHelpNetworkOutline |
| 38 | + case TrustedServerStatus.STATUS_FAILURE: |
| 39 | + default: |
| 40 | + return mdiCloseNetworkOutline |
| 41 | + } |
| 42 | +}) |
| 43 | +
|
| 44 | +const serverStatus = computed(() => { |
| 45 | + switch (props.server.status) { |
| 46 | + case TrustedServerStatus.STATUS_OK: |
| 47 | + return [t('federation', 'Server ok'), t('federation', 'User list was exchanged at least once successfully with the remote server.')] |
| 48 | + case TrustedServerStatus.STATUS_PENDING: |
| 49 | + return [t('federation', 'Server pending'), t('federation', 'Waiting for shared secret or initial user list exchange.')] |
| 50 | + case TrustedServerStatus.STATUS_ACCESS_REVOKED: |
| 51 | + return [t('federation', 'Server access revoked'), t('federation', 'Server access revoked')] |
| 52 | + case TrustedServerStatus.STATUS_FAILURE: |
| 53 | + default: |
| 54 | + return [t('federation', 'Server failure'), t('federation', 'Connection to the remote server failed or the remote server is misconfigured.')] |
| 55 | + } |
| 56 | +}) |
| 57 | +
|
| 58 | +/** |
| 59 | + * Emit delete event |
| 60 | + */ |
| 61 | +async function onDelete() { |
| 62 | + try { |
| 63 | + isLoading.value = true |
| 64 | + await deleteServer(props.server.id) |
| 65 | + emit('delete', props.server) |
| 66 | + } catch (error) { |
| 67 | + isLoading.value = false |
| 68 | + logger.error('Failed to delete trusted server', { error }) |
| 69 | + showError(t('federation', 'Failed to delete trusted server. Please try again later.')) |
| 70 | + } |
| 71 | +} |
| 72 | +</script> |
| 73 | + |
| 74 | +<template> |
| 75 | + <li :class="$style.trustedServer"> |
| 76 | + <NcIconSvgWrapper |
| 77 | + :class="{ |
| 78 | + [$style.trustedServer__icon_error]: hasError, |
| 79 | + }" |
| 80 | + :path="serverIcon" |
| 81 | + :name="serverStatus[0]" |
| 82 | + :title="serverStatus[1]" /> |
| 83 | + |
| 84 | + <code :class="$style.trustedServer__url" v-text="server.url" /> |
| 85 | + |
| 86 | + <NcButton |
| 87 | + :aria-label="t('federation', 'Delete')" |
| 88 | + :title="t('federation', 'Delete')" |
| 89 | + :disabled="isLoading" |
| 90 | + @click="onDelete"> |
| 91 | + <template #icon> |
| 92 | + <NcLoadingIcon v-if="isLoading" /> |
| 93 | + <NcIconSvgWrapper v-else :path="mdiTrashCanOutline" /> |
| 94 | + </template> |
| 95 | + </NcButton> |
| 96 | + </li> |
| 97 | +</template> |
| 98 | + |
| 99 | +<style module> |
| 100 | +.trustedServer { |
| 101 | + display: flex; |
| 102 | + flex-direction: row; |
| 103 | + gap: var(--default-grid-baseline); |
| 104 | + align-items: center; |
| 105 | + border-radius: var(--border-radius-element); |
| 106 | + padding-inline-start: var(--default-grid-baseline); |
| 107 | +} |
| 108 | +
|
| 109 | +.trustedServer:hover { |
| 110 | + background-color: var(--color-background-hover); |
| 111 | +} |
| 112 | +
|
| 113 | +.trustedServer__icon_error { |
| 114 | + color: var(--color-element-error); |
| 115 | +} |
| 116 | +
|
| 117 | +.trustedServer__url { |
| 118 | + padding-inline: 1ch; |
| 119 | + flex: 1 0 auto; |
| 120 | +} |
| 121 | +</style> |
0 commit comments