remove table resizing and fix admin panel user scroll behavior
All checks were successful
delpoy / build-and-deploy (push) Successful in 56s
All checks were successful
delpoy / build-and-deploy (push) Successful in 56s
This commit is contained in:
parent
b1f546ee94
commit
9ababd4847
@ -1,9 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte';
|
// eslint-disable-next-line no-undef
|
||||||
|
type T = $$Generic;
|
||||||
|
|
||||||
export let id: string | null = null;
|
export let id: string | null = null;
|
||||||
export let name: string | null = null;
|
export let name: string | null = null;
|
||||||
export let value: any | null = null;
|
export let value: T | null = null;
|
||||||
export let label: string | null = null;
|
export let label: string | null = null;
|
||||||
export let notice: string | null = null;
|
export let notice: string | null = null;
|
||||||
export let required = false;
|
export let required = false;
|
||||||
|
@ -3,56 +3,3 @@ export async function buttonTriggeredRequest<T>(e: MouseEvent, promise: Promise<
|
|||||||
await promise;
|
await promise;
|
||||||
(e.target as HTMLButtonElement).disabled = false;
|
(e.target as HTMLButtonElement).disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resizeTableColumn(event: MouseEvent, dragOffset: number) {
|
|
||||||
const element = event.target as HTMLTableCellElement;
|
|
||||||
const rect = element.getBoundingClientRect();
|
|
||||||
|
|
||||||
const posX = event.clientX - rect.left;
|
|
||||||
const offset = rect.width - event.clientX;
|
|
||||||
if (posX <= dragOffset || posX >= rect.width - dragOffset) {
|
|
||||||
// do not resize if resize request is on the table left or right
|
|
||||||
if (
|
|
||||||
(posX <= dragOffset && !element.previousElementSibling) ||
|
|
||||||
(posX >= rect.width - dragOffset && !element.nextElementSibling)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const table = element.parentElement!.parentElement!.parentElement as HTMLTableElement;
|
|
||||||
let resizeRow: HTMLTableRowElement;
|
|
||||||
if (table.tBodies[0].rows[0].hasAttribute('resize-row')) {
|
|
||||||
resizeRow = table.tBodies[0].rows[0];
|
|
||||||
} else {
|
|
||||||
resizeRow = table.tBodies[0].insertRow(0);
|
|
||||||
resizeRow.setAttribute('resize-row', '');
|
|
||||||
resizeRow.style.height = '0';
|
|
||||||
resizeRow.style.border = '0';
|
|
||||||
resizeRow.style.overflow = 'hidden';
|
|
||||||
for (let i = 0; i < table.rows[0].cells.length; i++) {
|
|
||||||
const cell = resizeRow.insertCell();
|
|
||||||
cell.style.padding = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert an additional to keep the zebra in place pattern which might be applied
|
|
||||||
const zebraGhostRow = table.tBodies[0].insertRow(1);
|
|
||||||
zebraGhostRow.hidden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const resizeElement =
|
|
||||||
resizeRow.cells[element.cellIndex - ((posX <= dragOffset) as unknown as number)];
|
|
||||||
|
|
||||||
// eslint-disable-next-line svelte/no-inner-declarations,no-inner-declarations
|
|
||||||
function resize(e: MouseEvent) {
|
|
||||||
document.body.style.cursor = 'col-resize';
|
|
||||||
resizeElement.style.width = `${offset + e.clientX}px`;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', resize);
|
|
||||||
|
|
||||||
document.addEventListener('mouseup', () => {
|
|
||||||
document.removeEventListener('mousemove', resize);
|
|
||||||
document.body.style.cursor = 'initial';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import { Permissions } from '$lib/permissions';
|
import { Permissions } from '$lib/permissions';
|
||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import ErrorToast from '$lib/components/Toast/ErrorToast.svelte';
|
import ErrorToast from '$lib/components/Toast/ErrorToast.svelte';
|
||||||
import { buttonTriggeredRequest, resizeTableColumn } from '$lib/components/utils';
|
import { buttonTriggeredRequest } from '$lib/components/utils';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { adminCount } from '$lib/stores';
|
import { adminCount } from '$lib/stores';
|
||||||
|
|
||||||
@ -97,18 +97,18 @@
|
|||||||
<table class="table table-zebra w-full">
|
<table class="table table-zebra w-full">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th on:mousedown={(e) => resizeTableColumn(e, 5)} />
|
<th />
|
||||||
<th on:mousedown={(e) => resizeTableColumn(e, 5)}>Benutzername</th>
|
<th>Benutzername</th>
|
||||||
<th on:mousedown={(e) => resizeTableColumn(e, 5)}>Passwort</th>
|
<th>Passwort</th>
|
||||||
<th on:mousedown={(e) => resizeTableColumn(e, 5)}>Berechtigungen</th>
|
<th>Berechtigungen</th>
|
||||||
<th on:mousedown={(e) => resizeTableColumn(e, 5)} />
|
<th />
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each data.admins as admin, i}
|
{#each data.admins as admin, i}
|
||||||
<tr>
|
<tr>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>{i + 1}</td>
|
<td>{i + 1}</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}
|
<td
|
||||||
><Input
|
><Input
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={admin.username}
|
bind:value={admin.username}
|
||||||
@ -116,7 +116,7 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
/></td
|
/></td
|
||||||
>
|
>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}
|
<td
|
||||||
><Input
|
><Input
|
||||||
type="password"
|
type="password"
|
||||||
bind:value={admin.password}
|
bind:value={admin.password}
|
||||||
@ -125,14 +125,14 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
/></td
|
/></td
|
||||||
>
|
>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}
|
<td
|
||||||
><Badges
|
><Badges
|
||||||
bind:value={admin.permissions}
|
bind:value={admin.permissions}
|
||||||
available={allPermissionBadges}
|
available={allPermissionBadges}
|
||||||
disabled={!permissions.adminWrite() || !admin.edit}
|
disabled={!permissions.adminWrite() || !admin.edit}
|
||||||
/></td
|
/></td
|
||||||
>
|
>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<div>
|
<div>
|
||||||
{#if admin.edit}
|
{#if admin.edit}
|
||||||
<span class="w-min" class:cursor-not-allowed={!permissions.adminWrite()}>
|
<span class="w-min" class:cursor-not-allowed={!permissions.adminWrite()}>
|
||||||
@ -196,21 +196,17 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
<tr>
|
<tr>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>{data.admins.length + 1}</td>
|
<td>{data.admins.length + 1}</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}
|
<td><Input type="text" bind:value={newAdminUsername} size="sm" /></td>
|
||||||
><Input type="text" bind:value={newAdminUsername} size="sm" /></td
|
<td><Input type="password" bind:value={newAdminPassword} size="sm" /></td>
|
||||||
>
|
<td
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}
|
|
||||||
><Input type="password" bind:value={newAdminPassword} size="sm" /></td
|
|
||||||
>
|
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}
|
|
||||||
><Badges
|
><Badges
|
||||||
bind:value={newAdminPermissions}
|
bind:value={newAdminPermissions}
|
||||||
available={allPermissionBadges}
|
available={allPermissionBadges}
|
||||||
disabled={!permissions.adminWrite()}
|
disabled={!permissions.adminWrite()}
|
||||||
/></td
|
/></td
|
||||||
>
|
>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<span
|
<span
|
||||||
class="w-min"
|
class="w-min"
|
||||||
class:cursor-not-allowed={!permissions.adminWrite() ||
|
class:cursor-not-allowed={!permissions.adminWrite() ||
|
||||||
@ -241,28 +237,3 @@
|
|||||||
<ErrorToast show={errorMessage !== ''}>
|
<ErrorToast show={errorMessage !== ''}>
|
||||||
<span />
|
<span />
|
||||||
</ErrorToast>
|
</ErrorToast>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
thead tr th,
|
|
||||||
tbody tr td {
|
|
||||||
@apply relative;
|
|
||||||
|
|
||||||
&:not(:first-child) {
|
|
||||||
@apply border-l-[1px] border-dashed;
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
@apply absolute left-0 bottom-0 h-full w-[5px] cursor-col-resize;
|
|
||||||
content: '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:not(:last-child) {
|
|
||||||
@apply border-r-[1px] border-dashed border-base-300;
|
|
||||||
|
|
||||||
&::after {
|
|
||||||
@apply absolute right-0 bottom-0 h-full w-[5px] cursor-col-resize;
|
|
||||||
content: '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
import Select from '$lib/components/Input/Select.svelte';
|
import Select from '$lib/components/Input/Select.svelte';
|
||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import type { User } from '$lib/server/database';
|
import type { User } from '$lib/server/database';
|
||||||
import { buttonTriggeredRequest, resizeTableColumn } from '$lib/components/utils';
|
import { buttonTriggeredRequest } from '$lib/components/utils';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import HeaderBar from './HeaderBar.svelte';
|
import HeaderBar from './HeaderBar.svelte';
|
||||||
|
|
||||||
@ -120,16 +120,16 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div class="h-screen flex flex-col overflow-hidden">
|
||||||
<HeaderBar bind:userFilter />
|
<HeaderBar bind:userFilter />
|
||||||
<hr class="divider my-1 mx-8 border-none" />
|
<hr class="divider my-1 mx-8 border-none" />
|
||||||
<div class="h-[90vh] overflow-scroll" bind:this={userTableContainerElement}>
|
<div class="h-full overflow-scroll" bind:this={userTableContainerElement}>
|
||||||
<table class="table relative">
|
<table class="table table-auto">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="[&>th]:bg-base-100 [&>th]:z-[1] [&>th]:sticky [&>th]:top-0">
|
<tr class="[&>th]:bg-base-100 [&>th]:z-[1] [&>th]:sticky [&>th]:top-0">
|
||||||
<th />
|
<th />
|
||||||
{#each headers as header}
|
{#each headers as header}
|
||||||
<th on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<th>
|
||||||
<button
|
<button
|
||||||
class="flex items-center"
|
class="flex items-center"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
@ -155,14 +155,14 @@
|
|||||||
{#await currentPageUsersRequest then _}
|
{#await currentPageUsersRequest then _}
|
||||||
{#each currentPageUsers as user, i}
|
{#each currentPageUsers as user, i}
|
||||||
<tr>
|
<tr>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>{i + 1}</td>
|
<td>{i + 1}</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input type="text" bind:value={user.firstname} disabled={!user.edit} size="sm" />
|
<Input type="text" bind:value={user.firstname} disabled={!user.edit} size="sm" />
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input type="text" bind:value={user.lastname} disabled={!user.edit} size="sm" />
|
<Input type="text" bind:value={user.lastname} disabled={!user.edit} size="sm" />
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input
|
<Input
|
||||||
type="date"
|
type="date"
|
||||||
value={new Date(user.birthday).toISOString().split('T')[0]}
|
value={new Date(user.birthday).toISOString().split('T')[0]}
|
||||||
@ -171,23 +171,23 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input type="tel" bind:value={user.telephone} disabled={!user.edit} size="sm" />
|
<Input type="tel" bind:value={user.telephone} disabled={!user.edit} size="sm" />
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input type="text" bind:value={user.username} disabled={!user.edit} size="sm" />
|
<Input type="text" bind:value={user.username} disabled={!user.edit} size="sm" />
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Select id="edition" bind:value={user.playertype} disabled={!user.edit} size="sm">
|
<Select id="edition" bind:value={user.playertype} disabled={!user.edit} size="sm">
|
||||||
<option value="java">Java Edition</option>
|
<option value="java">Java Edition</option>
|
||||||
<option value="bedrock">Bedrock Edition</option>
|
<option value="bedrock">Bedrock Edition</option>
|
||||||
<option value="cracked">Java cracked</option>
|
<option value="cracked">Java cracked</option>
|
||||||
</Select>
|
</Select>
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input type="text" bind:value={user.password} disabled={!user.edit} size="sm" />
|
<Input type="text" bind:value={user.password} disabled={!user.edit} size="sm" />
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<Input
|
<Input
|
||||||
id="uuid"
|
id="uuid"
|
||||||
type="text"
|
type="text"
|
||||||
@ -196,7 +196,7 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td on:mousedown={(e) => resizeTableColumn(e, 5)}>
|
<td>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
{#if user.edit}
|
{#if user.edit}
|
||||||
<button
|
<button
|
||||||
@ -242,8 +242,7 @@
|
|||||||
{/key}
|
{/key}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
<div class="flex justify-center items-center mb-2 mt-4 w-full">
|
||||||
<div class="flex justify-center w-full mt-4 mb-6">
|
|
||||||
<div class="join">
|
<div class="join">
|
||||||
{#each Array(Math.ceil(data.count / usersPerPage) || 1) as _, i}
|
{#each Array(Math.ceil(data.count / usersPerPage) || 1) as _, i}
|
||||||
<button
|
<button
|
||||||
@ -256,29 +255,5 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
thead tr th,
|
|
||||||
tbody tr td {
|
|
||||||
@apply relative;
|
|
||||||
|
|
||||||
&:not(:first-child) {
|
|
||||||
@apply border-l-[1px] border-dashed;
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
@apply absolute left-0 bottom-0 h-full w-[5px] cursor-col-resize;
|
|
||||||
content: '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:not(:last-child) {
|
|
||||||
@apply border-r-[1px] border-dashed border-base-300;
|
|
||||||
|
|
||||||
&::after {
|
|
||||||
@apply absolute right-0 bottom-0 h-full w-[5px] cursor-col-resize;
|
|
||||||
content: '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user