From e29b4f9d8d30971c93a140bba3d25a50861660e1 Mon Sep 17 00:00:00 2001 From: Pavel Vesely Date: Mon, 27 Apr 2020 22:43:24 +0200 Subject: [PATCH 1/2] Theme base components refactoring - clear of async warnings --- .../Themes/Controls/ModuleActionsBase.cs | 70 +++++++++++-------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/Oqtane.Client/Themes/Controls/ModuleActionsBase.cs b/Oqtane.Client/Themes/Controls/ModuleActionsBase.cs index c840128b..9dd748e6 100644 --- a/Oqtane.Client/Themes/Controls/ModuleActionsBase.cs +++ b/Oqtane.Client/Themes/Controls/ModuleActionsBase.cs @@ -14,9 +14,9 @@ namespace Oqtane.Themes.Controls { public class ModuleActionsBase : ContainerBase { - [Inject]public NavigationManager NavigationManager{get; set;} - [Inject]public IPageModuleService PageModuleService{get; set;} - + [Inject] public NavigationManager NavigationManager { get; set; } + [Inject] public IPageModuleService PageModuleService { get; set; } + protected List Actions; protected override void OnParametersSet() @@ -27,70 +27,78 @@ namespace Oqtane.Themes.Controls protected virtual List GetActions() { var actionList = new List(); - if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions)) + if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, ModuleState.Permissions)) { - - actionList.Add(new ActionViewModel {Name = "Manage Settings", Action = async (u,m) => Settings(u, m)}); - + actionList.Add(new ActionViewModel {Name = "Manage Settings", Action = async (u, m) => await Settings(u, m)}); + if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerManagerType != "") { - actionList.Add(new ActionViewModel {Name = "Import Content", Action = async(u,m)=> EditUrl(m.ModuleId, "Import")}); - actionList.Add(new ActionViewModel {Name = "Export Content", Action = async(u,m)=> EditUrl(m.ModuleId, "Export")}); + actionList.Add(new ActionViewModel {Name = "Import Content", Action = async (u, m) => await EditUrlAsync(u, m.ModuleId, "Import")}); + actionList.Add(new ActionViewModel {Name = "Export Content", Action = async (u, m) => await EditUrlAsync(u, m.ModuleId, "Export")}); } - - actionList.Add(new ActionViewModel {Name = "Delete Module" , Action = async (u,m) => await DeleteModule(u, m)}); - actionList.Add(new ActionViewModel {Name = "" }); - + + actionList.Add(new ActionViewModel {Name = "Delete Module", Action = async (u, m) => await DeleteModule(u, m)}); + actionList.Add(new ActionViewModel {Name = ""}); + if (ModuleState.PaneModuleIndex > 0) { - actionList.Add(new ActionViewModel {Name = "Move To Top" , Action = async (s,m) => await MoveTop(s, m)}); + actionList.Add(new ActionViewModel {Name = "Move To Top", Action = async (s, m) => await MoveTop(s, m)}); } - + if (ModuleState.PaneModuleIndex > 0) { - actionList.Add(new ActionViewModel {Name = "Move Up" , Action = async (s,m) => await MoveUp(s, m)}); + actionList.Add(new ActionViewModel {Name = "Move Up", Action = async (s, m) => await MoveUp(s, m)}); } - + if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1)) { - actionList.Add(new ActionViewModel {Name = "Move Down", Action = async (s,m) => await MoveDown(s, m) }); + actionList.Add(new ActionViewModel {Name = "Move Down", Action = async (s, m) => await MoveDown(s, m)}); } - + if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1)) { - actionList.Add(new ActionViewModel {Name = "Move To Bottom", Action = async (s,m) => await MoveBottom(s, m) }); + actionList.Add(new ActionViewModel {Name = "Move To Bottom", Action = async (s, m) => await MoveBottom(s, m)}); } - - foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + + foreach (string pane in PageState.Page.Panes.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries)) { if (pane != ModuleState.Pane) { - actionList.Add(new ActionViewModel {Name = "Move To " + pane + " Pane", Action = async (s,m) => await MoveToPane(s,pane, m) }); + actionList.Add(new ActionViewModel {Name = "Move To " + pane + " Pane", Action = async (s, m) => await MoveToPane(s, pane, m)}); } } } + return actionList; } + private async Task EditUrlAsync(string url, int moduleId, string import) + { + await Task.Yield(); + EditUrl(moduleId, import); + return url; + } + protected async Task ModuleAction(ActionViewModel action) { - if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions)) + if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, ModuleState.Permissions)) { PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); string url = NavigateUrl(); - if (action.Action!=null) + if (action.Action != null) { url = await action.Action(url, pagemodule); } + NavigationManager.NavigateTo(url); } } private async Task MoveToPane(string url, string newPane, PageModule pagemodule) { - string oldPane = pagemodule.Pane; + string oldPane = pagemodule.Pane; pagemodule.Pane = newPane; pagemodule.Order = int.MaxValue; // add to bottom of pane await PageModuleService.UpdatePageModuleAsync(pagemodule); @@ -99,7 +107,7 @@ namespace Oqtane.Themes.Controls return url; } - private async Task DeleteModule(string url,PageModule pagemodule) + private async Task DeleteModule(string url, PageModule pagemodule) { pagemodule.IsDeleted = true; await PageModuleService.UpdatePageModuleAsync(pagemodule); @@ -107,8 +115,9 @@ namespace Oqtane.Themes.Controls return url; } - private string Settings(string url, PageModule pagemodule) + private async Task Settings(string url, PageModule pagemodule) { + await Task.Yield(); url = EditUrl(pagemodule.ModuleId, "Settings"); return url; } @@ -120,7 +129,7 @@ namespace Oqtane.Themes.Controls await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane); return s; } - + private async Task MoveBottom(string s, PageModule pagemodule) { pagemodule.Order = int.MaxValue; @@ -128,6 +137,7 @@ namespace Oqtane.Themes.Controls await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane); return s; } + private async Task MoveUp(string s, PageModule pagemodule) { pagemodule.Order -= 3; @@ -135,6 +145,7 @@ namespace Oqtane.Themes.Controls await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane); return s; } + private async Task MoveDown(string s, PageModule pagemodule) { pagemodule.Order += 3; @@ -148,7 +159,6 @@ namespace Oqtane.Themes.Controls public string Name { set; get; } public Func> Action { set; get; } - } } } From 375c7060296b312dfea5c0e0d41f7d9c29fa0114 Mon Sep 17 00:00:00 2001 From: Pavel Vesely Date: Tue, 28 Apr 2020 14:51:27 +0200 Subject: [PATCH 2/2] Get custom theme and layout on a default install --- Oqtane.Client/UI/Installer.razor | 23 ------------------- .../Controllers/InstallationController.cs | 1 + .../Infrastructure/DatabaseManager.cs | 2 +- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/Oqtane.Client/UI/Installer.razor b/Oqtane.Client/UI/Installer.razor index bc537880..c20459b3 100644 --- a/Oqtane.Client/UI/Installer.razor +++ b/Oqtane.Client/UI/Installer.razor @@ -179,31 +179,8 @@ }; var installation = await InstallationService.Install(config); - //TODO: Should be moved to Database manager if (installation.Success) { - Site site = new Site(); - site.TenantId = -1; // will be populated on server - site.Name = "Default Site"; - site.LogoFileId = null; - site.FaviconFileId = null; - site.DefaultThemeType = Constants.DefaultTheme; - site.DefaultLayoutType = Constants.DefaultLayout; - site.DefaultContainerType = Constants.DefaultContainer; - site.PwaIsEnabled = false; - site.PwaAppIconFileId = null; - site.PwaSplashIconFileId = null; - site.AllowRegistration = false; - site = await SiteService.AddSiteAsync(site, null); - - User user = new User(); - user.SiteId = site.SiteId; - user.Username = _hostUsername; - user.Password = _hostPassword; - user.Email = _hostEmail; - user.DisplayName = _hostUsername; - user = await UserService.AddUserAsync(user); - NavigationManager.NavigateTo("", true); } else diff --git a/Oqtane.Server/Controllers/InstallationController.cs b/Oqtane.Server/Controllers/InstallationController.cs index c812c47e..713d065a 100644 --- a/Oqtane.Server/Controllers/InstallationController.cs +++ b/Oqtane.Server/Controllers/InstallationController.cs @@ -44,6 +44,7 @@ namespace Oqtane.Controllers _config.Reload(); } + _databaseManager.BuildDefaultSite(config.Password, config.HostEmail); installation.Success = true; return installation; } diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index bffd2f7f..a896a337 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -315,7 +315,7 @@ namespace Oqtane.Infrastructure } } - private void BuildDefaultSite(string password, string email) + public void BuildDefaultSite(string password, string email) { using (var scope = _serviceScopeFactory.CreateScope()) {