Astro build funktioniert
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { AufnahmeKomplettClient, BenutzerClient } from "#components/Ausweis/types.js";
|
||||
import Carousel from "#components/Carousel.svelte";
|
||||
import DashboardAusweis from "#components/Dashboard/DashboardAusweis.svelte";
|
||||
import { Objekt } from "@ibcornelsen/database/client";
|
||||
import { Objekt } from "#lib/client/prisma";
|
||||
import { ChevronLeft, ChevronRight, Plus } from "radix-svelte-icons";
|
||||
|
||||
export let user: BenutzerClient;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016.js";
|
||||
import AusweisPruefenNotification from "#components/AusweisPruefenNotification.svelte";
|
||||
import DashboardAusweisSkeleton from "#components/Dashboard/DashboardAusweisSkeleton.svelte"
|
||||
import { Event } from "@ibcornelsen/database/client";
|
||||
import { Event } from "#lib/client/prisma";
|
||||
import Pagination from "#components/Pagination.svelte";
|
||||
import { api } from "astro-typesafe-api/client";
|
||||
import Cookies from "js-cookie"
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { Designer } from "@pdfme/ui";
|
||||
import { image, text } from "@pdfme/schemas";
|
||||
import { variable } from "../../lib/pdf/plugins/variables/index"
|
||||
import { onMount } from "svelte";
|
||||
|
||||
import { Template, BLANK_PDF } from "@pdfme/common";
|
||||
|
||||
let template: Template = {
|
||||
basePdf: BLANK_PDF,
|
||||
schemas: [
|
||||
{
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
let plugins = { Bild: image, Text: text, Variablen: variable }
|
||||
|
||||
let container: HTMLDivElement;
|
||||
|
||||
let designer: Designer;
|
||||
|
||||
onMount(() => {
|
||||
designer = new Designer({ domContainer: container, template, plugins });
|
||||
});
|
||||
|
||||
function loadBasePDF() {
|
||||
if (!loadTemplateInput.files) return;
|
||||
|
||||
const file = loadTemplateInput.files[0];
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = function (e) {
|
||||
if (!e.target) return;
|
||||
|
||||
const basePdf = e.target.result as string;
|
||||
const newTemplate = { ...template, basePdf };
|
||||
designer = new Designer({ domContainer: container, template: newTemplate, plugins });
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
function addNewField() {
|
||||
template = designer.getTemplate();
|
||||
const page = designer.getPageCursor();
|
||||
|
||||
template.schemas[page]["new-field"] = {
|
||||
type: "text",
|
||||
position: { x: 0, y: 0 },
|
||||
width: 10,
|
||||
height: 10
|
||||
};
|
||||
|
||||
designer.updateTemplate(template);
|
||||
}
|
||||
|
||||
function exportTemplate() {
|
||||
const template = designer.getTemplate();
|
||||
const blob = new Blob([JSON.stringify(template)], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "template.json";
|
||||
a.click();
|
||||
}
|
||||
|
||||
function loadTemplate() {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".json";
|
||||
input.onchange = function (e) {
|
||||
if (!input.files) return;
|
||||
|
||||
const file = input.files[0];
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = function (e) {
|
||||
if (!e.target) return;
|
||||
|
||||
const template = JSON.parse(e.target.result as string) as Template;
|
||||
designer = new Designer({ domContainer: container, template, plugins });
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
};
|
||||
|
||||
input.click()
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.ctrlKey && e.key === "s") {
|
||||
e.preventDefault();
|
||||
exportTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
let loadTemplateInput: HTMLInputElement;
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={onKeydown}></svelte:window>
|
||||
|
||||
<header class="mb-4">
|
||||
<button class="btn btn-secondary" on:click={() => loadTemplateInput.click()}>Change base PDF</button>
|
||||
<button class="btn btn-secondary" on:click={addNewField}>Add new Field</button>
|
||||
<button class="btn btn-secondary" on:click={exportTemplate}>Export</button>
|
||||
<button class="btn btn-secondary" on:click={loadTemplate}>Load Template</button>
|
||||
<a class="btn btn-secondary" href="/dashboard/admin/pdf-viewer">Test in Viewer</a>
|
||||
<input type="file" hidden bind:this={loadTemplateInput} on:change={loadBasePDF}>
|
||||
</header>
|
||||
|
||||
<div bind:this={container} class="h-[80vh]"></div>
|
||||
@@ -1,99 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { variable } from "#lib/pdf/plugins/variables";
|
||||
import { Benutzer, GebaeudeStammdaten, Rechnungen, VerbrauchsausweisWohnen } from "@ibcornelsen/database/client";
|
||||
import { Template } from "@pdfme/common";
|
||||
import { Viewer } from "@pdfme/ui";
|
||||
import { Check } from "radix-svelte-icons";
|
||||
import { image, text } from "@pdfme/schemas";
|
||||
import { VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
||||
import { convertAusweisData } from "#lib/AusweisData";
|
||||
|
||||
|
||||
|
||||
export let ausweise: VerbrauchsausweisWohnenClient[];
|
||||
|
||||
let pdfInputs: VerbrauchsausweisWohnenClient;
|
||||
let template: Template;
|
||||
let viewer: Viewer
|
||||
|
||||
|
||||
function loadTemplate() {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".json";
|
||||
|
||||
input.onchange = function (e) {
|
||||
if (!input.files) return;
|
||||
|
||||
const file = input.files[0];
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = async function (e) {
|
||||
if (!e.target) return;
|
||||
|
||||
template = JSON.parse(e.target.result as string) as Template;
|
||||
|
||||
if (!pdfInputs) {
|
||||
alert("Bitte wählen Sie einen Ausweis aus, um diesen als Basis zu verwenden.")
|
||||
return
|
||||
};
|
||||
|
||||
const convertedInputs = convertAusweisData(pdfInputs);
|
||||
|
||||
viewer = new Viewer({
|
||||
domContainer: pdfViewerContainer,
|
||||
template,
|
||||
inputs: [convertedInputs],
|
||||
plugins: { text, image, variable: { ...variable, pdf: variable.pdf.bind(convertedInputs), ui: variable.ui.bind(convertedInputs) } }
|
||||
})
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
};
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
function changeInputs(inputs: VerbrauchsausweisWohnenClient) {
|
||||
pdfInputs = inputs;
|
||||
|
||||
if (!template) {
|
||||
alert("Bitte laden Sie zuerst ein Template.")
|
||||
return
|
||||
}
|
||||
|
||||
if (viewer) viewer.destroy();
|
||||
|
||||
const convertedInputs = convertAusweisData(pdfInputs);
|
||||
|
||||
viewer = new Viewer({
|
||||
domContainer: pdfViewerContainer,
|
||||
template,
|
||||
inputs: [convertedInputs],
|
||||
plugins: { text, image, variable: { ...variable, pdf: variable.pdf.bind(convertedInputs), ui: variable.ui.bind(convertedInputs) } }
|
||||
})
|
||||
}
|
||||
|
||||
let pdfViewerContainer: HTMLDivElement;
|
||||
</script>
|
||||
|
||||
<header>
|
||||
<div>
|
||||
<button class="btn btn-secondary mb-4" on:click={loadTemplate}>Load Template</button>
|
||||
</div>
|
||||
</header>
|
||||
<main class="grid grid-cols-[1fr_4fr] gap-4">
|
||||
<div>
|
||||
<div class="flex flex-col gap-4">
|
||||
{#each ausweise as ausweis}
|
||||
<div class="rounded-lg border p-2 flex flex-row items-center justify-between">
|
||||
<h2 class="text-black">{ausweis.aufnahme.objekt.adresse}</h2>
|
||||
<button class="btn btn-square btn-ghost p-1.5" on:click={() => {
|
||||
changeInputs(ausweis)
|
||||
}}><Check size={20}/></button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<div bind:this={pdfViewerContainer}></div>
|
||||
</main>
|
||||
Reference in New Issue
Block a user