mirror of
https://github.com/gurucomputing/headscale-ui.git
synced 2026-01-23 02:34:43 +00:00
refactors server settings, fixed sidebar absolute scrolling
This commit is contained in:
parent
d228780283
commit
e0002f7020
8 changed files with 332 additions and 180 deletions
238
package-lock.json
generated
238
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -17,6 +17,7 @@
|
|||
"@sveltejs/adapter-auto": "next",
|
||||
"@sveltejs/adapter-static": "^1.0.0-next.34",
|
||||
"@sveltejs/kit": "next",
|
||||
"@tailwindcss/typography": "github:tailwindcss/typography",
|
||||
"autoprefixer": "^10.4.4",
|
||||
"daisyui": "^2.19.0",
|
||||
"postcss": "^8.4.12",
|
||||
|
|
@ -29,8 +30,5 @@
|
|||
"tailwindcss": "^3.0.23",
|
||||
"typescript": "^4.7.2"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@tailwindcss/typography": "github:tailwindcss/typography"
|
||||
}
|
||||
"type": "module"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,40 +29,41 @@
|
|||
|
||||
<!-- let the page initialize before showing the nav bar -->
|
||||
{#if componentLoaded}
|
||||
<aside class="bg-base-200 shadow-xl w-14" class:navCollapsed={$navExpanded == 'collapsed'} class:navExpanded={$navExpanded == 'expanded'} transition:fade>
|
||||
<!-- sidebar menu items -->
|
||||
<p class="nav-item" on:click={() => ($navExpanded == 'collapsed' ? ($navExpanded = 'expanded') : ($navExpanded = 'collapsed'))}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h7" />
|
||||
</svg>
|
||||
<span class="indent-4 text-primary font-extrabold">Headscale</span>
|
||||
</p>
|
||||
|
||||
<div />
|
||||
<a href="/" class="nav-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
||||
</svg>
|
||||
<span class="indent-4">User View</span>
|
||||
</a>
|
||||
<a href="/devices.html" class="nav-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
||||
</svg>
|
||||
<span class="indent-4">Device View</span>
|
||||
</a>
|
||||
<a href="/settings.html" class="nav-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
|
||||
/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
<span class="indent-4">Settings</span>
|
||||
</a>
|
||||
</aside>
|
||||
<nav class="bg-base-200 flex shadow-xl w-14 h-screen relative" class:navCollapsed={$navExpanded == 'collapsed'} class:navExpanded={$navExpanded == 'expanded'} transition:fade>
|
||||
<!-- links on top of sidebar -->
|
||||
<div class="absolute top-0 w-full">
|
||||
<button class="w-full nav-item" on:click={() => ($navExpanded == 'collapsed' ? ($navExpanded = 'expanded') : ($navExpanded = 'collapsed'))}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h7" />
|
||||
</svg>
|
||||
<span class="indent-4 text-primary font-extrabold">Headscale</span>
|
||||
</button>
|
||||
<div />
|
||||
<a href="/" class="nav-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
||||
</svg>
|
||||
<span class="indent-4">User View</span>
|
||||
</a>
|
||||
<a href="/devices.html" class="nav-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
||||
</svg>
|
||||
<span class="indent-4">Device View</span>
|
||||
</a>
|
||||
<a href="/settings.html" class="nav-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
|
||||
/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
<span class="indent-4">Settings</span>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
{/if}
|
||||
|
||||
<style lang="postcss">
|
||||
|
|
|
|||
84
src/lib/settings/ServerSettings.svelte
Normal file
84
src/lib/settings/ServerSettings.svelte
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<script lang="ts">
|
||||
import { fly } from 'svelte/transition';
|
||||
import { onMount } from 'svelte';
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
|
||||
// Server Settings
|
||||
let headscaleURLStore: Writable<string>;
|
||||
let headscaleURL: string;
|
||||
let headscaleAPIKeyStore: Writable<string>;
|
||||
let headscaleAPIKey: string;
|
||||
let serverSettingsForm: HTMLFormElement;
|
||||
let apiStatus = 'untested';
|
||||
|
||||
async function TestServerSettings() {
|
||||
// using /api/v1/machine until headscale provides an endpoint to test a key against
|
||||
await fetch(headscaleURL + '/api/v1/machine', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${headscaleAPIKey}`
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
apiStatus = 'succeeded';
|
||||
})
|
||||
.catch((error) => {
|
||||
apiStatus = 'failed';
|
||||
});
|
||||
}
|
||||
|
||||
function SaveServerSettings(): void {
|
||||
if (serverSettingsForm.reportValidity()) {
|
||||
$headscaleURLStore = headscaleURL;
|
||||
$headscaleAPIKeyStore = headscaleAPIKey;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
// get the current URL and APIKey state from the local store
|
||||
headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
|
||||
|
||||
// set the current subscription values to the initial value
|
||||
headscaleURLStore = writable(headscaleURL);
|
||||
headscaleAPIKeyStore = writable(headscaleAPIKey);
|
||||
|
||||
// subscribe to the URL and APIKey state and update the local storage where needed
|
||||
headscaleURLStore.subscribe((val) => localStorage.setItem('headscaleURL', val));
|
||||
headscaleAPIKeyStore.subscribe((val) => localStorage.setItem('headscaleAPIKey', val));
|
||||
});
|
||||
|
||||
function ClearServerSettings() {
|
||||
headscaleURL = '';
|
||||
headscaleAPIKey = '';
|
||||
$headscaleURLStore = headscaleURL;
|
||||
$headscaleAPIKeyStore = headscaleAPIKey;
|
||||
}
|
||||
</script>
|
||||
|
||||
<form bind:this={serverSettingsForm}>
|
||||
<h1 class="text-2xl bold text-primary mb-4">Server Settings</h1>
|
||||
<label class="block text-secondary text-sm font-bold mb-2" for="url"> Headscale URL </label>
|
||||
<input bind:value={headscaleURL} class="form-input" type="url" required pattern={String.raw`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`} placeholder="https://hs.yourdomain.com.au" />
|
||||
<p class="text-xs text-base-content text-italics mb-8">URL for your headscale server instance</p>
|
||||
<label class="block text-secondary text-sm font-bold mb-2" for="password"> Headscale API Key </label>
|
||||
<input bind:value={headscaleAPIKey} minlength="54" maxlength="54" class="form-input" type="password" required placeholder="******************" />
|
||||
<p class="text-xs text-base-content text-italics mb-8">Generate an API key for your headscale instance and place it here.</p>
|
||||
<!-- disable the SaveServerSettings button if nothing has changed from stored values, or the dependent inputs do not validate -->
|
||||
<div class="tooltip" data-tip="Note: API Key and URL currently save to localStorage (IE: Your Browser) Make sure you are using a trusted computer">
|
||||
<button disabled={headscaleAPIKey === $headscaleAPIKeyStore && headscaleURL === $headscaleURLStore} on:click={() => SaveServerSettings()} class="btn btn-sm btn-accent capitalize" type="button">Save Server Settings</button>
|
||||
</div>
|
||||
<button on:click={() => ClearServerSettings()} class="btn btn-sm btn-primary capitalize" type="button">Clear Server Settings</button>
|
||||
<button on:click={() => TestServerSettings()} class="btn btn-sm btn-secondary capitalize" type="button">Test Server Settings</button>
|
||||
{#if apiStatus === 'succeeded'}
|
||||
<svg in:fly={{ x: 10, duration: 600 }} xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 inline" fill="none" viewBox="0 0 24 24" stroke="green" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{/if}
|
||||
{#if apiStatus === 'failed'}
|
||||
<svg in:fly={{ x: 10, duration: 600 }} xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 inline" fill="none" viewBox="0 0 24 24" stroke="red" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
{/if}
|
||||
</form>
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
import Alert from '$lib/common/Alert.svelte'
|
||||
</script>
|
||||
|
||||
<main class="flex flex-col" data-theme="light">
|
||||
<div class="flex min-h-screen overflow-hidden">
|
||||
<main class="flex flex-col" data-theme="hsui">
|
||||
<div class="flex h-screen overflow-hidden">
|
||||
<!-- sidebar -->
|
||||
<Nav />
|
||||
<!-- main window -->
|
||||
<div class="flex flex-1 flex-col bg-base-100">
|
||||
<div class="flex flex-1 min-w-0 overflow-auto flex-col bg-base-100">
|
||||
<Alert></Alert>
|
||||
<!-- header -->
|
||||
<!-- <div class="flex bg-gray-100 h-12 p-4">Header</div> -->
|
||||
|
|
|
|||
|
|
@ -71,4 +71,4 @@
|
|||
<p>API test did not succeed.<br />Headscale might be down or API settings may need to be set<br />change server settings in the <a href="/settings.html" class="hyperlink">settings</a> page</p>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
|
|
@ -2,71 +2,14 @@
|
|||
//
|
||||
// Imports
|
||||
//
|
||||
import ServerSettings from '$lib/settings/ServerSettings.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
import { fade, fly } from 'svelte/transition';
|
||||
import { TestAPI } from '$lib/common/functions.svelte';
|
||||
|
||||
//
|
||||
// Variable Declarations
|
||||
//
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
// Set to true once component is initialized
|
||||
let componentLoaded = false;
|
||||
|
||||
// Server Settings
|
||||
let headscaleURLStore: Writable<string>;
|
||||
let headscaleURL: string;
|
||||
let headscaleAPIKeyStore: Writable<string>;
|
||||
let headscaleAPIKey: string;
|
||||
let headscaleAPITest = 'untested';
|
||||
let serverSettingsForm: HTMLFormElement;
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
|
||||
// Server Settings
|
||||
function SaveServerSettings(): void {
|
||||
if (serverSettingsForm.reportValidity()) {
|
||||
$headscaleURLStore = headscaleURL;
|
||||
$headscaleAPIKeyStore = headscaleAPIKey;
|
||||
}
|
||||
}
|
||||
|
||||
function ClearServerSettings(): void {
|
||||
headscaleURL = '';
|
||||
headscaleAPIKey = '';
|
||||
$headscaleURLStore = headscaleURL;
|
||||
$headscaleAPIKeyStore = headscaleAPIKey;
|
||||
}
|
||||
|
||||
function TestServerSettings(): void {
|
||||
TestAPI().then((succeeded: boolean) => {
|
||||
if (succeeded === true) {
|
||||
headscaleAPITest = 'succeeded';
|
||||
} else {
|
||||
headscaleAPITest = 'failed';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Component Initialization
|
||||
//
|
||||
|
||||
onMount(async () => {
|
||||
// get the current URL and APIKey state from the local store
|
||||
headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
|
||||
|
||||
// set the current subscription values to the initial value
|
||||
headscaleURLStore = writable(headscaleURL);
|
||||
headscaleAPIKeyStore = writable(headscaleAPIKey);
|
||||
|
||||
// subscribe to the URL and APIKey state and update the local storage where needed
|
||||
headscaleURLStore.subscribe((val) => localStorage.setItem('headscaleURL', val));
|
||||
headscaleAPIKeyStore.subscribe((val) => localStorage.setItem('headscaleAPIKey', val));
|
||||
|
||||
// Display component frontend
|
||||
componentLoaded = true;
|
||||
});
|
||||
|
|
@ -77,31 +20,7 @@
|
|||
{#if componentLoaded}
|
||||
<div in:fade class="px-4 py-4 w-4/5">
|
||||
<!-- Server Settings -->
|
||||
<form bind:this={serverSettingsForm}>
|
||||
<h1 class="text-2xl bold text-primary mb-4">Server Settings</h1>
|
||||
<label class="block text-secondary text-sm font-bold mb-2" for="url"> Headscale URL </label>
|
||||
<input bind:value={headscaleURL} class="form-input" type="url" required pattern={String.raw`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`} placeholder="https://hs.yourdomain.com.au" />
|
||||
<p class="text-xs text-base-content text-italics mb-8">URL for your headscale server instance</p>
|
||||
<label class="block text-secondary text-sm font-bold mb-2" for="password"> Headscale API Key </label>
|
||||
<input bind:value={headscaleAPIKey} minlength="54" maxlength="54" class="form-input" type="password" required placeholder="******************" />
|
||||
<p class="text-xs text-base-content text-italics mb-8">Generate an API key for your headscale instance and place it here.</p>
|
||||
<!-- disable the SaveServerSettings button if nothing has changed from stored values, or the dependent inputs do not validate -->
|
||||
<div class="tooltip" data-tip="Note: API Key and URL currently save to localStorage (IE: Your Browser) Make sure you are using a trusted computer">
|
||||
<button disabled={headscaleAPIKey === $headscaleAPIKeyStore && headscaleURL === $headscaleURLStore} on:click={() => SaveServerSettings()} class="btn btn-sm btn-accent capitalize" type="button">Save Server Settings</button>
|
||||
</div>
|
||||
<button on:click={() => ClearServerSettings()} class="btn btn-sm btn-primary capitalize" type="button">Clear Server Settings</button>
|
||||
<button on:click={() => TestServerSettings()} class="btn btn-sm btn-secondary capitalize" type="button">Test Server Settings</button>
|
||||
{#if headscaleAPITest === 'succeeded'}
|
||||
<svg in:fly={{ x: 10, duration: 600 }} xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 inline" fill="none" viewBox="0 0 24 24" stroke="green" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{/if}
|
||||
{#if headscaleAPITest === 'failed'}
|
||||
<svg in:fly={{ x: 10, duration: 600 }} xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 inline" fill="none" viewBox="0 0 24 24" stroke="red" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
{/if}
|
||||
</form>
|
||||
<ServerSettings />
|
||||
<!-- Server Settings End -->
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,24 @@ const config = {
|
|||
extend: {}
|
||||
},
|
||||
|
||||
daisyui: {
|
||||
themes: [
|
||||
{
|
||||
hsui: {
|
||||
"primary": "#065f46",
|
||||
"secondary": "#0369a1",
|
||||
"accent": "#6b21a8",
|
||||
"neutral": "#78716c",
|
||||
"base-100": "#FFFFFF",
|
||||
"info": "#3ABFF8",
|
||||
"success": "#36D399",
|
||||
"warning": "#FBBD23",
|
||||
"error": "#F87272",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
plugins: [require("@tailwindcss/typography"), require("daisyui")]
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue