56eaf57649
- Fix modal scroll: restructure overlay with scroll/centering wrapper - Add SSH key textarea + file upload to host modal (authType='key') - Fix textarea reset on new host (clear via DOM) - SSH username placeholder instead of default 'root' - Nav uses plain <a href> instead of HTMX for full-page navigation - /hosts route returns full page; /hosts/list for HTMX partials - Remove OS and Provider from host modal, grid card, and list card - Fix key modal x-data scope for Alpine $dispatch - Update key_grid to display multi-line key content properly - Simplify SSH key placeholder format
181 lines
12 KiB
HTML
181 lines
12 KiB
HTML
{{define "host_modal"}}
|
|
<div id="host-modal" class="fixed inset-0 z-50" x-data="hostForm()" x-show="open" x-cloak
|
|
@open-modal.window="reset(); open = true"
|
|
@edit-host.window="populate($event.detail); open = true"
|
|
@keydown.escape.window="open = false">
|
|
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm" @click="open = false"></div>
|
|
<div class="absolute inset-0 overflow-y-auto p-4" x-show="open" x-transition>
|
|
<div class="flex min-h-full items-center justify-center">
|
|
<div class="bg-white rounded-2xl max-w-lg w-full border border-outline-variant/30 shadow-2xl max-h-[90vh] overflow-y-auto">
|
|
|
|
<div class="flex justify-between items-center border-b border-outline-variant/30 p-6 pb-4">
|
|
<h3 class="font-bold text-lg text-on-surface" x-text="editing ? 'Edit Host' : 'Add Host'"></h3>
|
|
<button @click="open = false"
|
|
class="text-outline hover:text-primary cursor-pointer p-1 rounded-lg">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
|
|
</button>
|
|
</div>
|
|
|
|
<form hx-post="/hosts"
|
|
hx-target="#host-list" hx-swap="innerHTML"
|
|
@submit="open = false; $dispatch('toast-message', { message: editing ? 'Host updated' : 'Host added' })"
|
|
class="p-6 space-y-4 text-sm">
|
|
<input type="hidden" name="hostId" :value="editing ? hostId : ''">
|
|
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">Host Identifier</label>
|
|
<input type="text" name="name" x-model="form.name" required placeholder="e.g. prod-db-replica"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-medium text-on-surface">
|
|
</div>
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">IP Address / Domain</label>
|
|
<input type="text" name="ip" x-model="form.ip" required placeholder="e.g. 10.0.12.19"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">Hostname (SSH)</label>
|
|
<input type="text" name="hostname" x-model="form.hostname" placeholder="e.g. prod.example.com"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs">
|
|
</div>
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">SSH Port</label>
|
|
<input type="number" name="port" x-model="form.port" min="1" max="65535" placeholder="22"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">SSH Username</label>
|
|
<input type="text" name="username" x-model="form.username" placeholder="root"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-medium text-on-surface">
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">Host Purpose / Type</label>
|
|
<div class="grid grid-cols-3 gap-2">
|
|
<button type="button" @click="form.type = 'api'"
|
|
:class="form.type === 'api' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
|
|
class="py-2.5 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all">API Node</button>
|
|
<button type="button" @click="form.type = 'db'"
|
|
:class="form.type === 'db' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
|
|
class="py-2.5 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all">DB Node</button>
|
|
<button type="button" @click="form.type = 'web'"
|
|
:class="form.type === 'web' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
|
|
class="py-2.5 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all">Web Node</button>
|
|
</div>
|
|
<input type="hidden" name="type" :value="form.type">
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">Authentication</label>
|
|
<div class="grid grid-cols-2 gap-2">
|
|
<button type="button" @click="form.authType = 'key'"
|
|
:class="form.authType === 'key' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
|
|
class="py-2 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all flex items-center justify-center gap-1.5">
|
|
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.75 5.25a3 3 0 013 3m3 0a6 6 0 01-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1121.75 8.25z"/></svg>
|
|
SSH Key
|
|
</button>
|
|
<button type="button" @click="form.authType = 'password'"
|
|
:class="form.authType === 'password' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
|
|
class="py-2 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all flex items-center justify-center gap-1.5">
|
|
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16.5 10.5V6.75a4.5 4.5 0 10-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H6.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z"/></svg>
|
|
Password
|
|
</button>
|
|
</div>
|
|
<input type="hidden" name="authType" :value="form.authType">
|
|
</div>
|
|
|
|
<div x-show="form.authType === 'key'" x-cloak class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">SSH Private Key</label>
|
|
<textarea name="password" rows="5" placeholder="Paste your SSH private key here... -----BEGIN OPENSSH PRIVATE KEY----- ... -----END OPENSSH PRIVATE KEY-----"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs resize-none leading-relaxed"></textarea>
|
|
<div class="flex items-center gap-3 mt-1">
|
|
<label class="flex items-center gap-1.5 text-xs text-on-surface-variant cursor-pointer hover:text-primary transition-colors">
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/></svg>
|
|
Or upload a key file
|
|
</label>
|
|
<input type="file" class="hidden" accept=".pem,.key,.pub,.txt,.ppk" @change="readKeyFile($event)">
|
|
<span class="text-[10px] text-outline">.pem .key .ppk</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div x-show="form.authType === 'password'" x-cloak class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">Password</label>
|
|
<input type="password" name="password" x-model="form.password" placeholder="SSH password"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs">
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-1.5">
|
|
<label class="text-xs font-bold text-on-surface-variant uppercase">Notes</label>
|
|
<textarea name="notes" x-model="form.notes" rows="2" placeholder="Optional notes about this host"
|
|
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all text-xs resize-none"></textarea>
|
|
</div>
|
|
|
|
<div class="pt-4 flex justify-end gap-3 border-t border-outline-variant/20">
|
|
<button type="button" @click="open = false"
|
|
class="px-4 py-2 text-xs font-bold text-outline hover:text-on-surface transition-colors">Cancel</button>
|
|
<button type="submit"
|
|
class="bg-primary text-white py-2 px-5 rounded-lg font-bold text-xs shadow-md hover:bg-primary-container hover:text-on-primary-container transition-all"
|
|
x-text="editing ? 'Save Changes' : 'Add Host'"></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function hostForm() {
|
|
return {
|
|
open: false,
|
|
editing: false,
|
|
hostId: '',
|
|
form: {
|
|
name: '', ip: '', hostname: '', port: '22', username: '',
|
|
type: 'api', authType: 'key', password: '', notes: ''
|
|
},
|
|
reset() {
|
|
this.editing = false;
|
|
this.hostId = '';
|
|
this.form = {
|
|
name: '', ip: '', hostname: '', port: '22', username: '',
|
|
type: 'api', authType: 'key', password: '', notes: ''
|
|
};
|
|
var ta = document.querySelector('#host-modal textarea[name=password]');
|
|
if (ta) ta.value = '';
|
|
},
|
|
populate(host) {
|
|
this.editing = true;
|
|
this.hostId = host.ID;
|
|
this.form = {
|
|
name: host.Name || '',
|
|
ip: host.IP || '',
|
|
hostname: host.Hostname || '',
|
|
port: String(host.Port || 22),
|
|
username: host.Username || 'root',
|
|
type: host.Type || 'api',
|
|
authType: host.AuthType || 'key',
|
|
password: host.Password || '',
|
|
notes: host.Notes || ''
|
|
};
|
|
var ta = document.querySelector('#host-modal textarea[name=password]');
|
|
if (ta) ta.value = host.Password || '';
|
|
},
|
|
readKeyFile($event) {
|
|
var file = $event.target.files[0];
|
|
if (!file) return;
|
|
var reader = new FileReader();
|
|
var ta = document.querySelector('#host-modal textarea[name=password]');
|
|
reader.onload = function(e) {
|
|
if (ta) ta.value = e.target.result;
|
|
};
|
|
reader.readAsText(file);
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
{{end}} |