restrict container selection to the current theme, hide layout selection if theme does not support layouts, make behavior consistent for all theme/layout/container selection

This commit is contained in:
Shaun Walker 2020-05-31 22:53:11 -04:00
parent be4813d9c0
commit 7d21cfefc1
9 changed files with 160 additions and 125 deletions

View File

@ -105,7 +105,7 @@
protected override async Task OnInitializedAsync()
{
_title = ModuleState.Title;
_containers = ThemeService.GetContainerTypes(await ThemeService.GetThemesAsync());
_containers = ThemeService.GetContainerTypes(await ThemeService.GetThemesAsync(), PageState.Page.ThemeType);
_containerType = ModuleState.ContainerType;
if (!string.IsNullOrEmpty(PageState.Page.DefaultContainerType) && _containerType == PageState.Page.DefaultContainerType)
{

View File

@ -116,6 +116,8 @@
</select>
</td>
</tr>
@if (_panelayouts.Count > 0)
{
<tr>
<td>
<Label For="Layout" HelpText="Select a layout for the page (if the selected theme supports it)">Layout: </Label>
@ -137,6 +139,7 @@
</select>
</td>
</tr>
}
<tr>
<td>
<Label For="defaultContainer" HelpText="Select the default container for the page">Default Container: </Label>
@ -199,8 +202,8 @@
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
private Dictionary<string, string> _themes;
private Dictionary<string, string> _panelayouts;
private Dictionary<string, string> _themes = new Dictionary<string, string>();
private Dictionary<string, string> _panelayouts = new Dictionary<string, string>();
private Dictionary<string, string> _containers = new Dictionary<string, string>();
private List<Theme> _themeList;
private List<Page> _pageList;
@ -233,9 +236,6 @@
_children = PageState.Pages.Where(item => item.ParentId == null).ToList();
_themes = ThemeService.GetThemeTypes(_themeList);
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_containers = ThemeService.GetContainerTypes(_themeList);
_permissions = string.Empty;
}
catch (Exception ex)
@ -288,11 +288,15 @@
if (_themetype != "-")
{
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
}
else
{
_panelayouts = new Dictionary<string, string>();
_containers = new Dictionary<string, string>();
}
_layouttype = "-";
_containertype = "-";
StateHasChanged();
}
catch (Exception ex)

View File

@ -127,6 +127,8 @@
</select>
</td>
</tr>
@if (_panelayouts.Count > 0)
{
<tr>
<td>
<Label For="Layout" HelpText="Select a layout for the page (if the selected theme supports it)">Layout: </Label>
@ -148,6 +150,7 @@
</select>
</td>
</tr>
}
<tr>
<td>
<Label For="defaultContainer" HelpText="Select the default container for the page">Default Container: </Label>
@ -212,8 +215,8 @@
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
private Dictionary<string, string> _themes;
private Dictionary<string, string> _panelayouts;
private Dictionary<string, string> _themes = new Dictionary<string, string>();
private Dictionary<string, string> _panelayouts = new Dictionary<string, string>();
private Dictionary<string, string> _containers = new Dictionary<string, string>();
private List<Theme> _themeList;
private List<Page> _pageList;
@ -257,7 +260,6 @@
_children = PageState.Pages.Where(item => item.ParentId == null).ToList();
_themes = ThemeService.GetThemeTypes(_themeList);
_containers = ThemeService.GetContainerTypes(_themeList);
_pageId = Int32.Parse(PageState.QueryString["id"]);
var page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId);
@ -291,12 +293,13 @@
{
_themetype = "-";
}
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, page.ThemeType);
_layouttype = page.LayoutType;
if (_layouttype == PageState.Site.DefaultLayoutType)
{
_layouttype = "-";
}
_containers = ThemeService.GetContainerTypes(_themeList, page.ThemeType);
_containertype = page.DefaultContainerType;
if (string.IsNullOrEmpty(_containertype))
{
@ -370,11 +373,15 @@
if (_themetype != "-")
{
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
}
else
{
_panelayouts = new Dictionary<string, string>();
_containers = new Dictionary<string, string>();
}
_layouttype = "-";
_containertype = "-";
StateHasChanged();
}
catch (Exception ex)

View File

@ -56,6 +56,7 @@
</td>
<td>
<select id="defaultTheme" class="form-control" @onchange="(e => ThemeChanged(e))">
<option value="-">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in _themes)
{
if (item.Key == _themetype)
@ -70,12 +71,15 @@
</select>
</td>
</tr>
@if (_panelayouts.Count > 0)
{
<tr>
<td>
<Label For="defaultLayout" HelpText="Select the sites default layout">Default Layout: </Label>
</td>
<td>
<select id="defaultLayout" class="form-control" @bind="@_layouttype">
<option value="-">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in _panelayouts)
{
<option value="@panelayout.Key">@panelayout.Value</option>
@ -83,12 +87,14 @@
</select>
</td>
</tr>
}
<tr>
<td>
<Label For="defaultContainer" HelpText="Select the default container for the site">Default Container: </Label>
</td>
<td>
<select id="defaultContainer" class="form-control" @bind="@_containertype">
<option value="-">&lt;Select Container&gt;</option>
@foreach (KeyValuePair<string, string> container in _containers)
{
<option value="@container.Key">@container.Value</option>
@ -205,9 +211,9 @@
}
@code {
private Dictionary<string, string> _themes;
private Dictionary<string, string> _panelayouts;
private Dictionary<string, string> _containers;
private Dictionary<string, string> _themes = new Dictionary<string, string>();
private Dictionary<string, string> _panelayouts = new Dictionary<string, string>();
private Dictionary<string, string> _containers = new Dictionary<string, string>();
private List<Theme> _themeList;
private string _name = string.Empty;
private List<Tenant> _tenantList;
@ -218,9 +224,9 @@
private FileManager _logofilemanager;
private int _faviconfileid = -1;
private FileManager _faviconfilemanager;
private string _themetype;
private string _layouttype;
private string _containertype;
private string _themetype = "-";
private string _layouttype = "-";
private string _containertype = "-";
private string _allowregistration;
private string _smtphost = string.Empty;
private string _smtpport = string.Empty;
@ -271,6 +277,7 @@
_themetype = site.DefaultThemeType;
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_layouttype = site.DefaultLayoutType;
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
_containertype = site.DefaultContainerType;
_allowregistration = site.AllowRegistration.ToString();
@ -313,7 +320,7 @@
}
_themes = ThemeService.GetThemeTypes(_themeList);
_containers = ThemeService.GetContainerTypes(_themeList);
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
}
catch (Exception ex)
{
@ -330,11 +337,15 @@
if (_themetype != string.Empty)
{
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
}
else
{
_panelayouts = new Dictionary<string, string>();
_containers = new Dictionary<string, string>();
}
_layouttype = "-";
_containertype = "-";
StateHasChanged();
}
catch (Exception ex)
@ -348,7 +359,7 @@
{
try
{
if (_name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype))
if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && (_panelayouts.Count == 0 || _layouttype != "-") && _containertype != "-")
{
var unique = true;
foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
@ -373,7 +384,7 @@
}
site.DefaultThemeType = _themetype;
site.DefaultLayoutType = (_layouttype == null ? string.Empty : _layouttype);
site.DefaultLayoutType = (_layouttype == "-" ? string.Empty : _layouttype);
site.DefaultContainerType = _containertype;
site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration));
site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted));

View File

@ -38,7 +38,7 @@ else
</td>
<td>
<select id="defaultTheme" class="form-control" @onchange="(e => ThemeChanged(e))">
<option value="">&lt;Select Theme&gt;</option>
<option value="-">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in _themes)
{
<option value="@item.Key">@item.Value</option>
@ -46,13 +46,15 @@ else
</select>
</td>
</tr>
@if (_panelayouts.Count > 0)
{
<tr>
<td>
<Label For="defaultLayout" HelpText="Select the default layout for the site">Default Layout: </Label>
</td>
<td>
<select id="defaultLayout" class="form-control" @bind="@_layouttype">
<option value="">&lt;Select Layout&gt;</option>
<option value="-">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in _panelayouts)
{
<option value="@panelayout.Key">@panelayout.Value</option>
@ -60,13 +62,14 @@ else
</select>
</td>
</tr>
}
<tr>
<td>
<Label For="defaultContainer" HelpText="Select the default container for the site">Default Container: </Label>
</td>
<td>
<select id="defaultContainer" class="form-control" @bind="@_containertype">
<option value="">&lt;Select Container&gt;</option>
<option value="-">&lt;Select Container&gt;</option>
@foreach (KeyValuePair<string, string> container in _containers)
{
<option value="@container.Key">@container.Value</option>
@ -80,7 +83,7 @@ else
</td>
<td>
<select id="siteTemplate" class="form-control" @bind="@_sitetemplatetype">
<option value="">&lt;Select Site Template&gt;</option>
<option value="-">&lt;Select Site Template&gt;</option>
@foreach (SiteTemplate siteTemplate in _siteTemplates)
{
<option value="@siteTemplate.TypeName">@siteTemplate.Name</option>
@ -218,10 +221,10 @@ else
private string _name = string.Empty;
private string _urls = string.Empty;
private string _themetype = string.Empty;
private string _layouttype = string.Empty;
private string _containertype = string.Empty;
private string _sitetemplatetype = string.Empty;
private string _themetype = "-";
private string _layouttype = "-";
private string _containertype = "-";
private string _sitetemplatetype = "-";
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
@ -231,7 +234,6 @@ else
_tenants = await TenantService.GetTenantsAsync();
_urls = PageState.Alias.Name;
_themes = ThemeService.GetThemeTypes(_themeList);
_containers = ThemeService.GetContainerTypes(_themeList);
_siteTemplates = await SiteTemplateService.GetSiteTemplatesAsync();
}
@ -266,12 +268,15 @@ else
if (_themetype != string.Empty)
{
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
}
else
{
_panelayouts = new Dictionary<string, string>();
_containers = new Dictionary<string, string>();
}
_layouttype = "-";
_containertype = "-";
StateHasChanged();
}
catch (Exception ex)
@ -283,7 +288,7 @@ else
private async Task SaveSite()
{
if (_tenantid != "-" && _name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype) && !string.IsNullOrEmpty(_sitetemplatetype))
if (_tenantid != "-" && _name != string.Empty && _urls != string.Empty && _themetype != "-" && (_panelayouts.Count == 0 || _layouttype != "-") && _containertype != "-" && _sitetemplatetype != "-")
{
var duplicates = new List<string>();
var aliases = await AliasService.GetAliasesAsync();

View File

@ -39,7 +39,7 @@
</td>
<td>
<select id="defaultTheme" class="form-control" @onchange="(e => ThemeChanged(e))">
<option value="">&lt;Select Theme&gt;</option>
<option value="-">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in _themes)
{
if (item.Key == _themetype)
@ -54,13 +54,15 @@
</select>
</td>
</tr>
@if (_panelayouts.Count > 0)
{
<tr>
<td>
<Label For="defaultLayout" HelpText="Select the default layout for the site">Default Layout: </Label>
</td>
<td>
<select id="defaultLayout" class="form-control" @bind="@_layouttype">
<option value="">&lt;Select Layout&gt;</option>
<option value="-">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in _panelayouts)
{
<option value="@panelayout.Key">@panelayout.Value</option>
@ -68,13 +70,14 @@
</select>
</td>
</tr>
}
<tr>
<td>
<Label For="defaultContainer" HelpText="Select the default container for the site">Default Container: </Label>
</td>
<td>
<select id="defaultIdea" class="form-control" @bind="@_containertype">
<option value="">&lt;Select Container&gt;</option>
<option value="-">&lt;Select Container&gt;</option>
@foreach (KeyValuePair<string, string> container in _containers)
{
<option value="@container.Key">@container.Value</option>
@ -103,9 +106,9 @@
}
@code {
private Dictionary<string, string> _themes;
private Dictionary<string, string> _panelayouts;
private Dictionary<string, string> _containers;
private Dictionary<string, string> _themes = new Dictionary<string, string>();
private Dictionary<string, string> _panelayouts = new Dictionary<string, string>();
private Dictionary<string, string> _containers = new Dictionary<string, string>();
private Alias _alias;
private List<Theme> _themeList;
private string _name = string.Empty;
@ -147,9 +150,11 @@
_urls += alias.Name + "\n";
}
_themes = ThemeService.GetThemeTypes(_themeList);
_themetype = site.DefaultThemeType;
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_layouttype = site.DefaultLayoutType;
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
_containertype = site.DefaultContainerType;
_createdby = site.CreatedBy;
_createdon = site.CreatedOn;
@ -159,9 +164,6 @@
_deletedon = site.DeletedOn;
_isdeleted = site.IsDeleted.ToString();
}
_themes = ThemeService.GetThemeTypes(_themeList);
_containers = ThemeService.GetContainerTypes(_themeList);
}
catch (Exception ex)
{
@ -178,12 +180,15 @@
if (_themetype != string.Empty)
{
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
_containers = ThemeService.GetContainerTypes(_themeList, _themetype);
}
else
{
_panelayouts = new Dictionary<string, string>();
_containers = new Dictionary<string, string>();
}
_layouttype = "-";
_containertype = "-";
StateHasChanged();
}
catch (Exception ex)
@ -197,7 +202,7 @@
{
try
{
if (_name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype))
if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && (_panelayouts.Count == 0 || _layouttype != "-") && _containertype != "-")
{
var unique = true;
foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))

View File

@ -9,7 +9,7 @@ namespace Oqtane.Services
Task<List<Theme>> GetThemesAsync();
Dictionary<string, string> GetThemeTypes(List<Theme> themes);
Dictionary<string, string> GetPaneLayoutTypes(List<Theme> themes, string themeName);
Dictionary<string, string> GetContainerTypes(List<Theme> themes);
Dictionary<string, string> GetContainerTypes(List<Theme> themes, string themeName);
Task InstallThemesAsync();
Task DeleteThemeAsync(string themeName);
}

View File

@ -44,7 +44,7 @@ namespace Oqtane.Services
var selectablePaneLayouts = new Dictionary<string, string>();
foreach (Theme theme in themes)
{
if (themeName.StartsWith(theme.ThemeName))
if (Utilities.GetTypeName(themeName).StartsWith(Utilities.GetTypeName(theme.ThemeName)))
{
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
@ -55,16 +55,19 @@ namespace Oqtane.Services
return selectablePaneLayouts;
}
public Dictionary<string, string> GetContainerTypes(List<Theme> themes)
public Dictionary<string, string> GetContainerTypes(List<Theme> themes, string themeName)
{
var selectableContainers = new Dictionary<string, string>();
foreach (Theme theme in themes)
{
if (Utilities.GetTypeName(themeName).StartsWith(Utilities.GetTypeName(theme.ThemeName)))
{
foreach (string container in theme.ContainerControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
selectableContainers.Add(container, theme.Name + " - " + @Utilities.GetTypeNameLastSegment(container, 0));
}
}
}
return selectableContainers;
}

View File

@ -301,7 +301,7 @@
var panes = PageState.Page.Panes;
Pane = panes.Count() == 1 ? panes.SingleOrDefault() : "";
var themes = await ThemeService.GetThemesAsync();
_containers = ThemeService.GetContainerTypes(themes);
_containers = ThemeService.GetContainerTypes(themes, PageState.Page.ThemeType);
ContainerType = PageState.Site.DefaultContainerType;
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);