diff --git a/src/lib/components/data/machine/EditMachine.svelte b/src/lib/components/data/machine/EditMachine.svelte index 899fe57..79afb3d 100644 --- a/src/lib/components/data/machine/EditMachine.svelte +++ b/src/lib/components/data/machine/EditMachine.svelte @@ -8,12 +8,17 @@ import * as Form from '$lib/components/form'; - import type { Machine } from '$lib/api'; + import { User, type Machine } from '$lib/api'; + import Label from '$lib/components/ui/label/label.svelte'; + import SelectUser from '../user/SelectUser.svelte'; + import { writable } from 'svelte/store'; export let machine: Machine; + export let users: User[] | undefined; const schema = z.object({ - name: z.string() + name: z.string(), + assigned_user: z.string() }); const form = superForm(defaults(zod(schema)), { @@ -30,9 +35,11 @@ const { constraints, form: formData } = form; - formData.set({ name: machine.givenName || '' }); + function reset() { + formData.set({ name: machine.givenName || '', assigned_user: machine.user?.name || '' }); + } - function reset() {} + reset(); @@ -45,13 +52,20 @@ Edit machine - + Given name + + + + Assigned user + + + diff --git a/src/lib/components/data/machine/MachineActions.svelte b/src/lib/components/data/machine/MachineActions.svelte index 6f689ad..148ca6c 100644 --- a/src/lib/components/data/machine/MachineActions.svelte +++ b/src/lib/components/data/machine/MachineActions.svelte @@ -7,13 +7,15 @@ import Telescope from 'lucide-svelte/icons/telescope'; import Trash from 'lucide-svelte/icons/trash-2'; - import type { Machine } from '$lib/api'; + import type { Machine, User } from '$lib/api'; import DeleteMachine from './DeleteMachine.svelte'; import EditMachine from './EditMachine.svelte'; import ExpireSession from './ExpireSession.svelte'; + import { isExpired } from '$lib/utils/time'; export let machine: Machine; + export let users: User[] | undefined; const dispatch = createEventDispatcher<{ close: undefined; focus: undefined }>(); @@ -37,7 +39,7 @@
  • - + diff --git a/src/lib/components/data/machine/MachineInfo.svelte b/src/lib/components/data/machine/MachineInfo.svelte index 51b63a7..7d1d124 100644 --- a/src/lib/components/data/machine/MachineInfo.svelte +++ b/src/lib/components/data/machine/MachineInfo.svelte @@ -167,7 +167,12 @@ diff --git a/src/lib/components/data/user/SelectUser.svelte b/src/lib/components/data/user/SelectUser.svelte new file mode 100644 index 0000000..d9837f2 --- /dev/null +++ b/src/lib/components/data/user/SelectUser.svelte @@ -0,0 +1,29 @@ + + + + + + + + + + {#each users || [] as user} + {user.name} + {/each} + + + diff --git a/src/lib/mock/handlers.ts b/src/lib/mock/handlers.ts index d1e9c0a..519f42a 100644 --- a/src/lib/mock/handlers.ts +++ b/src/lib/mock/handlers.ts @@ -9,7 +9,7 @@ const MAX_ARRAY_LENGTH = 5; const MIN_ARRAY_LENGTH = 0; const usersLength = faker.number.int({ min: 3, max: 8 }); -const machinesLength = faker.number.int({ min: 10, max: 25 }); +const machinesLength = faker.number.int({ min: 10, max: 30 }); const simulateApiError: boolean = false; @@ -145,8 +145,10 @@ export const handlers = [ path: '/api/v1/node', method: 'get', response: { - nodes: randomSizedArray( - (id) => ({ + nodes: randomSizedArray((id) => { + const userId = faker.number.int({ min: 0, max: usersLength - 1 }); + + return { id: String(id), name: faker.person.lastName(), givenName: faker.person.lastName(), @@ -162,12 +164,15 @@ export const handlers = [ forcedTags: [], validTags: [], user: { - id: faker.number.octal({ min: 1, max: usersLength - 1 }) + id: String(userId), + name: usernames[userId] }, - ipAddresses: [faker.internet.ipv4(), faker.internet.ipv6()] - }), - machinesLength - ) + ipAddresses: [ + `100.64.${Math.trunc((id + 1) / 255)}.${(id + 1) % 255}`, + 'fd7a:115c:a1e0::' + (id + 1).toString(16) + ] + }; + }, machinesLength) } }), handler({ diff --git a/src/lib/utils/networkGraph.ts b/src/lib/utils/networkGraph.ts index d6fcb47..6a686d4 100644 --- a/src/lib/utils/networkGraph.ts +++ b/src/lib/utils/networkGraph.ts @@ -24,8 +24,6 @@ import { type V1User, type V1Node } from '$lib/api'; -import { get } from 'svelte/store'; -import { mode } from 'mode-watcher'; const exitRoutes = ['0.0.0.0/0', '::/0']; diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index c048ec9..4f32df2 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -195,6 +195,7 @@ {#key $selectedNode} { focusOnNode(graph, $selectedNode);