Merge pull request #3969 from sbwalker/dev

consolidate Clone logic for Resource objects
This commit is contained in:
Shaun Walker 2024-03-08 19:33:23 -05:00 committed by GitHub
commit df1690515c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 53 additions and 38 deletions

View File

@ -271,7 +271,7 @@
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
// repopulate the SiteState service based on the values passed in the SiteState parameter (this is how state is marshalled across the render mode boundary) // repopulate the SiteState service based on the values passed in the SiteState parameter (this is how state is marshalled across the render mode boundary)
ComponentSiteState.Clone(SiteState); ComponentSiteState.Hydrate(SiteState);
_canViewAdminDashboard = CanViewAdminDashboard(); _canViewAdminDashboard = CanViewAdminDashboard();
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.PermissionList)) if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.PermissionList))

View File

@ -71,7 +71,7 @@
if (ModuleType != null) if (ModuleType != null)
{ {
// repopulate the SiteState service based on the values passed in the SiteState parameter (this is how state is marshalled across the render mode boundary) // repopulate the SiteState service based on the values passed in the SiteState parameter (this is how state is marshalled across the render mode boundary)
ComponentSiteState.Clone(SiteState); ComponentSiteState.Hydrate(SiteState);
DynamicComponent = builder => DynamicComponent = builder =>
{ {

View File

@ -569,21 +569,22 @@
// ensure resource does not exist already // ensure resource does not exist already
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower())) if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
{ {
pageresources.Add(new Resource pageresources.Add(resource.Clone(level, name));
{ // pageresources.Add(new Resource
ResourceType = resource.ResourceType, // {
Url = resource.Url, // ResourceType = resource.ResourceType,
Integrity = resource.Integrity, // Url = resource.Url,
CrossOrigin = resource.CrossOrigin, // Integrity = resource.Integrity,
Bundle = resource.Bundle, // CrossOrigin = resource.CrossOrigin,
Location = resource.Location, // Bundle = resource.Bundle,
ES6Module = resource.ES6Module, // Location = resource.Location,
Content = resource.Content, // ES6Module = resource.ES6Module,
RenderMode = resource.RenderMode, // Content = resource.Content,
Reload = resource.Reload, // RenderMode = resource.RenderMode,
Level = level, // Reload = resource.Reload,
Namespace = name // Level = level,
}); // Namespace = name
// });
} }
} }
} }

View File

@ -681,21 +681,22 @@
// ensure resource does not exist already // ensure resource does not exist already
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower())) if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
{ {
pageresources.Add(new Resource pageresources.Add(resource.Clone(level, name));
{ // pageresources.Add(new Resource
ResourceType = resource.ResourceType, // {
Url = resource.Url, // ResourceType = resource.ResourceType,
Integrity = resource.Integrity, // Url = resource.Url,
CrossOrigin = resource.CrossOrigin, // Integrity = resource.Integrity,
Bundle = resource.Bundle, // CrossOrigin = resource.CrossOrigin,
Location = resource.Location, // Bundle = resource.Bundle,
ES6Module = resource.ES6Module, // Location = resource.Location,
Content = resource.Content, // ES6Module = resource.ES6Module,
RenderMode = resource.RenderMode, // Content = resource.Content,
Reload = resource.Reload, // RenderMode = resource.RenderMode,
Level = level, // Reload = resource.Reload,
Namespace = name // Level = level,
}); // Namespace = name
// });
} }
} }
} }

View File

@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace Oqtane.Models namespace Oqtane.Models

View File

@ -77,6 +77,24 @@ namespace Oqtane.Models
/// </summary> /// </summary>
public string Namespace { get; set; } public string Namespace { get; set; }
public Resource Clone(ResourceLevel level, string name)
{
var resource = new Resource();
resource.ResourceType = ResourceType;
resource.Url = Url;
resource.Integrity = Integrity;
resource.CrossOrigin = CrossOrigin;
resource.Bundle = Bundle;
resource.Location = Location;
resource.ES6Module = ES6Module;
resource.Content = Content;
resource.RenderMode = RenderMode;
resource.Reload = Reload;
resource.Level = level;
resource.Namespace = name;
return resource;
}
[Obsolete("ResourceDeclaration is deprecated", false)] [Obsolete("ResourceDeclaration is deprecated", false)]
public ResourceDeclaration Declaration { get; set; } public ResourceDeclaration Declaration { get; set; }
} }

View File

@ -1,6 +1,3 @@
using System.Net;
using System.Xml.Linq;
using System;
using Oqtane.Models; using Oqtane.Models;
namespace Oqtane.Shared namespace Oqtane.Shared
@ -31,7 +28,7 @@ namespace Oqtane.Shared
} }
} }
public void Clone(SiteState siteState) public void Hydrate(SiteState siteState)
{ {
Alias = siteState.Alias; Alias = siteState.Alias;
AntiForgeryToken = siteState.AntiForgeryToken; AntiForgeryToken = siteState.AntiForgeryToken;