271 lines
10 KiB
Plaintext
271 lines
10 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Sites
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject ISiteService SiteService
|
|
@inject ITenantService TenantService
|
|
@inject IAliasService AliasService
|
|
@inject IThemeService ThemeService
|
|
|
|
@if (_themes != null)
|
|
{
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Name: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_name" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Tenant: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_tenant" readonly />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Aliases: </label>
|
|
</td>
|
|
<td>
|
|
<textarea class="form-control" @bind="@_urls" rows="3" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Default Theme: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @onchange="(e => ThemeChanged(e))">
|
|
<option value=""><Select Theme></option>
|
|
@foreach (KeyValuePair<string, string> item in _themes)
|
|
{
|
|
if (item.Key == _themetype)
|
|
{
|
|
<option value="@item.Key" selected>@item.Value</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="@item.Key">@item.Value</option>
|
|
}
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Default Layout: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@_layouttype">
|
|
<option value=""><Select Layout></option>
|
|
@foreach (KeyValuePair<string, string> panelayout in _panelayouts)
|
|
{
|
|
<option value="@panelayout.Key">@panelayout.Value</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Default Container: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@_containertype">
|
|
<option value=""><Select Container></option>
|
|
@foreach (KeyValuePair<string, string> container in _containers)
|
|
{
|
|
<option value="@container.Key">@container.Value</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Is Deleted? </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@_isdeleted">
|
|
<option value="True">Yes</option>
|
|
<option value="False">No</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br />
|
|
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
|
<br />
|
|
<br />
|
|
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon" DeletedBy="@_deletedby" DeletedOn="@_deletedon"></AuditInfo>
|
|
}
|
|
|
|
@code {
|
|
private Dictionary<string, string> _themes;
|
|
private Dictionary<string, string> _panelayouts;
|
|
private Dictionary<string, string> _containers;
|
|
private Alias _alias;
|
|
private List<Theme> _themeList;
|
|
private string _name = string.Empty;
|
|
private List<Tenant> _tenantList;
|
|
private string _tenant = string.Empty;
|
|
private List<Alias> _aliasList;
|
|
private string _urls = string.Empty;
|
|
private string _themetype;
|
|
private string _layouttype;
|
|
private string _containertype;
|
|
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.Host;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_themeList = await ThemeService.GetThemesAsync();
|
|
_aliasList = await AliasService.GetAliasesAsync();
|
|
|
|
_alias = _aliasList.Find(item => item.AliasId == Int32.Parse(PageState.QueryString["id"]));
|
|
var site = await SiteService.GetSiteAsync(_alias.SiteId, _alias);
|
|
if (site != null)
|
|
{
|
|
_name = site.Name;
|
|
_tenantList = await TenantService.GetTenantsAsync();
|
|
_tenant = _tenantList.Find(item => item.TenantId == site.TenantId).Name;
|
|
|
|
foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
|
{
|
|
_urls += alias.Name + "\n";
|
|
}
|
|
|
|
_themetype = site.DefaultThemeType;
|
|
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
|
|
_layouttype = site.DefaultLayoutType;
|
|
_containertype = site.DefaultContainerType;
|
|
_createdby = site.CreatedBy;
|
|
_createdon = site.CreatedOn;
|
|
_modifiedby = site.ModifiedBy;
|
|
_modifiedon = site.ModifiedOn;
|
|
_deletedby = site.DeletedBy;
|
|
_deletedon = site.DeletedOn;
|
|
_isdeleted = site.IsDeleted.ToString();
|
|
}
|
|
|
|
_themes = ThemeService.GetThemeTypes(_themeList);
|
|
_containers = ThemeService.GetContainerTypes(_themeList);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await Log(_alias, LogLevel.Error, string.Empty, ex, "Error Loading Site {SiteId} {Error}", _alias.SiteId, ex.Message);
|
|
AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async void ThemeChanged(ChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_themetype = (string)e.Value;
|
|
if (_themetype != string.Empty)
|
|
{
|
|
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
|
|
}
|
|
else
|
|
{
|
|
_panelayouts = new Dictionary<string, string>();
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message);
|
|
AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task SaveSite()
|
|
{
|
|
try
|
|
{
|
|
if (_name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype))
|
|
{
|
|
var unique = true;
|
|
foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
if (_aliasList.Exists(item => item.Name == name && item.SiteId != _alias.SiteId && item.TenantId != _alias.TenantId))
|
|
{
|
|
unique = false;
|
|
}
|
|
}
|
|
|
|
if (unique)
|
|
{
|
|
var site = await SiteService.GetSiteAsync(_alias.SiteId, _alias);
|
|
if (site != null)
|
|
{
|
|
site.Name = _name;
|
|
site.LogoFileId = null;
|
|
site.DefaultThemeType = _themetype;
|
|
site.DefaultLayoutType = _layouttype ?? string.Empty;
|
|
site.DefaultContainerType = _containertype;
|
|
site.IsDeleted = (_isdeleted == null || Boolean.Parse(_isdeleted));
|
|
|
|
site = await SiteService.UpdateSiteAsync(site, _alias);
|
|
|
|
_urls = _urls.Replace("\n", ",");
|
|
var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
|
{
|
|
if (!names.Contains(alias.Name))
|
|
{
|
|
await AliasService.DeleteAliasAsync(alias.AliasId);
|
|
}
|
|
}
|
|
|
|
foreach (string name in names)
|
|
{
|
|
if (!_aliasList.Exists(item => item.Name == name))
|
|
{
|
|
Alias alias = new Alias
|
|
{
|
|
Name = name,
|
|
TenantId = site.TenantId,
|
|
SiteId = site.SiteId
|
|
};
|
|
await AliasService.AddAliasAsync(alias);
|
|
}
|
|
}
|
|
|
|
await Log(_alias, LogLevel.Information,PermissionNames.Edit, null, "Site Saved {Site}", site);
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await Log(_alias, LogLevel.Error, string.Empty, ex, "Error Saving Site {SiteId} {Error}", _alias.SiteId, ex.Message);
|
|
AddModuleMessage("Error Saving Site", MessageType.Error);
|
|
}
|
|
}
|
|
}
|