Weitere Tests, Besseres Typechecking, Alle Ausweise und Verbesserter Verbrauchsausweis Gewerbe
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
<script lang="ts">
|
||||
import type { BedarfsausweisWohnen, VerbrauchsausweisGewerbe, VerbrauchsausweisWohnen } from "@ibcornelsen/database/client";
|
||||
import type { BedarfsausweisWohnen, Enums, VerbrauchsausweisGewerbe } from "@ibcornelsen/database/client";
|
||||
|
||||
export let max: number = 2;
|
||||
export let name: string = ""
|
||||
|
||||
// Array of base64 encoded images read into the input.
|
||||
export let images: (File & { data: string })[] = [];
|
||||
export let ausweis: VerbrauchsausweisWohnen | VerbrauchsausweisGewerbe | BedarfsausweisWohnen;
|
||||
import { GebaeudeClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "./Ausweis/types";
|
||||
|
||||
export let images: UploadedGebaeudeBild[] = [];
|
||||
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbe | BedarfsausweisWohnen;
|
||||
export let gebaeude: GebaeudeClient;
|
||||
export let kategorie: Enums.BilderKategorie;
|
||||
|
||||
function getAllImages(this: HTMLInputElement) {
|
||||
const files = this.files || [];
|
||||
@@ -41,7 +46,7 @@
|
||||
let blob = new Blob([reader.result as ArrayBuffer]);
|
||||
let url = URL.createObjectURL(blob);
|
||||
let image = new Image();
|
||||
image.onload = () => {
|
||||
image.onload = async () => {
|
||||
// Create a new canvas with the desired output size
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = image.naturalWidth;
|
||||
@@ -57,25 +62,8 @@
|
||||
// Get the scaled-down data from the canvas in the desired output format and quality
|
||||
const dataURL = canvas.toDataURL("image/jpeg", 0.8);
|
||||
|
||||
|
||||
fetch("/api/image.json", {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
data: dataURL.split(';base64,')[1],
|
||||
name: file.name,
|
||||
kategorie: "",
|
||||
gebaeude_uid: ausweis.gebaeude_stammdaten_id
|
||||
})
|
||||
}).then(response => response.json()).then(json => {
|
||||
if (json.success === false) {
|
||||
return
|
||||
}
|
||||
|
||||
images.push({ ...file, data: dataURL as string } as (File & { data: string }));
|
||||
images = images;
|
||||
|
||||
ausweis.uid = json.data.gebaeude_uid;
|
||||
})
|
||||
images.push({ base64: dataURL as string, kategorie });
|
||||
images = images;
|
||||
|
||||
|
||||
if (i == (Math.min(files.length, max) - 1)) {
|
||||
@@ -92,7 +80,7 @@
|
||||
</script>
|
||||
|
||||
{#if max > 1}
|
||||
<input type="file" multiple on:change={getAllImages} />
|
||||
<input type="file" {name} multiple on:change={getAllImages} />
|
||||
{:else}
|
||||
<input type="file" on:change={getAllImages} />
|
||||
<input type="file" {name} on:change={getAllImages} />
|
||||
{/if}
|
||||
Reference in New Issue
Block a user