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