mirror of
https://github.com/gurucomputing/headscale-ui.git
synced 2026-07-26 09:24:02 +00:00
added persistence for preauthkey hide preference
This commit is contained in:
parent
5491fc3b1b
commit
53df2ab7bc
4 changed files with 12 additions and 6 deletions
|
|
@ -3,6 +3,7 @@
|
|||
import { headscaleThemeStore } from '$lib/common/stores.js';
|
||||
import { headscaleURLStore } from '$lib/common/stores.js';
|
||||
import { headscaleAPIKeyStore } from '$lib/common/stores.js';
|
||||
import { preAuthHideStore } from '$lib/common/stores.js';
|
||||
|
||||
onMount(async () => {
|
||||
// stores headscale theme
|
||||
|
|
@ -12,8 +13,11 @@
|
|||
headscaleURLStore.set(localStorage.getItem('headscaleURL') || '');
|
||||
headscaleAPIKeyStore.set(localStorage.getItem('headscaleAPIKey') || '');
|
||||
|
||||
preAuthHideStore.set(localStorage.getItem('headscalePreAuthHide') || 'false');
|
||||
|
||||
// subscribe to store's state and update the local storage where needed
|
||||
headscaleThemeStore.subscribe((val) => localStorage.setItem('headscaleTheme', val));
|
||||
preAuthHideStore.subscribe((val) => localStorage.setItem('headscalePreAuthHide', val));
|
||||
|
||||
headscaleURLStore.subscribe((val) => localStorage.setItem('headscaleURL', val));
|
||||
headscaleAPIKeyStore.subscribe((val) => localStorage.setItem('headscaleAPIKey', val));
|
||||
|
|
|
|||
|
|
@ -203,7 +203,6 @@
|
|||
|
||||
await headscalePreAuthKeyResponse.json().then((data) => {
|
||||
headscalePreAuthKey = data.preAuthKeys;
|
||||
console.log(headscalePreAuthKey);
|
||||
});
|
||||
return headscalePreAuthKey;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ export const headscaleThemeStore = writable('');
|
|||
// stores URL and API Key
|
||||
export const headscaleURLStore = writable('');
|
||||
export const headscaleAPIKeyStore = writable('');
|
||||
// stores preauth key preference
|
||||
export const preAuthHideStore = writable('');
|
||||
// stores user and device data
|
||||
export const headscaleUserStore = writable([new User()]);
|
||||
export const headscaleDeviceStore = writable([new Device()]);
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
<script lang="ts">
|
||||
import { getPreauthKeys } from '$lib/common/apiFunctions.svelte';
|
||||
import { PreAuthKey, User } from '$lib/common/classes';
|
||||
import { alertStore } from '$lib/common/stores';
|
||||
import { alertStore, preAuthHideStore } from '$lib/common/stores';
|
||||
|
||||
// function for refreshing users from parent
|
||||
export let user = new User();
|
||||
let keyList = [new PreAuthKey()];
|
||||
let hideExpired = false;
|
||||
let preAuthHide = ($preAuthHideStore == 'true');
|
||||
|
||||
// If the key hasn't expired or key hasn't been used, flag as green, otherwise flag as red
|
||||
function testExpiry(keyExpiry: string, keyUsed: boolean): string {
|
||||
|
|
@ -40,9 +40,10 @@
|
|||
>
|
||||
</div>
|
||||
<div class="border rounded p-1 -mx-2 w-fit">
|
||||
<input type="checkbox" bind:checked={hideExpired} class="checkbox checkbox-xs" /><span
|
||||
<input type="checkbox" bind:checked="{preAuthHide}" on:change="{() => {preAuthHide ? $preAuthHideStore = 'true': $preAuthHideStore = 'false'}}" class="checkbox checkbox-xs text-base-content" /><span
|
||||
on:click={() => {
|
||||
hideExpired = !hideExpired;
|
||||
$preAuthHideStore == 'true' ? $preAuthHideStore = 'false' : $preAuthHideStore = 'true';
|
||||
preAuthHide = ($preAuthHideStore == 'true');
|
||||
}}
|
||||
class="font-normal ml-2">Hide Expired/Used Keys</span
|
||||
>
|
||||
|
|
@ -57,7 +58,7 @@
|
|||
<tr><td>Refresh to see contents</td></tr>
|
||||
{:else}
|
||||
<!-- hide if key is expired or used (and not reusable) and checkbox is checked -->
|
||||
<tr class:hidden={hideExpired && ((key.used && !key.reusable) || new Date(key.expiration).getTime() < new Date().getTime())}>
|
||||
<tr class:hidden={preAuthHide && ((key.used && !key.reusable) || new Date(key.expiration).getTime() < new Date().getTime())}>
|
||||
<th>{key.id}</th>
|
||||
<td
|
||||
><code class="border p-1 rounded">{key.key}</code>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue