Gallery verwendet Datenbank
- Menü: Fixed typo in Gallerie - Datenbanken-Funktionen dokumentiert
This commit is contained in:
@ -1,5 +1,11 @@
|
||||
@page "/gallery"
|
||||
|
||||
@using DataAccess.Data
|
||||
@using DataAccess.Models
|
||||
|
||||
@inject BildInfoData BildInfoData;
|
||||
@inject WunschInfoData WunschInfoData;
|
||||
|
||||
<style>
|
||||
.image-grid {
|
||||
background-color: white; /* Hintergrund der RadzenDataList weiß machen */
|
||||
@ -57,12 +63,12 @@
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<RadzenDataList WrapItems="@true" AllowPaging="true" Data="@imagePaths" PageSize="20" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true" class="image-grid">
|
||||
<Template Context="imagePath">
|
||||
<RadzenDataList WrapItems="@true" AllowPaging="true" Data="@_bildInfos" PageSize="20" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true" class="image-grid">
|
||||
<Template Context="bildInfo">
|
||||
<div class="image-grid-item">
|
||||
<RadzenCard Style="width: 200px; height: 200px; padding: 0; border: none;">
|
||||
<RadzenButton Click="@(args => ShowImageInfo(imagePath))">
|
||||
<RadzenImage Src="@imagePath" Style="width: 100%; height: 100%; object-fit: cover;" />
|
||||
<RadzenButton Click="@(args => ShowImageInfo(bildInfo))">
|
||||
<RadzenImage Src="@bildInfo.Dateiname" Style="width: 100%; height: 100%; object-fit: cover;" />
|
||||
</RadzenButton>
|
||||
</RadzenCard>
|
||||
</div>
|
||||
@ -83,63 +89,26 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
List<string> imagePaths = new List<string>();
|
||||
string selectedImage;
|
||||
string infoText = "Info Text";
|
||||
string popupStyle = "display: none;";
|
||||
|
||||
IEnumerable<BildInfoModel>? _bildInfos;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
// Get the physical path to the folder
|
||||
string folderPath = Path.Combine(_environment.WebRootPath, "generated_images");
|
||||
|
||||
if (Directory.Exists(folderPath))
|
||||
{
|
||||
// Load the image file names from the folder
|
||||
var imageFiles = Directory.GetFiles(folderPath, "*.jpg");
|
||||
|
||||
// Get the relative paths to the images
|
||||
imagePaths = imageFiles.Select(file => file.Replace(_environment.WebRootPath, "").Replace("\\", "/")).ToList();
|
||||
}
|
||||
_bildInfos = await BildInfoData.GetAllBildInfosAsync();
|
||||
}
|
||||
|
||||
private async void ShowImageInfo(string imagePath)
|
||||
private async void ShowImageInfo(BildInfoModel bildInfo)
|
||||
{
|
||||
selectedImage = imagePath;
|
||||
selectedImage = bildInfo.Dateiname;
|
||||
popupStyle = "display: block;";
|
||||
infoText = await GetInfoTextForImageAsync(imagePath);
|
||||
}
|
||||
|
||||
|
||||
private async Task<string> GetInfoTextForImageAsync(string imagePath)
|
||||
{
|
||||
// Bestimme den Ordnerpfad, in dem sich die Bilder und die info_texts.txt Datei befinden
|
||||
string folderPath = Path.Combine(_environment.WebRootPath, "generated_images");
|
||||
|
||||
// Bestimme den Pfad zur info_texts.txt Datei
|
||||
string infoTextsFilePath = Path.Combine(folderPath, "info_texts.txt");
|
||||
|
||||
// Überprüfe, ob die Datei existiert
|
||||
if (!File.Exists(infoTextsFilePath))
|
||||
return $"Kein Infotext für {imagePath} gefunden.";
|
||||
|
||||
// Lies alle Zeilen der Datei
|
||||
var lines = await File.ReadAllLinesAsync(infoTextsFilePath);
|
||||
string adaptedImagePath = imagePath.Substring(1) + ":";
|
||||
|
||||
// Durchsuche jede Zeile nach dem gegebenen imagePath
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith(adaptedImagePath)) // Überprüft, ob die Zeile mit dem Dateinamen des Bildes beginnt
|
||||
{
|
||||
// Trenne den Dateinamen und den Infotext und gib den Infotext zurück
|
||||
return line.Split(new[] { ':' }, 2).LastOrDefault()?.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
return $"Kein Infotext für {imagePath} gefunden.";
|
||||
WunschInfoModel wunschInfo = await WunschInfoData.GetWunschInfoAsync(bildInfo.WunschId);
|
||||
infoText = wunschInfo.BildBeschreibung;
|
||||
}
|
||||
|
||||
private void CloseImageInfo()
|
||||
|
||||
Reference in New Issue
Block a user