326 lines
12 KiB
Plaintext
326 lines
12 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Sites
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject ISiteService SiteService
|
|
@inject IAliasService AliasService
|
|
@inject IThemeService ThemeService
|
|
@inject ISettingService SettingService
|
|
|
|
@if (themes != null)
|
|
{
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Name: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@name" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Aliases: </label>
|
|
</td>
|
|
<td>
|
|
<textarea class="form-control" @bind="@urls" rows="3" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Logo: </label>
|
|
</td>
|
|
<td>
|
|
<FileManager FileId="@logofileid.ToString()" @ref="filemanager" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" 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 for="Name" 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 for="Name" 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 for="Name" 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>
|
|
|
|
<a data-toggle="collapse" class="app-link-unstyled" href="#SMTP" aria-expanded="false" aria-controls="SMTP">
|
|
<h5>SMTP Settings</h5><hr class="app-rule" />
|
|
</a>
|
|
<div class="collapse" id="SMTP">
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Host: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@smtphost" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Port: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@smtpport" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">SSL Enabled: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@smtpssl" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Username: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@smtpusername" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Password: </label>
|
|
</td>
|
|
<td>
|
|
<input type="password" class="form-control" @bind="@smtppassword" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<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 {
|
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
|
|
|
Dictionary<string, string> themes;
|
|
Dictionary<string, string> panelayouts;
|
|
Dictionary<string, string> containers;
|
|
|
|
Alias Alias;
|
|
int siteid;
|
|
string name = "";
|
|
List<Alias> aliases;
|
|
string urls = "";
|
|
int logofileid = -1;
|
|
FileManager filemanager;
|
|
string themetype;
|
|
string layouttype;
|
|
string containertype;
|
|
|
|
string smtphost = "";
|
|
string smtpport = "";
|
|
string smtpssl = "";
|
|
string smtpusername = "";
|
|
string smtppassword = "";
|
|
|
|
string createdby;
|
|
DateTime createdon;
|
|
string modifiedby;
|
|
DateTime modifiedon;
|
|
string deletedby;
|
|
DateTime? deletedon;
|
|
string isdeleted;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
Alias = PageState.Aliases.Where(item => item.AliasId == Int32.Parse(PageState.QueryString["id"])).FirstOrDefault();
|
|
siteid = Alias.SiteId;
|
|
Site site = await SiteService.GetSiteAsync(siteid, Alias);
|
|
if (site != null)
|
|
{
|
|
name = site.Name;
|
|
aliases = PageState.Aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList();
|
|
foreach (Alias alias in aliases)
|
|
{
|
|
urls += alias.Name + "\n";
|
|
}
|
|
if (site.LogoFileId != null)
|
|
{
|
|
logofileid = site.LogoFileId.Value;
|
|
}
|
|
themetype = site.DefaultThemeType;
|
|
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype);
|
|
layouttype = site.DefaultLayoutType;
|
|
containertype = site.DefaultContainerType;
|
|
|
|
Dictionary<string, string> settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
|
|
smtphost = SettingService.GetSetting(settings, "SMTPHost", "");
|
|
smtpport = SettingService.GetSetting(settings, "SMTPPort", "");
|
|
smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "");
|
|
smtpusername = SettingService.GetSetting(settings, "SMTPUsername", "");
|
|
smtppassword = SettingService.GetSetting(settings, "SMTPPassword", "");
|
|
|
|
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(PageState.Themes);
|
|
containers = ThemeService.GetContainerTypes(PageState.Themes);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", siteid, ex.Message);
|
|
AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async void ThemeChanged(ChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
themetype = (string)e.Value;
|
|
if (themetype != "")
|
|
{
|
|
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, 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 != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
|
|
{
|
|
Site site = await SiteService.GetSiteAsync(siteid, Alias);
|
|
if (site != null)
|
|
{
|
|
site.Name = name;
|
|
site.LogoFileId = null;
|
|
int logofileid = filemanager.GetFileId();
|
|
if (logofileid != -1)
|
|
{
|
|
site.LogoFileId = logofileid;
|
|
}
|
|
site.DefaultThemeType = themetype;
|
|
site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
|
|
site.DefaultContainerType = containertype;
|
|
site.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
|
|
|
|
site = await SiteService.UpdateSiteAsync(site, Alias);
|
|
|
|
urls = urls.Replace("\n", ",");
|
|
string[] names = urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (Alias alias in aliases)
|
|
{
|
|
if (!names.Contains(alias.Name))
|
|
{
|
|
await AliasService.DeleteAliasAsync(alias.AliasId);
|
|
}
|
|
}
|
|
foreach (string name in names)
|
|
{
|
|
if (!aliases.Exists(item => item.Name == name))
|
|
{
|
|
Alias alias = new Alias();
|
|
alias.Name = name;
|
|
alias.TenantId = site.TenantId;
|
|
alias.SiteId = site.SiteId;
|
|
await AliasService.AddAliasAsync(alias);
|
|
}
|
|
}
|
|
|
|
Dictionary<string, string> settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
|
|
SettingService.SetSetting(settings, "SMTPHost", smtphost);
|
|
SettingService.SetSetting(settings, "SMTPPort", smtpport);
|
|
SettingService.SetSetting(settings, "SMTPSSL", smtpssl);
|
|
SettingService.SetSetting(settings, "SMTPUsername", smtpusername);
|
|
SettingService.SetSetting(settings, "SMTPPassword", smtppassword);
|
|
await SettingService.UpdateModuleSettingsAsync(settings, site.SiteId);
|
|
|
|
await logger.LogInformation("Site Saved {Site}", site);
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", siteid, ex.Message);
|
|
AddModuleMessage("Error Saving Site", MessageType.Error);
|
|
}
|
|
}
|
|
}
|