Suche
This commit is contained in:
@@ -135,7 +135,7 @@
|
||||
);
|
||||
blockLocalStorageSync = true;
|
||||
localStorage.clear()
|
||||
window.location.href = `/dashboard/objekte?id=${ausweis.id}`
|
||||
window.location.href = `/dashboard/objekte/${ausweis.id}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
Gear,
|
||||
LockClosed,
|
||||
CaretDown,
|
||||
MagnifyingGlass,
|
||||
} from "radix-svelte-icons";
|
||||
import NotificationProvider from "#components/NotificationProvider/NotificationProvider.svelte";
|
||||
import DashboardNotification from "./DashboardNotification.svelte";
|
||||
@@ -17,6 +18,8 @@
|
||||
|
||||
export let lightTheme: boolean;
|
||||
export let benutzer: BenutzerClient;
|
||||
|
||||
let id: string;
|
||||
</script>
|
||||
|
||||
<aside class="rounded-lg bg-white box px-6 py-5">
|
||||
@@ -41,11 +44,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="flex flex-col gap-2 mt-0 md:mt-8 px-0">
|
||||
<a class="button-tab" href="/dashboard">
|
||||
<Reader width={22} height={22} />
|
||||
Ausweise
|
||||
</a>
|
||||
|
||||
<div class="flex flex-row gap-2">
|
||||
<input type="text" bind:value={id} placeholder="ID">
|
||||
<button class="button" on:click={() => {
|
||||
window.location.href = `/dashboard/objekte/${id}`
|
||||
}}><MagnifyingGlass size={24}></MagnifyingGlass></button>
|
||||
</div>
|
||||
|
||||
<hr class="border-gray-600" />
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
{#if page > 1}
|
||||
<a class="p-2 rounded-lg hover:bg-gray-200 cursor-pointer" href="/dashboard/objekte/{page - 1}">
|
||||
<a class="p-2 rounded-lg hover:bg-gray-200 cursor-pointer" href="/dashboard/objekte?p={page - 1}">
|
||||
<CaretLeft size={30}></CaretLeft>
|
||||
</a>
|
||||
{:else}
|
||||
@@ -89,7 +89,7 @@
|
||||
{/if}
|
||||
<div class="text-lg">Ausweis {page} / {totalPageCount}</div>
|
||||
{#if totalPageCount > page}
|
||||
<a class="p-2 rounded-lg hover:bg-gray-200 cursor-pointer" href="/dashboard/objekte/{page + 1}">
|
||||
<a class="p-2 rounded-lg hover:bg-gray-200 cursor-pointer" href="/dashboard/objekte?p={page + 1}">
|
||||
<CaretRight size={30}></CaretRight>
|
||||
</a>
|
||||
{:else}
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<Pagination pages={totalPages} current={page} prev="/dashboard/objekte/{page - 1}" next="/dashboard/objekte/{page + 1}"></Pagination>
|
||||
<Pagination pages={totalPages} current={page} prev="/dashboard/objekte?p={page - 1}" next="/dashboard/objekte?p={page + 1}"></Pagination>
|
||||
|
||||
|
||||
<Overlay bind:hidden={objektOverlayHidden}>
|
||||
|
||||
@@ -265,7 +265,7 @@
|
||||
);
|
||||
|
||||
localStorage.clear();
|
||||
window.location.href = `/dashboard/objekte?id=${ausweis.id}`
|
||||
window.location.href = `/dashboard/objekte/${ausweis.id}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1103,7 +1103,7 @@ sm:grid-cols-[min-content_min-content_min-content] sm:justify-self-end sm:mt-8"
|
||||
{#if user.rolle === Enums.BenutzerRolle.ADMIN}
|
||||
<button class="button text-sm" on:click={() => {
|
||||
localStorage.clear()
|
||||
window.location.href = "/dashboard/objekte/1"
|
||||
window.location.href = "/dashboard/objekte?p=1"
|
||||
}}>Zurück zum Dashboard</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
return Astro.redirect("/dashboard/objekte/1", 301);
|
||||
return Astro.redirect("/dashboard/objekte?p=1", 301);
|
||||
---
|
||||
|
||||
|
||||
|
||||
83
src/pages/dashboard/objekte/[id].astro
Normal file
83
src/pages/dashboard/objekte/[id].astro
Normal file
@@ -0,0 +1,83 @@
|
||||
---
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import { Enums, prisma } from "#lib/server/prisma";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
import DashboardAufnahmeModule from "#modules/Dashboard/DashboardAufnahmeModule.svelte";
|
||||
import { getPrismaAusweisAdapter } from "#lib/server/ausweis";
|
||||
|
||||
const id = Astro.params.id as string;
|
||||
const page = Number(Astro.url.searchParams.get("p"));
|
||||
const user = await getCurrentUser(Astro);
|
||||
|
||||
if (!user) {
|
||||
return Astro.redirect("/auth/login");
|
||||
}
|
||||
|
||||
const totalPageCount = await prisma.aufnahme.count({
|
||||
where:
|
||||
user.rolle === Enums.BenutzerRolle.USER
|
||||
? {
|
||||
benutzer: {
|
||||
id: user.id,
|
||||
},
|
||||
}
|
||||
: {},
|
||||
});
|
||||
|
||||
let ausweis;
|
||||
// Wir fragen den neuesten Ausweis ab
|
||||
// Falls der Nutzer ein Admin ist dann kommt der ganz neueste ansonsten der neueste des eingeloggten Benutzers.
|
||||
if (user.rolle === Enums.BenutzerRolle.USER) {
|
||||
const adapter = getPrismaAusweisAdapter(id);
|
||||
ausweis = await adapter?.findUnique({
|
||||
where: {
|
||||
id,
|
||||
benutzer_id: user.id,
|
||||
},
|
||||
include: {
|
||||
rechnung: true,
|
||||
aufnahme: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
objekt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const adapter = getPrismaAusweisAdapter(id);
|
||||
ausweis = await adapter?.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
rechnung: true,
|
||||
aufnahme: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
objekt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!ausweis) {
|
||||
return Astro.redirect("/dashboard/objekte?p=1")
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<UserLayout title="Objekte" {user}>
|
||||
<DashboardAufnahmeModule
|
||||
{ausweis}
|
||||
benutzer={user}
|
||||
{totalPageCount}
|
||||
{page}
|
||||
client:load
|
||||
/>
|
||||
<!-- {!aufnahme ? <p>Keine weiteren Ausweise vorhanden.</p> : <DashboardAufnahmeModule {user} {aufnahme} benutzer={user} objekt={aufnahme.objekt} client:load/>} -->
|
||||
<!-- <DashboardModule {user} {objekte} totalPages={Math.ceil(totalPages / 25)} page={page} {id} client:load /> -->
|
||||
</UserLayout>
|
||||
@@ -1,134 +0,0 @@
|
||||
---
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import { Enums, prisma } from "#lib/server/prisma";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
import DashboardAufnahmeModule from "#modules/Dashboard/DashboardAufnahmeModule.svelte";
|
||||
import { getPrismaAusweisAdapter } from "#lib/server/ausweis";
|
||||
|
||||
const params = Astro.params;
|
||||
|
||||
const page = Number(params.page);
|
||||
|
||||
const id = Astro.url.searchParams.get("id") || undefined;
|
||||
|
||||
const user = await getCurrentUser(Astro);
|
||||
|
||||
if (!user) {
|
||||
return Astro.redirect("/auth/login");
|
||||
}
|
||||
|
||||
const totalPageCount = await prisma.aufnahme.count({
|
||||
where:
|
||||
user.rolle === Enums.BenutzerRolle.USER
|
||||
? {
|
||||
benutzer: {
|
||||
id: user.id,
|
||||
},
|
||||
}
|
||||
: {},
|
||||
});
|
||||
|
||||
if (page < 1 || page > totalPageCount) {
|
||||
return Astro.redirect("/dashboard/objekte/1");
|
||||
}
|
||||
|
||||
let ausweis,
|
||||
result: { id: string; updated_at: Date }[] = [];
|
||||
// Wir fragen den neuesten Ausweis ab
|
||||
// Falls der Nutzer ein Admin ist dann kommt der ganz neueste ansonsten der neueste des eingeloggten Benutzers.
|
||||
if (user.rolle === Enums.BenutzerRolle.USER) {
|
||||
if (id) {
|
||||
const adapter = getPrismaAusweisAdapter(id);
|
||||
ausweis = await adapter?.findUnique({
|
||||
where: {
|
||||
id,
|
||||
benutzer_id: user.id,
|
||||
},
|
||||
include: {
|
||||
rechnung: true,
|
||||
aufnahme: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
objekt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
result =
|
||||
await prisma.$queryRaw`SELECT id, updated_at FROM "VerbrauchsausweisWohnen" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "VerbrauchsausweisGewerbe" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisWohnen" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisGewerbe" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisWohnen" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisGewerbe" WHERE benutzer_id = ${user.id}
|
||||
ORDER BY updated_at DESC LIMIT 1 OFFSET ${page - 1}`;
|
||||
}
|
||||
} else {
|
||||
if (id) {
|
||||
const adapter = getPrismaAusweisAdapter(id);
|
||||
ausweis = await adapter?.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
rechnung: true,
|
||||
aufnahme: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
objekt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
result =
|
||||
await prisma.$queryRaw`SELECT id, updated_at FROM "VerbrauchsausweisWohnen" UNION ALL
|
||||
SELECT id, updated_at FROM "VerbrauchsausweisGewerbe" UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisWohnen" UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisGewerbe" UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisWohnen" UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisGewerbe"
|
||||
ORDER BY updated_at DESC LIMIT 1 OFFSET ${page - 1}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.length > 0) {
|
||||
const adapter = getPrismaAusweisAdapter(result[0].id);
|
||||
|
||||
ausweis = await adapter?.findUnique({
|
||||
where: {
|
||||
id: result[0].id,
|
||||
},
|
||||
include: {
|
||||
rechnung: true,
|
||||
aufnahme: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
objekt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!ausweis) {
|
||||
return Astro.redirect("/dashboard/objekte/1")
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<UserLayout title="Objekte" {user}>
|
||||
<DashboardAufnahmeModule
|
||||
{ausweis}
|
||||
benutzer={user}
|
||||
{totalPageCount}
|
||||
{page}
|
||||
client:load
|
||||
/>
|
||||
<!-- {!aufnahme ? <p>Keine weiteren Ausweise vorhanden.</p> : <DashboardAufnahmeModule {user} {aufnahme} benutzer={user} objekt={aufnahme.objekt} client:load/>} -->
|
||||
<!-- <DashboardModule {user} {objekte} totalPages={Math.ceil(totalPages / 25)} page={page} {id} client:load /> -->
|
||||
</UserLayout>
|
||||
@@ -1,5 +1,56 @@
|
||||
---
|
||||
return Astro.redirect("/dashboard/objekte/1");
|
||||
---
|
||||
import { Enums, prisma } from "#lib/server/prisma";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
|
||||
<script></script>
|
||||
const page = Number(Astro.url.searchParams.get("p"));
|
||||
|
||||
const user = await getCurrentUser(Astro);
|
||||
|
||||
if (!user) {
|
||||
return Astro.redirect("/auth/login");
|
||||
}
|
||||
|
||||
const totalPageCount = await prisma.aufnahme.count({
|
||||
where:
|
||||
user.rolle === Enums.BenutzerRolle.USER
|
||||
? {
|
||||
benutzer: {
|
||||
id: user.id,
|
||||
},
|
||||
}
|
||||
: {},
|
||||
});
|
||||
|
||||
if (page < 1 || page > totalPageCount) {
|
||||
return Astro.redirect("/dashboard/objekte?p=1");
|
||||
}
|
||||
|
||||
let result: { id: string; updated_at: Date }[] = [];
|
||||
// Wir fragen den neuesten Ausweis ab
|
||||
// Falls der Nutzer ein Admin ist dann kommt der ganz neueste ansonsten der neueste des eingeloggten Benutzers.
|
||||
if (user.rolle === Enums.BenutzerRolle.USER) {
|
||||
result =
|
||||
await prisma.$queryRaw`SELECT id, updated_at FROM "VerbrauchsausweisWohnen" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "VerbrauchsausweisGewerbe" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisWohnen" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisGewerbe" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisWohnen" WHERE benutzer_id = ${user.id} UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisGewerbe" WHERE benutzer_id = ${user.id}
|
||||
ORDER BY updated_at DESC LIMIT 1 OFFSET ${page - 1}`;
|
||||
} else {
|
||||
result =
|
||||
await prisma.$queryRaw`SELECT id, updated_at FROM "VerbrauchsausweisWohnen" UNION ALL
|
||||
SELECT id, updated_at FROM "VerbrauchsausweisGewerbe" UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisWohnen" UNION ALL
|
||||
SELECT id, updated_at FROM "BedarfsausweisGewerbe" UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisWohnen" UNION ALL
|
||||
SELECT id, updated_at FROM "GEGNachweisGewerbe"
|
||||
ORDER BY updated_at DESC LIMIT 1 OFFSET ${page - 1}`;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return Astro.redirect("/dashboard/objekte?p=1");
|
||||
}
|
||||
|
||||
return Astro.redirect(`/dashboard/objekte/${result[0].id}?p=${page}`)
|
||||
---
|
||||
Reference in New Issue
Block a user