forked from vhaudiquet/rhema-together
feat: open provider and sandbox forms in dialogs
This commit is contained in:
1 parent
bd3aed67b4
commit
5237a477d7
1 file changed
+58
-15
+58
-15
@@ -13,8 +13,9 @@ import type {
|
|||||||
TestSandboxResponse,
|
TestSandboxResponse,
|
||||||
} from '~/types'
|
} from '~/types'
|
||||||
import { apiErrorMessage } from '~/utils/errors'
|
import { apiErrorMessage } from '~/utils/errors'
|
||||||
|
import BaseDialog from '~/components/BaseDialog.vue'
|
||||||
|
|
||||||
useHead({ title: 'Settings · rhema together' })
|
useHead({ title: 'Settings · Rhema Together' })
|
||||||
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ const deletingTarget = ref<string | null>(null)
|
|||||||
const deleteBusy = ref(false)
|
const deleteBusy = ref(false)
|
||||||
const rowError = ref('')
|
const rowError = ref('')
|
||||||
|
|
||||||
|
const providerDialog = ref(false)
|
||||||
|
const sandboxDialog = ref(false)
|
||||||
const testingTarget = ref<string | null>(null)
|
const testingTarget = ref<string | null>(null)
|
||||||
const testResults = ref<Record<string, TestSandboxResponse>>({})
|
const testResults = ref<Record<string, TestSandboxResponse>>({})
|
||||||
const copiedKey = ref<string | null>(null)
|
const copiedKey = ref<string | null>(null)
|
||||||
@@ -71,6 +74,28 @@ async function loadLists() {
|
|||||||
|
|
||||||
onMounted(loadLists)
|
onMounted(loadLists)
|
||||||
|
|
||||||
|
function openProviderDialog() {
|
||||||
|
providerError.value = ''
|
||||||
|
providerDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeProviderDialog() {
|
||||||
|
providerDialog.value = false
|
||||||
|
providerKey.value = ''
|
||||||
|
providerError.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function openSandboxDialog() {
|
||||||
|
sandboxError.value = ''
|
||||||
|
sandboxDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeSandboxDialog() {
|
||||||
|
sandboxDialog.value = false
|
||||||
|
sandboxKey.value = ''
|
||||||
|
sandboxError.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
async function addProvider() {
|
async function addProvider() {
|
||||||
if (providerBusy.value) return
|
if (providerBusy.value) return
|
||||||
providerBusy.value = true
|
providerBusy.value = true
|
||||||
@@ -89,6 +114,7 @@ async function addProvider() {
|
|||||||
providerBaseUrl.value = ''
|
providerBaseUrl.value = ''
|
||||||
providerKey.value = ''
|
providerKey.value = ''
|
||||||
await loadLists()
|
await loadLists()
|
||||||
|
providerDialog.value = false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
providerError.value = apiErrorMessage(err)
|
providerError.value = apiErrorMessage(err)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -117,6 +143,7 @@ async function addSandbox() {
|
|||||||
sandboxRoot.value = '/root'
|
sandboxRoot.value = '/root'
|
||||||
sandboxKey.value = ''
|
sandboxKey.value = ''
|
||||||
await loadLists()
|
await loadLists()
|
||||||
|
sandboxDialog.value = false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
sandboxError.value = apiErrorMessage(err)
|
sandboxError.value = apiErrorMessage(err)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -193,10 +220,14 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="section-head">
|
<div class="section-head">
|
||||||
<h2 class="section-title">Providers</h2>
|
<h2 class="section-title">Providers</h2>
|
||||||
|
<button type="button" class="btn btn-sm" @click="openProviderDialog">
|
||||||
|
<Plus :size="14" aria-hidden="true" />
|
||||||
|
Add provider
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">A provider holds the model backend and key. Rooms spend from the provider their owner picks.</p>
|
<p class="hint">A provider holds the model backend and key. Rooms spend from the provider their owner picks.</p>
|
||||||
|
|
||||||
<div v-if="!loading && providers.length === 0" class="empty">No providers yet. Add one below.</div>
|
<div v-if="!loading && providers.length === 0" class="empty">No providers yet. Use Add provider to connect one.</div>
|
||||||
|
|
||||||
<div v-else class="list">
|
<div v-else class="list">
|
||||||
<div v-for="provider in providers" :key="provider.id" class="settings-row">
|
<div v-for="provider in providers" :key="provider.id" class="settings-row">
|
||||||
@@ -233,13 +264,17 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-panel">
|
<BaseDialog
|
||||||
<h3 class="panel-title">Add provider</h3>
|
v-if="providerDialog"
|
||||||
|
title="Add provider"
|
||||||
|
description="The key stays sealed on the server and is never shown again."
|
||||||
|
@close="closeProviderDialog"
|
||||||
|
>
|
||||||
<form class="form" @submit.prevent="addProvider">
|
<form class="form" @submit.prevent="addProvider">
|
||||||
<div class="form-grid">
|
<div class="form-grid">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="provider-name">Name</label>
|
<label class="field-label" for="provider-name">Name</label>
|
||||||
<input id="provider-name" v-model="providerName" class="input" type="text" maxlength="60" required>
|
<input id="provider-name" v-model="providerName" class="input" type="text" maxlength="60" autofocus required>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="provider-kind">Kind</label>
|
<label class="field-label" for="provider-kind">Kind</label>
|
||||||
@@ -287,23 +322,27 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
|
|
||||||
<p v-if="providerError" class="form-error" role="alert">{{ providerError }}</p>
|
<p v-if="providerError" class="form-error" role="alert">{{ providerError }}</p>
|
||||||
|
|
||||||
<div>
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn" :disabled="providerBusy" @click="closeProviderDialog">Cancel</button>
|
||||||
<button type="submit" class="btn btn-primary" :disabled="providerBusy">
|
<button type="submit" class="btn btn-primary" :disabled="providerBusy">
|
||||||
<Plus :size="16" aria-hidden="true" />
|
|
||||||
{{ providerBusy ? 'Adding' : 'Add provider' }}
|
{{ providerBusy ? 'Adding' : 'Add provider' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</BaseDialog>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="section-head">
|
<div class="section-head">
|
||||||
<h2 class="section-title">Sandboxes</h2>
|
<h2 class="section-title">Sandboxes</h2>
|
||||||
|
<button type="button" class="btn btn-sm" @click="openSandboxDialog">
|
||||||
|
<Plus :size="14" aria-hidden="true" />
|
||||||
|
Add sandbox
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">A sandbox is an ssh machine the room works on. The public key belongs in its authorized_keys file.</p>
|
<p class="hint">A sandbox is an ssh machine the room works on. The public key belongs in its authorized_keys file.</p>
|
||||||
|
|
||||||
<div v-if="!loading && targets.length === 0" class="empty">No sandboxes yet. Add one below.</div>
|
<div v-if="!loading && targets.length === 0" class="empty">No sandboxes yet. Use Add sandbox to connect one.</div>
|
||||||
|
|
||||||
<div v-else class="list">
|
<div v-else class="list">
|
||||||
<div v-for="target in targets" :key="target.id" class="settings-row">
|
<div v-for="target in targets" :key="target.id" class="settings-row">
|
||||||
@@ -366,13 +405,17 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-panel">
|
<BaseDialog
|
||||||
<h3 class="panel-title">Add sandbox</h3>
|
v-if="sandboxDialog"
|
||||||
|
title="Add sandbox"
|
||||||
|
description="The room runs commands on this machine with the matching private key."
|
||||||
|
@close="closeSandboxDialog"
|
||||||
|
>
|
||||||
<form class="form" @submit.prevent="addSandbox">
|
<form class="form" @submit.prevent="addSandbox">
|
||||||
<div class="form-grid">
|
<div class="form-grid">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="sandbox-name">Name</label>
|
<label class="field-label" for="sandbox-name">Name</label>
|
||||||
<input id="sandbox-name" v-model="sandboxName" class="input" type="text" maxlength="60" required>
|
<input id="sandbox-name" v-model="sandboxName" class="input" type="text" maxlength="60" autofocus required>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="sandbox-host">Host</label>
|
<label class="field-label" for="sandbox-host">Host</label>
|
||||||
@@ -411,14 +454,14 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
|
|
||||||
<p v-if="sandboxError" class="form-error" role="alert">{{ sandboxError }}</p>
|
<p v-if="sandboxError" class="form-error" role="alert">{{ sandboxError }}</p>
|
||||||
|
|
||||||
<div>
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn" :disabled="sandboxBusy" @click="closeSandboxDialog">Cancel</button>
|
||||||
<button type="submit" class="btn btn-primary" :disabled="sandboxBusy">
|
<button type="submit" class="btn btn-primary" :disabled="sandboxBusy">
|
||||||
<Plus :size="16" aria-hidden="true" />
|
|
||||||
{{ sandboxBusy ? 'Adding' : 'Add sandbox' }}
|
{{ sandboxBusy ? 'Adding' : 'Add sandbox' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</BaseDialog>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
Reference in new issue
Block a user