diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index f6263f33..b5db984a 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -240,243 +240,249 @@ } @code { - private ElementReference form; - private bool validated = false; - private bool _initialized = false; - private List _themeList; - private List _themes = new List(); - private List _containers = new List(); - private string _name = string.Empty; - private List _aliasList; - private string _urls = string.Empty; - private string _runtime = ""; - private string _prerender = ""; - private int _logofileid = -1; - private FileManager _logofilemanager; - private int _faviconfileid = -1; - private FileManager _faviconfilemanager; - private string _themetype = "-"; - private string _containertype = "-"; - private string _admincontainertype = "-"; - private string _allowregistration; - private string _smtphost = string.Empty; - private string _smtpport = string.Empty; - private string _smtpssl = "False"; - private string _smtpusername = string.Empty; - private string _smtppassword = string.Empty; - private string _smtpsender = string.Empty; - private string _pwaisenabled; - private int _pwaappiconfileid = -1; - private FileManager _pwaappiconfilemanager; - private int _pwasplashiconfileid = -1; - private FileManager _pwasplashiconfilemanager; - private string _tenant = string.Empty; - private string _database = string.Empty; - private string _connectionstring = string.Empty; - private string _createdby; - private DateTime _createdon; - private string _modifiedby; - private DateTime _modifiedon; - private string _deletedby; - private DateTime? _deletedon; - private string _isdeleted; + private ElementReference form; + private bool validated = false; + private bool _initialized = false; + private List _themeList; + private List _themes = new List(); + private List _containers = new List(); + private string _name = string.Empty; + private List _aliasList; + private string _urls = string.Empty; + private string _runtime = ""; + private string _prerender = ""; + private int _logofileid = -1; + private FileManager _logofilemanager; + private int _faviconfileid = -1; + private FileManager _faviconfilemanager; + private string _themetype = "-"; + private string _containertype = "-"; + private string _admincontainertype = "-"; + private string _allowregistration; + private string _smtphost = string.Empty; + private string _smtpport = string.Empty; + private string _smtpssl = "False"; + private string _smtpusername = string.Empty; + private string _smtppassword = string.Empty; + private string _smtpsender = string.Empty; + private string _pwaisenabled; + private int _pwaappiconfileid = -1; + private FileManager _pwaappiconfilemanager; + private int _pwasplashiconfileid = -1; + private FileManager _pwasplashiconfilemanager; + private string _tenant = string.Empty; + private string _database = string.Empty; + private string _connectionstring = string.Empty; + private string _createdby; + private DateTime _createdon; + private string _modifiedby; + private DateTime _modifiedon; + private string _deletedby; + private DateTime? _deletedon; + private string _isdeleted; - public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; - protected override async Task OnInitializedAsync() - { - try - { - _themeList = await ThemeService.GetThemesAsync(); - Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId); - if (site != null) - { - _name = site.Name; - _runtime = site.Runtime; - _prerender = site.RenderMode.Replace(_runtime, ""); - _allowregistration = site.AllowRegistration.ToString(); - _isdeleted = site.IsDeleted.ToString(); + protected override async Task OnInitializedAsync() + { + try + { + _themeList = await ThemeService.GetThemesAsync(); + Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId); + if (site != null) + { + _name = site.Name; + _runtime = site.Runtime; + _prerender = site.RenderMode.Replace(_runtime, ""); + _allowregistration = site.AllowRegistration.ToString(); + _isdeleted = site.IsDeleted.ToString(); - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - _aliasList = await AliasService.GetAliasesAsync(); - foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) - { - _urls += alias.Name + ","; - } - _urls = _urls.Substring(0, _urls.Length - 1); + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + _aliasList = await AliasService.GetAliasesAsync(); + foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) + { + _urls += alias.Name + ","; + } + _urls = _urls.Substring(0, _urls.Length - 1); - } + } - if (site.LogoFileId != null) - { - _logofileid = site.LogoFileId.Value; - } + if (site.LogoFileId != null) + { + _logofileid = site.LogoFileId.Value; + } - if (site.FaviconFileId != null) - { - _faviconfileid = site.FaviconFileId.Value; - } + if (site.FaviconFileId != null) + { + _faviconfileid = site.FaviconFileId.Value; + } - _themes = ThemeService.GetThemeControls(_themeList); - _themetype = (!string.IsNullOrEmpty(site.DefaultThemeType)) ? site.DefaultThemeType : Constants.DefaultTheme; - _containers = ThemeService.GetContainerControls(_themeList, _themetype); - _containertype = (!string.IsNullOrEmpty(site.DefaultContainerType)) ? site.DefaultContainerType : Constants.DefaultContainer; - _admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer; + _themes = ThemeService.GetThemeControls(_themeList); + _themetype = (!string.IsNullOrEmpty(site.DefaultThemeType)) ? site.DefaultThemeType : Constants.DefaultTheme; + _containers = ThemeService.GetContainerControls(_themeList, _themetype); + _containertype = (!string.IsNullOrEmpty(site.DefaultContainerType)) ? site.DefaultContainerType : Constants.DefaultContainer; + _admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer; - var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); - _smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty); - _smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty); - _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "False"); - _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty); - _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty); - _smtpsender = SettingService.GetSetting(settings, "SMTPSender", string.Empty); + _pwaisenabled = site.PwaIsEnabled.ToString(); + if (site.PwaAppIconFileId != null) + { + _pwaappiconfileid = site.PwaAppIconFileId.Value; + } + if (site.PwaSplashIconFileId != null) + { + _pwasplashiconfileid = site.PwaSplashIconFileId.Value; + } + + var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); + _smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty); + _smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty); + _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "False"); + _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty); + _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty); + _smtpsender = SettingService.GetSetting(settings, "SMTPSender", string.Empty); - _pwaisenabled = site.PwaIsEnabled.ToString(); + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + var tenants = await TenantService.GetTenantsAsync(); + var _databases = await DatabaseService.GetDatabasesAsync(); + var tenant = tenants.Find(item => item.TenantId == site.TenantId); + if (tenant != null) + { + _tenant = tenant.Name; + _database = _databases.Find(item => item.DBType == tenant.DBType)?.Name; + _connectionstring = tenant.DBConnectionString; + } + } - if (site.PwaAppIconFileId != null) - { - _pwaappiconfileid = site.PwaAppIconFileId.Value; - } + _createdby = site.CreatedBy; + _createdon = site.CreatedOn; + _modifiedby = site.ModifiedBy; + _modifiedon = site.ModifiedOn; + _deletedby = site.DeletedBy; + _deletedon = site.DeletedOn; - if (site.PwaSplashIconFileId != null) - { - _pwasplashiconfileid = site.PwaSplashIconFileId.Value; - } + _initialized = true; + } + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); + AddModuleMessage(ex.Message, MessageType.Error); + } + } - _pwaisenabled = site.PwaIsEnabled.ToString(); - if (site.PwaAppIconFileId != null) - { - _pwaappiconfileid = site.PwaAppIconFileId.Value; - } - if (site.PwaSplashIconFileId != null) - { - _pwasplashiconfileid = site.PwaSplashIconFileId.Value; - } + private async void ThemeChanged(ChangeEventArgs e) + { + try + { + _themetype = (string)e.Value; + if (_themetype != "-") + { + _containers = ThemeService.GetContainerControls(_themeList, _themetype); + } + else + { + _containers = new List(); + } + _containertype = "-"; + _admincontainertype = Constants.DefaultAdminContainer; + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); + AddModuleMessage(Localizer["Error.Theme.LoadPane"], MessageType.Error); + } + } - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - var tenants = await TenantService.GetTenantsAsync(); - var _databases = await DatabaseService.GetDatabasesAsync(); - var tenant = tenants.Find(item => item.TenantId == site.TenantId); - if (tenant != null) - { - _tenant = tenant.Name; - _database = _databases.Find(item => item.DBType == tenant.DBType)?.Name; - _connectionstring = tenant.DBConnectionString; - } - } + private async Task SaveSite() + { + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) + { + try + { + if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && _containertype != "-") + { + var unique = true; + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + { + if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId)) + { + unique = false; + } + } + } - _createdby = site.CreatedBy; - _createdon = site.CreatedOn; - _modifiedby = site.ModifiedBy; - _modifiedon = site.ModifiedOn; - _deletedby = site.DeletedBy; - _deletedon = site.DeletedOn; + if (unique) + { + var site = await SiteService.GetSiteAsync(PageState.Site.SiteId); + if (site != null) + { + bool refresh = false; + bool reload = false; - _initialized = true; - } - } - catch (Exception ex) - { - await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); - AddModuleMessage(ex.Message, MessageType.Error); - } - } + site.Name = _name; + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + if (site.Runtime != _runtime || site.RenderMode != _runtime + _prerender) + { + site.Runtime = _runtime; + site.RenderMode = _runtime + _prerender; + refresh = true; + reload = true; // needs to be reloaded on server + } + } + site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration)); + site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); - private async void ThemeChanged(ChangeEventArgs e) - { - try - { - _themetype = (string)e.Value; - if (_themetype != "-") - { - _containers = ThemeService.GetContainerControls(_themeList, _themetype); - } - else - { - _containers = new List(); - } - _containertype = "-"; - _admincontainertype = Constants.DefaultAdminContainer; - StateHasChanged(); - } - catch (Exception ex) - { - await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); - AddModuleMessage(Localizer["Error.Theme.LoadPane"], MessageType.Error); - } - } + site.LogoFileId = null; + var logofileid = _logofilemanager.GetFileId(); + if (logofileid != -1) + { + site.LogoFileId = logofileid; + } + int? faviconFieldId = _faviconfilemanager.GetFileId(); + if (faviconFieldId == -1) faviconFieldId = null; + if (site.FaviconFileId != faviconFieldId) + { + site.FaviconFileId = faviconFieldId; + reload = true; // needs to be reloaded on server + } + if (site.DefaultThemeType != _themetype) + { + site.DefaultThemeType = _themetype; + refresh = true; // needs to be refreshed on client + } + if (site.DefaultContainerType != _containertype) + { + site.DefaultContainerType = _containertype; + refresh = true; // needs to be refreshed on client + } + site.AdminContainerType = _admincontainertype; - private async Task SaveSite() - { - validated = true; - var interop = new Interop(JSRuntime); - if (await interop.FormValid(form)) - { - try - { - if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && _containertype != "-") - { - var unique = true; - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) - { - if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId)) - { - unique = false; - } - } - } - - if (unique) - { - var site = await SiteService.GetSiteAsync(PageState.Site.SiteId); - if (site != null) - { - bool reload = false; - bool refresh = (site.DefaultThemeType != _themetype || site.DefaultContainerType != _containertype); - - site.Name = _name; - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - if (site.Runtime != _runtime || site.RenderMode != _runtime + _prerender) - { - site.Runtime = _runtime; - site.RenderMode = _runtime + _prerender; - refresh = true; - reload = true; - } - } - site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration)); - site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); - - site.LogoFileId = null; - var logofileid = _logofilemanager.GetFileId(); - if (logofileid != -1) - { - site.LogoFileId = logofileid; - } - var faviconFieldId = _faviconfilemanager.GetFileId(); - if (faviconFieldId != -1) - { - site.FaviconFileId = faviconFieldId; - } - site.DefaultThemeType = _themetype; - site.DefaultContainerType = _containertype; - site.AdminContainerType = _admincontainertype; - - site.PwaIsEnabled = (_pwaisenabled == null ? true : Boolean.Parse(_pwaisenabled)); - var pwaappiconfileid = _pwaappiconfilemanager.GetFileId(); - if (pwaappiconfileid != -1) + if (site.PwaIsEnabled.ToString() != _pwaisenabled) + { + site.PwaIsEnabled = Boolean.Parse(_pwaisenabled); + reload = true; // needs to be reloaded on server + } + int? pwaappiconfileid = _pwaappiconfilemanager.GetFileId(); + if (pwaappiconfileid == -1) pwaappiconfileid = null; + if (site.PwaAppIconFileId != pwaappiconfileid) { site.PwaAppIconFileId = pwaappiconfileid; + reload = true; // needs to be reloaded on server } - var pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId(); - if (pwasplashiconfileid != -1) + int? pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId(); + if (pwasplashiconfileid == -1) pwasplashiconfileid = null; + if (site.PwaSplashIconFileId != pwasplashiconfileid) { site.PwaSplashIconFileId = pwasplashiconfileid; + reload = true; // needs to be reloaded on server } site = await SiteService.UpdateSiteAsync(site); @@ -518,7 +524,7 @@ if (refresh) { - NavigationManager.NavigateTo(NavigateUrl(), reload); // refresh to show new theme or container + NavigationManager.NavigateTo(NavigateUrl(true), reload); // refresh/reload } else { diff --git a/Oqtane.Server/Pages/_Host.cshtml.cs b/Oqtane.Server/Pages/_Host.cshtml.cs index cb878e2e..e03ef2bd 100644 --- a/Oqtane.Server/Pages/_Host.cshtml.cs +++ b/Oqtane.Server/Pages/_Host.cshtml.cs @@ -149,16 +149,16 @@ namespace Oqtane.Pages "var manifest = { " + "\"name\": \"" + site.Name + "\", " + "\"short_name\": \"" + site.Name + "\", " + - "\"start_url\": \"" + route.Scheme + "://" + route.Authority + "/\", " + + "\"start_url\": \"" + route.SiteUrl + "/\", " + "\"display\": \"standalone\", " + "\"background_color\": \"#fff\", " + "\"description\": \"" + site.Name + "\", " + "\"icons\": [{ " + - "\"src\": \"" + route.Scheme + "://" + route.Authority + Utilities.ContentUrl(alias, site.PwaAppIconFileId.Value) + "\", " + + "\"src\": \"" + route.RootUrl + Utilities.ContentUrl(alias, site.PwaAppIconFileId.Value) + "\", " + "\"sizes\": \"192x192\", " + "\"type\": \"image/png\" " + "}, { " + - "\"src\": \"" + route.Scheme + "://" + route.Authority + Utilities.ContentUrl(alias, site.PwaSplashIconFileId.Value) + "\", " + + "\"src\": \"" + route.RootUrl + Utilities.ContentUrl(alias, site.PwaSplashIconFileId.Value) + "\", " + "\"sizes\": \"512x512\", " + "\"type\": \"image/png\" " + "}] " + diff --git a/Oqtane.Shared/Models/Route.cs b/Oqtane.Shared/Models/Route.cs index 6f02538a..a41d4f46 100644 --- a/Oqtane.Shared/Models/Route.cs +++ b/Oqtane.Shared/Models/Route.cs @@ -4,12 +4,16 @@ using Oqtane.Shared; namespace Oqtane.Models { /// - /// A route is comprised of multiple components: + /// A route is comprised of multiple components ( some optional depending on context ) /// {scheme}://{hostname}/{aliaspath}/{pagepath}/*/{moduleid}/{action}/!/{urlparameters}?{query}#{fragment} /// public class Route { - // default constructor accepts an absolute route url and alias + /// + /// default constructor + /// the route parameter can be obtained from NavigationManager.Uri on client or HttpContext.Request.GetEncodedUrl() on server + /// the aliaspath parameter can be obtained from PageState.Alias.Path on client or TenantManager.GetAlias().Path on server + /// public Route(string route, string aliaspath) { Uri uri = new Uri(route); @@ -120,5 +124,27 @@ namespace Oqtane.Models /// A route may contain a fragment located after the # delimiter /// public string Fragment { get; set; } + + /// + /// The root url contains the resource identifier for the root of an Oqtane installation ( including scheme ) + /// + public string RootUrl + { + get + { + return Scheme + "://" + Authority; + } + } + + /// + /// The site url contains the resource identifier for the home page of a specific Oqtane site ( including scheme and possibly an alias path ) + /// + public string SiteUrl + { + get + { + return Scheme + "://" + Authority + ((!string.IsNullOrEmpty(AliasPath)) ? "/" + AliasPath : ""); + } + } } }