Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redesign tweaks #150

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

.card-primary {
@apply grid grid-cols-1 divide-y p-2 max-w-screen-lg border mx-4 border-base-content rounded-md text-sm text-base-content shadow
@apply grid grid-cols-1 divide-y p-2 max-w-screen-lg mx-4 border-base-content rounded-md text-sm text-base-content shadow
}

.card-pending {
Expand Down
101 changes: 51 additions & 50 deletions src/lib/common/classes.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
export class Device {
public id: string = '';
public name: string = '';
public givenName: string = '';
public lastSeen: string = '';
public ipAddresses: string[] = []
public forcedTags: string[] = []
public validTags: string[] = []
public invalidTags: string[] = []
public user: { name: string } = { name: '' }
public id: string = '';
public name: string = '';
public givenName: string = '';
public lastSeen: string = '';
public ipAddresses: string[] = [];
public forcedTags: string[] = [];
public validTags: string[] = [];
public invalidTags: string[] = [];
public user: { name: string } = { name: '' };
public online?: boolean;

public constructor(init?: Partial<Device>) {
Object.assign(this, init);
}
public constructor(init?: Partial<Device>) {
Object.assign(this, init);
}
}

export class ACL {
public groups: {[key: string]: [string]} = {}
public groups: { [key: string]: [string] } = {};

public constructor(init?: Partial<Route>) {
Object.assign(this, init);
}
public constructor(init?: Partial<Route>) {
Object.assign(this, init);
}
}

export class Route {
// current (hs 18+) method of handling a route
advertised: boolean = true;
prefix: string = "";
enabled: boolean = false;
id: number = 0;
// current (hs 18+) method of handling a route
advertised: boolean = true;
prefix: string = '';
enabled: boolean = false;
id: number = 0;

public constructor(init?: Partial<Route>) {
Object.assign(this, init);
}
public constructor(init?: Partial<Route>) {
Object.assign(this, init);
}
}

export class APIKey {
id: string = '';
prefix: string = '';
expiration: string = '';
createdAt: string = '';
lastSeen: string = '';
id: string = '';
prefix: string = '';
expiration: string = '';
createdAt: string = '';
lastSeen: string = '';

public constructor(init?: Partial<Route>) {
Object.assign(this, init);
}
public constructor(init?: Partial<Route>) {
Object.assign(this, init);
}
}

export class PreAuthKey {
public user: string = '';
public id: string = '';
public key: string = '';
public createdAt: string = '';
public expiration: string = '';
public reusable: boolean = false;
public ephemeral: boolean = false;
public used: boolean = false;
public user: string = '';
public id: string = '';
public key: string = '';
public createdAt: string = '';
public expiration: string = '';
public reusable: boolean = false;
public ephemeral: boolean = false;
public used: boolean = false;

public constructor(init?: Partial<PreAuthKey>) {
Object.assign(this, init);
}
public constructor(init?: Partial<PreAuthKey>) {
Object.assign(this, init);
}
}

export class User {
public id: string = '';
public name: string = '';
public createdAt: string = '';
public constructor(init?: Partial<User>) {
Object.assign(this, init);
}
}
public id: string = '';
public name: string = '';
public createdAt: string = '';
public constructor(init?: Partial<User>) {
Object.assign(this, init);
}
}
23 changes: 19 additions & 4 deletions src/lib/devices/DeviceCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
} else if (timeDifference < 86400) {
return 'bg-warning';
}

return 'bg-error';
}

// return button colour based on online status
function onlineBackground(online: boolean) {
return online ? 'bg-success' : 'bg-error';
}

function getBadgeColour(date: Date, online?: boolean) {
if (online !== undefined) {
return onlineBackground(online);
}

return timeDifference(date);
}

// returns time last seen in human readable format
Expand Down Expand Up @@ -57,11 +72,11 @@
}
</script>

<div class="card-primary">
<div on:keypress on:click={() => (cardExpanded = !cardExpanded)} class="flex">
<div class="card-primary bg-base-200">
<div on:keypress on:click={() => (cardExpanded = !cardExpanded)} class="flex items-center">
<span class="min-w-64 w-1/2 font-bold">
{#if cardEditing == false}
<span class="badge badge-xs tooltip {timeDifference(new Date(device.lastSeen))}" data-tip={timeSince(new Date(device.lastSeen))} /> {device.id}: {device.givenName}
<span class="badge badge-xs tooltip {getBadgeColour(new Date(device.lastSeen), device.online)}" data-tip={timeSince(new Date(device.lastSeen))} /> {device.id}: {device.givenName}
{/if}
<RenameDevice bind:cardEditing {device} />
</span>
Expand All @@ -85,7 +100,7 @@
</div>
{#if cardExpanded}
<!-- we put a conditional on the outro transition so page changes do not trigger the animation -->
<div in:slide|global out:slide|global={{ duration: cardExpanded ? 0 : 500 }} class="pt-2 pl-2">
<div in:slide|global out:slide|global={{ duration: cardExpanded ? 0 : 500 }} class="mt-2 pt-2 pl-2">
<div class="overflow-x-auto">
<table class="table table-compact w-full">
<tbody>
Expand Down
32 changes: 17 additions & 15 deletions src/lib/devices/DeviceCard/DeviceTags.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@
}
</script>

<span><NewDeviceTag {device}/></span>
<div class="flex gap-1">
<span><NewDeviceTag {device}/></span>

{#each device.forcedTags as tag}
<span class="mb-1 mr-1 btn btn-xs btn-primary normal-case">{tag.replace("tag:","")}
<!-- Cancel symbol -->
<button on:click|stopPropagation={() => {updateTagsAction(tag)}}
class="ml-1"
><svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 inline flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg></button
>
</span>
{/each}
{#each device.forcedTags as tag}
<span class="btn btn-xs btn-primary normal-case">{tag.replace("tag:","")}
<!-- Cancel symbol -->
<button on:click|stopPropagation={() => {updateTagsAction(tag)}}
class="ml-1"
><svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 inline flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg></button
>
</span>
{/each}

{#each device.validTags as tag}
<span class="mb-1 mr-1 btn btn-xs btn-secondary normal-case">{tag.replace("tag:","")}</span>
{/each}
{#each device.validTags as tag}
<span class="mb-1 mr-1 btn btn-xs btn-secondary normal-case">{tag.replace("tag:","")}</span>
{/each}
</div>

4 changes: 2 additions & 2 deletions src/lib/users/UserCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let cardExpanded = false;
</script>

<div in:fade|global class="card-primary">
<div in:fade|global class="card-primary bg-base-200">
<div on:keypress on:click={() => (cardExpanded = !cardExpanded)} class="flex justify-between">
<div>
<EditUser {user} />
Expand All @@ -34,7 +34,7 @@
</div>
{#if cardExpanded}
<!-- we put a conditional on the outro transition so page changes do not trigger the animation -->
<div in:slide|global out:slide|global={{ duration: cardExpanded ? 0 : 500 }} class="pt-2 pl-2">
<div in:slide|global out:slide|global={{ duration: cardExpanded ? 0 : 500 }} class="mt-2 pt-2 pl-2">
<div class="overflow-x-auto">
<table class="table table-compact w-full">
<tbody>
Expand Down
12 changes: 7 additions & 5 deletions src/routes/devices.html/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@

<CreateDevice bind:newDeviceCardVisible bind:newDeviceKey />

{#each $deviceStore as device}
{#if $deviceFilterStore.includes(device)}
<DeviceCard {device} />
{/if}
{/each}
<div class="flex flex-col gap-2">
{#each $deviceStore as device}
{#if $deviceFilterStore.includes(device)}
<DeviceCard {device} />
{/if}
{/each}
</div>
{/if}
{#if $apiTestStore === 'failed'}
<div in:fade|global class="max-w-lg mx-auto p-4 border-4 text-sm text-base-content shadow-lg text-center">
Expand Down
13 changes: 8 additions & 5 deletions src/routes/users.html/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
>
</table>
<CreateUser bind:newUserCardVisible />
{#each $userStore as user}
{#if $userFilterStore.includes(user)}
<UserCard {user} />
{/if}
{/each}

<div class="flex flex-col gap-2">
{#each $userStore as user}
{#if $userFilterStore.includes(user)}
<UserCard {user} />
{/if}
{/each}
</div>
{/if}
{#if $apiTestStore === 'failed'}
<div in:fade|global class="max-w-lg mx-auto p-4 border-4 text-sm text-base-content shadow-lg text-center">
Expand Down