Started updating service feature with missing changes from AddServersFeature branch
This commit is contained in:
parent
681403ec6e
commit
0ec6949095
4 changed files with 21 additions and 22 deletions
|
@ -11,14 +11,14 @@ public class DummyServiceDefinition : ServiceDefinition
|
|||
public override Type ConfigType => typeof(DummyConfig);
|
||||
public override async Task BuildUserView(ServiceViewContext context)
|
||||
{
|
||||
context.Layout = ComponentHelper.FromType<DummyUser>();
|
||||
context.Layout = typeof(DummyUser);
|
||||
|
||||
await context.AddPage<DummyPage>("Demo", "/demo");
|
||||
}
|
||||
|
||||
public override Task BuildAdminView(ServiceViewContext context)
|
||||
{
|
||||
context.Layout = ComponentHelper.FromType<DummyAdmin>();
|
||||
context.Layout = typeof(DummyAdmin);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public class ServerServiceDefinition : ServiceDefinition
|
|||
public override Type ConfigType => typeof(ServerConfig);
|
||||
public override async Task BuildUserView(ServiceViewContext context)
|
||||
{
|
||||
context.Layout = ComponentHelper.FromType<UserLayout>();
|
||||
context.Layout = typeof(UserLayout);
|
||||
}
|
||||
|
||||
public override Task BuildAdminView(ServiceViewContext context)
|
||||
|
|
|
@ -15,7 +15,7 @@ public class ServiceViewContext
|
|||
|
||||
// Content
|
||||
public List<ServiceUiPage> Pages { get; set; } = new();
|
||||
public RenderFragment Layout { get; set; }
|
||||
public Type Layout { get; set; }
|
||||
|
||||
public Task AddPage<T>(string name, string route, string icon = "") where T : ComponentBase
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
@page "/service/{Id:int}/{Route?}"
|
||||
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using Moonlight.Core.Models.Enums
|
||||
@using Moonlight.Core.Helpers
|
||||
@using Moonlight.Core.Repositories
|
||||
@using Moonlight.Core.Services
|
||||
@using Moonlight.Features.ServiceManagement.Entities
|
||||
|
@ -19,22 +20,13 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
// An admin should still be able to manage the service, that's why we check for permissions here
|
||||
if (NeedsRenewal && !IdentityService.Permissions[Permission.AdminServices])
|
||||
if (NeedsRenewal)
|
||||
{
|
||||
<NeedsRenewalAlert />
|
||||
}
|
||||
else
|
||||
{
|
||||
<CascadingValue Name="Service" Value="Service">
|
||||
<CascadingValue Name="Implementation" Value="Definition">
|
||||
<CascadingValue Name="Route" Value="Route">
|
||||
<CascadingValue Name="ViewContext" Value="ViewContext">
|
||||
@ViewContext.Layout
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
</CascadingValue>
|
||||
@Layout
|
||||
}
|
||||
}
|
||||
</LazyLoader>
|
||||
|
@ -51,7 +43,9 @@
|
|||
private ServiceDefinition Definition;
|
||||
private ServiceViewContext ViewContext;
|
||||
|
||||
private bool NeedsRenewal;
|
||||
private bool NeedsRenewal = false;
|
||||
|
||||
private RenderFragment Layout;
|
||||
|
||||
private async Task Load(LazyLoader lazyLoader)
|
||||
{
|
||||
|
@ -74,12 +68,9 @@
|
|||
if (Service == null)
|
||||
return;
|
||||
|
||||
// Check expiration
|
||||
NeedsRenewal = await ServiceService.Manage.NeedsRenewal(Service);
|
||||
|
||||
// Stop loading more data if the user is not an admin
|
||||
// because a admin should still be able to manage the service
|
||||
if(NeedsRenewal && !IdentityService.Permissions[Permission.AdminServices])
|
||||
if(NeedsRenewal) // Stop loading more data
|
||||
return;
|
||||
|
||||
// Load implementation
|
||||
|
@ -98,5 +89,13 @@
|
|||
|
||||
await Definition.BuildUserView(ViewContext);
|
||||
await PluginService.BuildUserServiceView(ViewContext);
|
||||
|
||||
Layout = ComponentHelper.FromType(ViewContext.Layout, parameters =>
|
||||
{
|
||||
parameters.Add("Service", Service);
|
||||
parameters.Add("Implementation", Definition);
|
||||
parameters.Add("Route", Route!);
|
||||
parameters.Add("ViewContext", ViewContext);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue