init
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
import {computed, ref} from 'vue'
|
||||
import {useConfigStore} from '@/stores/config'
|
||||
import {useRouter} from 'vue-router'
|
||||
|
||||
const props = defineProps<{
|
||||
open?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['update:open'])
|
||||
|
||||
const configStore = useConfigStore()
|
||||
const router = useRouter()
|
||||
|
||||
const serverAddress = ref('')
|
||||
const selectedIdentity = ref('')
|
||||
|
||||
const identitiesOptions = computed(() => {
|
||||
if (!configStore.config) return []
|
||||
return configStore.config.identities.map(i => ({
|
||||
label: i.username || i.id,
|
||||
value: i.id
|
||||
}))
|
||||
})
|
||||
|
||||
async function joinServer() {
|
||||
if (!serverAddress.value || !selectedIdentity.value) return
|
||||
|
||||
if (configStore.config) {
|
||||
configStore.config.servers.push({
|
||||
adresse: serverAddress.value,
|
||||
identity: selectedIdentity.value
|
||||
})
|
||||
await configStore.saveConfig()
|
||||
|
||||
emit('update:open', false)
|
||||
router.push('/config/servers')
|
||||
}
|
||||
}
|
||||
|
||||
const isOpen = computed({
|
||||
get: () => !!props.open,
|
||||
set: (val) => emit('update:open', val)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UModal
|
||||
v-model:open="isOpen"
|
||||
title="Joindre un nouveau serveur"
|
||||
description="Entrez l'adresse d'un serveur et choisissez une identité pour vous connecter."
|
||||
>
|
||||
<!-- <template #header>-->
|
||||
<!-- <div class="p-4">-->
|
||||
<!-- <h3 class="text-xl font-bold">Joindre un nouveau serveur</h3>-->
|
||||
<!-- <p class="text-gray-500 text-sm">Entrez l'adresse d'un serveur et choisissez une identité pour vous-->
|
||||
<!-- connecter.</p>-->
|
||||
<!-- </div>-->
|
||||
<!-- </template>-->
|
||||
|
||||
<template #body>
|
||||
<div class="space-y-4 px-4 pb-4">
|
||||
<UFormField label="Adresse du serveur (IP:Port)">
|
||||
<UInput
|
||||
v-model="serverAddress"
|
||||
placeholder="ex: 127.0.0.1:50051"
|
||||
icon="i-lucide-server"
|
||||
class="w-full"
|
||||
/>
|
||||
</UFormField>
|
||||
|
||||
<UFormField label="Identité à utiliser">
|
||||
<USelect
|
||||
v-model="selectedIdentity"
|
||||
:items="identitiesOptions"
|
||||
placeholder="Sélectionner une identité"
|
||||
icon="i-lucide-user"
|
||||
class="w-full"
|
||||
/>
|
||||
</UFormField>
|
||||
|
||||
<p v-if="identitiesOptions.length === 0" class="text-xs text-red-500">
|
||||
Vous devez d'abord créer une identité dans la configuration.
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end gap-3 w-full px-4 py-3">
|
||||
<UButton
|
||||
color="neutral"
|
||||
variant="ghost"
|
||||
label="Annuler"
|
||||
@click="isOpen = false"
|
||||
/>
|
||||
<UButton
|
||||
label="Joindre"
|
||||
:disabled="!serverAddress || !selectedIdentity"
|
||||
@click="joinServer"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</UModal>
|
||||
</template>
|
||||
Reference in New Issue
Block a user