more stuff

This commit is contained in:
2026-05-01 19:48:34 -05:00
parent e1d437fd49
commit 7e767541cf
18 changed files with 1292 additions and 319 deletions

View File

@@ -1,13 +1,17 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace ApplianceRepair.Components.Pages.admin
{
public partial class Admin(HomePageReader homePageReader, ContentCardReader contentCardReader, BusinessConfigReader businessConfigReader, RepairRequestReader repairRequestReader) : ComponentBase
public partial class Admin(HomePageReader homePageReader, ContentCardReader contentCardReader, BusinessConfigReader businessConfigReader, RepairRequestReader repairRequestReader, RepairRequestMediaReader repairRequestMediaReader) : ComponentBase
{
public HomePageModel? HomePageModel;
public BusinessInfoModel? BusinessInfo;
public List<RepairRequestModel>? RepairRequests;
public List<RepairRequestMediaRecord>? SelectedRequestMedia;
public int SelectedRequestMediaImageIndex = 0;
private enum AdminTab { Home, Requests, BusinessInfo }
private AdminTab CurrentTab = AdminTab.Home;
@@ -28,6 +32,29 @@ namespace ApplianceRepair.Components.Pages.admin
});
}
private async void RefreshContentCards()
{
if (HomePageModel == null)
{
return;
}
var servicesList = await contentCardReader.ReadAllByPageAndGroup(HomePageModel.PageName, nameof(HomePageModel.ContentCardTypes.Services)) ?? [];
var trustList = await contentCardReader.ReadAllByPageAndGroup(HomePageModel.PageName, nameof(HomePageModel.ContentCardTypes.Trust)) ?? [];
HomePageModel.ServicesCards.Clear();
foreach (var card in servicesList)
{
HomePageModel.ServicesCards.Add(new ContentCardModel(card));
}
HomePageModel.TrustCards.Clear();
foreach (var card in trustList)
{
HomePageModel.TrustCards.Add(new ContentCardModel(card));
}
}
private async void RevertHomePageModel()
{
var businessConfig = await businessConfigReader.ReadLatestRecord() ?? Defaults.DefaultBusinessConfig;
@@ -69,6 +96,12 @@ namespace ApplianceRepair.Components.Pages.admin
await businessConfigReader.UpdateRecord(BusinessInfo);
}
private async Task DeleteContentCard(ContentCardModel card)
{
await contentCardReader.DeleteRecord(card);
RefreshContentCards();
}
private void AddServiceCard()
{
HomePageModel?.ServicesCards.Add(new ContentCardModel() {
@@ -93,5 +126,58 @@ namespace ApplianceRepair.Components.Pages.admin
Text = "Short Description"
});
}
private async Task ViewRequestImages(RepairRequestModel request)
{
if (!string.IsNullOrEmpty(request.RequestNumber))
{
SelectedRequestMedia = await repairRequestMediaReader.ReadAllByRequestNumber(request.RequestNumber);
SelectedRequestMediaImageIndex = 0;
await JS.InvokeVoidAsync("eval", $"document.getElementById('imageViewerModal').showModal()");
}
}
private async Task CloseImageViewer()
{
await JS.InvokeVoidAsync("eval", $"document.getElementById('imageViewerModal').close()");
SelectedRequestMedia = [];
}
private async Task ImageViewerModal_PrevImage()
{
if (SelectedRequestMedia == null) return;
SelectedRequestMediaImageIndex++;
if (SelectedRequestMediaImageIndex >= SelectedRequestMedia.Count())
{
SelectedRequestMediaImageIndex = 0;
}
}
private async Task ImageViewerModal_NextImage()
{
if (SelectedRequestMedia == null) return;
SelectedRequestMediaImageIndex--;
if (SelectedRequestMediaImageIndex < 0)
{
SelectedRequestMediaImageIndex = SelectedRequestMedia.Count() - 1;
}
}
private string GetWebPath(string fullPath = "")
{
if (string.IsNullOrEmpty(fullPath)) return "";
var marker = "wwwroot";
var index = fullPath.IndexOf(marker);
if (index != -1)
{
// Returns "/uploads/filename.jpg"
return fullPath.Substring(index + marker.Length).Replace('\\', '/');
}
return fullPath;
}
}
}