diff --git a/FilterCair.Client/Pages/FilterForm.razor b/FilterCair.Client/Pages/FilterForm.razor index db8f2a5..d65d6a3 100644 --- a/FilterCair.Client/Pages/FilterForm.razor +++ b/FilterCair.Client/Pages/FilterForm.razor @@ -19,23 +19,20 @@ +
-
- +
-
- +
-
- +
-
@@ -45,72 +42,75 @@
-
-
-
- +
-
-
+ +
+
+
+ Fotos (@filter.Photos.Count) +
+ +
+ + @if (filter.Photos.Any()) + { +
+ @foreach (var photo in filter.Photos) + { +
+
+ + +
+
+ } +
+ } + else + { +
+ +

Noch keine Fotos – tippe auf "Foto aufnehmen"

+
+ } +
+ +
- - @if (showToast) - { -
-
-
-
- ✅ Filterdaten erfolgreich gespeichert! -
-
-
-
- }
@code { - private FilterModel filter = new(); - private bool showToast; - - private async Task SaveForm() - { - bool success = await FilterService.SaveFilterAsync(filter); - if (success) - { - await JS.InvokeVoidAsync("showToast", "✅ Offline gespeichert – wird synchronisiert!", "success"); - NavManager.NavigateTo($"/stations/{filter.CustomerId}/filters/{filter.StationId}"); - } - else - { - await JS.InvokeVoidAsync("showToast", "Fehler", "error"); - } - } - + private FilterModel filter = new() { Photos = new List() }; protected override async Task OnInitializedAsync() { var uri = NavManager.ToAbsoluteUri(NavManager.Uri); var query = System.Web.HttpUtility.ParseQueryString(uri.Query); - // Standardwerte setzen if (int.TryParse(query.Get("customerId"), out int customerId)) filter.CustomerId = customerId; @@ -123,11 +123,44 @@ if (existing != null) { filter = existing; - StateHasChanged(); + // Sicherstellen, dass Photos existieren + filter.Photos ??= new List(); } } } + private async Task TakePhoto() + { + try + { + var photoBase64 = await JS.InvokeAsync("takePhoto"); + if (!string.IsNullOrEmpty(photoBase64)) + { + filter.Photos.Add(photoBase64); + StateHasChanged(); + await JS.InvokeVoidAsync("showToast", "Foto hinzugefügt!", "success"); + } + } + catch (Exception ex) + { + await JS.InvokeVoidAsync("showToast", "Kamera-Fehler", "error"); + Console.WriteLine(ex); + } + } + private void RemovePhoto(string photo) + { + filter.Photos.Remove(photo); + StateHasChanged(); + } -} + private async Task SaveForm() + { + bool success = await FilterService.SaveFilterAsync(filter); + if (success) + { + await JS.InvokeVoidAsync("showToast", "Filter + Fotos gespeichert!", "success"); + NavManager.NavigateTo($"/stations/{filter.CustomerId}/filters/{filter.StationId}"); + } + } +} \ No newline at end of file diff --git a/FilterCair.Client/wwwroot/index.html b/FilterCair.Client/wwwroot/index.html index 5417535..35bfff4 100644 --- a/FilterCair.Client/wwwroot/index.html +++ b/FilterCair.Client/wwwroot/index.html @@ -47,6 +47,7 @@ + diff --git a/FilterCair.Client/wwwroot/js/camera.js b/FilterCair.Client/wwwroot/js/camera.js new file mode 100644 index 0000000..c7c94a5 --- /dev/null +++ b/FilterCair.Client/wwwroot/js/camera.js @@ -0,0 +1,17 @@ +window.takePhoto = async () => { + const video = document.createElement('video'); + const canvas = document.createElement('canvas'); + const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }); + video.srcObject = stream; + video.play(); + + return new Promise((resolve) => { + video.onloadedmetadata = () => { + canvas.width = video.videoWidth; + canvas.height = video.videoHeight; + canvas.getContext('2d').drawImage(video, 0, 0); + stream.getTracks().forEach(t => t.stop()); + resolve(canvas.toDataURL('image/jpeg', 0.8)); + }; + }); +}; \ No newline at end of file diff --git a/FilterCair.Shared/Models/FilterModel.cs b/FilterCair.Shared/Models/FilterModel.cs index 03f32dc..7e4b2dc 100644 --- a/FilterCair.Shared/Models/FilterModel.cs +++ b/FilterCair.Shared/Models/FilterModel.cs @@ -19,5 +19,7 @@ namespace FilterCair.Shared.Models public DateTime? LetzteWartung { get; set; } public string Zustand { get; set; } = string.Empty; public string QRCode { get; set; } = string.Empty; + //Bilder + public List Photos { get; set; } = new(); } }