diff --git a/LANCommander.Server/UI/Pages/Redistributables/Components/RedistributableEditView.razor b/LANCommander.Server/UI/Pages/Redistributables/Components/RedistributableEditView.razor new file mode 100644 index 00000000..ee9256e2 --- /dev/null +++ b/LANCommander.Server/UI/Pages/Redistributables/Components/RedistributableEditView.razor @@ -0,0 +1,78 @@ +@using Microsoft.EntityFrameworkCore +@inject DatabaseServiceFactory DatabaseServiceFactory +@inject NavigationManager NavigationManager + + + + + General + + @if (Redistributable?.Id != Guid.Empty) + { + Archives + Scripts + } + + + + + + + + @if (TitleTemplate != null) + { + @TitleTemplate(Redistributable) + } + else { + @Title + } + + + + @TitleExtraTemplate?.Invoke(Redistributable) + + + + + + @ChildContent?.Invoke(Redistributable) + + + + +@code { + [Parameter] public Guid Id { get; set; } + [Parameter] public string Title { get; set; } + [Parameter] public RenderFragment? TitleTemplate { get; set; } + [Parameter] public RenderFragment? TitleExtraTemplate { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } + + Redistributable Redistributable { get; set; } = new(); + Guid _id; + + protected override async Task OnParametersSetAsync() + { + if (_id != Id) + { + _id = Id; + + using (var redistributableService = DatabaseServiceFactory.Create()) + { + if (_id != Guid.Empty) + Redistributable = await redistributableService + .Query(query => + { + return query + .Include(g => g.CreatedBy) + .Include(g => g.UpdatedBy); + }) + .GetAsync(_id); + else + Redistributable = new(); + } + + if (Redistributable == null) + NavigationManager.NavigateTo("/Redistributables"); + } + } +} \ No newline at end of file diff --git a/LANCommander.Server/UI/Pages/Redistributables/Edit.razor b/LANCommander.Server/UI/Pages/Redistributables/Edit.razor deleted file mode 100644 index f9fa970e..00000000 --- a/LANCommander.Server/UI/Pages/Redistributables/Edit.razor +++ /dev/null @@ -1,179 +0,0 @@ -@page "/Redistributables/{id:guid}" -@page "/Redistributables/{id:guid}/{panel}" -@page "/Redistributables/Add" -@using LANCommander.SDK.Enums -@using LANCommander.Server.Models -@using Microsoft.EntityFrameworkCore -@attribute [Authorize(Roles = RoleService.AdministratorRoleName)] -@inject DatabaseServiceFactory DatabaseServiceFactory -@inject IMessageService MessageService -@inject NavigationManager NavigationManager -@inject ILogger Logger - - - - - General - - @if (Redistributable?.Id != Guid.Empty) - { - Scripts - Archives - } - - - - - - - @if (Id == Guid.Empty) - { - Add New Redistributable - } - else - { - @Panel - } - - - - @if (Redistributable != null && Redistributable.Id != Guid.Empty) - { - Export - } - - Save - - - - - - - - - - - - - - - - - - - - - - - - - - - @if (Redistributable != null && Redistributable.Id != Guid.Empty) - { - - - - - - - - } - - - - -@if (!String.IsNullOrWhiteSpace(Panel)) -{ - -} -else -{ - -} - -@code { - [Parameter] public Guid Id { get; set; } - [Parameter] public string Panel { get; set; } - - Redistributable Redistributable = new Redistributable(); - - ICollection Games; - - Settings Settings = SettingService.GetSettings(); - - Guid LatestArchiveId - { - get - { - if (Redistributable != null && Redistributable.Archives != null && Redistributable.Archives.Count > 0) - return Redistributable.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Id; - else - return Guid.Empty; - } - } - - protected override async Task OnInitializedAsync() - { - using (var redistributableService = DatabaseServiceFactory.Create()) - { - if (Id != Guid.Empty && Panel == null) - NavigationManager.NavigateTo($"/Redistributables/{Id}/General", true); - else if (Id != Guid.Empty) - Redistributable = await redistributableService - .Include(r => r.Games) - .GetAsync(Id); - } - - using (var gameService = DatabaseServiceFactory.Create()) - { - Games = await gameService - .SortBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle) - .GetAsync(g => g.Type == GameType.MainGame || g.Type == GameType.StandaloneExpansion || g.Type == GameType.StandaloneMod || g.BaseGame == null); - } - } - - async Task Save() - { - try - { - using (var redistributableService = DatabaseServiceFactory.Create()) - { - if (Redistributable.Id != Guid.Empty) - { - Redistributable = await redistributableService.UpdateAsync(Redistributable); - - await MessageService.Success("Redistributable updated!"); - } - else - { - Redistributable = await redistributableService.AddAsync(Redistributable); - - NavigationManager.LocationChanged += NotifyRedistributableAdded; - - NavigationManager.NavigateTo($"/Redistributables/{Redistributable.Id}"); - } - } - } - catch (Exception ex) - { - MessageService.Error("Could not save!"); - Logger.LogError(ex, "Could not save!"); - } - } - - void NotifyRedistributableAdded(object? sender, LocationChangedEventArgs e) - { - NavigationManager.LocationChanged -= NotifyRedistributableAdded; - - MessageService.Success("Redistributable added!"); - } -} \ No newline at end of file diff --git a/LANCommander.Server/UI/Pages/Redistributables/Edit/Archives.razor b/LANCommander.Server/UI/Pages/Redistributables/Edit/Archives.razor new file mode 100644 index 00000000..31df9ae6 --- /dev/null +++ b/LANCommander.Server/UI/Pages/Redistributables/Edit/Archives.razor @@ -0,0 +1,11 @@ +@page "/Redistributables/{id:guid}/Archives" +@using LANCommander.Server.UI.Pages.Redistributables.Components +@attribute [Authorize(Roles = RoleService.AdministratorRoleName)] + + + + + +@code { + [Parameter] public Guid Id { get; set; } +} \ No newline at end of file diff --git a/LANCommander.Server/UI/Pages/Redistributables/Edit/General.razor b/LANCommander.Server/UI/Pages/Redistributables/Edit/General.razor new file mode 100644 index 00000000..edb9eb41 --- /dev/null +++ b/LANCommander.Server/UI/Pages/Redistributables/Edit/General.razor @@ -0,0 +1,133 @@ +@page "/Redistributables/{id:guid}" +@page "/Redistributables/{id:guid}/General" +@page "/Redistributables/Add" +@using LANCommander.SDK.Enums +@using LANCommander.Server.UI.Pages.Redistributables.Components +@attribute [Authorize(Roles = RoleService.AdministratorRoleName)] +@inject DatabaseServiceFactory DatabaseServiceFactory +@inject IMessageService MessageService +@inject NavigationManager NavigationManager +@inject ILogger Logger + + + + @if (Id == Guid.Empty) + { + Add New Redistributable + } + else + { + General + } + + + + @if (context != null && context.Id != Guid.Empty) + { + + + + + Full + + + Metadata + + + + + Export + + + } + + Save + + + + + + + + + + + + + + + + + + + + + + + +@code { + [Parameter] public Guid Id { get; set; } + + Redistributable Redistributable = new(); + + ICollection Games; + + protected override async Task OnInitializedAsync() + { + if (Id != Guid.Empty) + { + using (var redistributableService = DatabaseServiceFactory.Create()) + { + Redistributable = await redistributableService + .Include(r => r.Archives) + .Include(r => r.Games) + .Include(r => r.Scripts) + .GetAsync(Id); + } + } + + using (var gameService = DatabaseServiceFactory.Create()) + { + Games = await gameService + .Include(g => g.Media) + .SortBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle) + .GetAsync(g => g.Type == GameType.MainGame || g.Type == GameType.StandaloneExpansion || g.Type == GameType.StandaloneMod || g.BaseGame == null); + } + } + + async Task Save(Redistributable redistributable) + { + try + { + using (var redistributableService = DatabaseServiceFactory.Create()) + { + if (Redistributable.Id != Guid.Empty) + { + Redistributable = await redistributableService.UpdateAsync(redistributable); + + await MessageService.Success("Redistributable updated!"); + } + else + { + Redistributable = await redistributableService.AddAsync(redistributable); + + NavigationManager.LocationChanged += NotifyRedistributableAdded; + + NavigationManager.NavigateTo($"/Redistributables/{redistributable.Id}"); + } + } + } + catch (Exception ex) + { + MessageService.Error("Could not save!"); + Logger.LogError(ex, "Could not save!"); + } + } + + void NotifyRedistributableAdded(object? sender, LocationChangedEventArgs e) + { + NavigationManager.LocationChanged -= NotifyRedistributableAdded; + + MessageService.Success("Redistributable added!"); + } +} \ No newline at end of file diff --git a/LANCommander.Server/UI/Pages/Redistributables/Edit/Scripts.razor b/LANCommander.Server/UI/Pages/Redistributables/Edit/Scripts.razor new file mode 100644 index 00000000..ff83235f --- /dev/null +++ b/LANCommander.Server/UI/Pages/Redistributables/Edit/Scripts.razor @@ -0,0 +1,41 @@ +@page "/Redistributables/{id:guid}/Scripts" +@using LANCommander.SDK.Enums +@using LANCommander.Server.UI.Pages.Redistributables.Components +@attribute [Authorize(Roles = RoleService.AdministratorRoleName)] +@inject DatabaseServiceFactory DatabaseServiceFactory +@inject NavigationManager NavigationManager + + + + + +@code { + [Parameter] public Guid Id { get; set; } + [Parameter] public string Panel { get; set; } + + Redistributable Redistributable = new(); + + Guid LatestArchiveId + { + get + { + if (Redistributable != null && Redistributable.Archives != null && Redistributable.Archives.Count > 0) + return Redistributable.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Id; + else + return Guid.Empty; + } + } + + protected override async Task OnInitializedAsync() + { + using (var redistributableService = DatabaseServiceFactory.Create()) + { + if (Id == Guid.Empty) + NavigationManager.NavigateTo($"/Redistributables", true); + else + Redistributable = await redistributableService + .Include(r => r.Archives) + .GetAsync(Id); + } + } +} \ No newline at end of file diff --git a/LANCommander.Server/UI/Pages/Redistributables/Index.razor b/LANCommander.Server/UI/Pages/Redistributables/Index.razor index 6d2277f7..b94a0a24 100644 --- a/LANCommander.Server/UI/Pages/Redistributables/Index.razor +++ b/LANCommander.Server/UI/Pages/Redistributables/Index.razor @@ -24,7 +24,7 @@ - Edit + Edit