allow host to change runtime and rendermode settings in System Info

This commit is contained in:
Shaun Walker 2021-06-06 11:04:37 -04:00
parent 900ea8cfbc
commit 54cd360bb5
4 changed files with 53 additions and 4 deletions

View File

@ -18,15 +18,21 @@
<Label For="runtime" HelpText="Blazor Runtime (Server or WebAssembly)" ResourceKey="BlazorRuntime">Blazor Runtime: </Label>
</td>
<td>
<input id="runtime" class="form-control" @bind="@_runtime" readonly />
<select id="runtime" class="form-control" @bind="@_runtime">
<option value="Server">@Localizer["Server"]</option>
<option value="WebAssembly">@Localizer["WebAssembly"]</option>
</select>
</td>
</tr>
<tr>
<td>
<Label For="rendermode" HelpText="Blazor Render Mode" ResourceKey="RenderMode">Render Mode: </Label>
<Label For="rendermode" HelpText="Blazor Server Render Mode" ResourceKey="RenderMode">Render Mode: </Label>
</td>
<td>
<input id="rendermode" class="form-control" @bind="@_rendermode" readonly />
<select id="rendermode" class="form-control" @bind="@_rendermode">
<option value="Server">@Localizer["Server"]</option>
<option value="ServerPrerendered">@Localizer["ServerPrerendered"]</option>
</select>
</td>
</tr>
<tr>
@ -62,6 +68,7 @@
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="SaveConfig">@Localizer["Save"]</button>&nbsp;
<a class="btn btn-primary" href="swagger/index.html" target="_new">@Localizer["Access Framework API"]</a>&nbsp;
<ActionDialog Header="Restart Application" Message="Are You Sure You Wish To Restart The Application?" Action="Restart Application" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await RestartApplication())" ResourceKey="RestartApplication" />
@ -92,6 +99,23 @@
}
}
private async Task SaveConfig()
{
try
{
var settings = new Dictionary<string, string>();
settings.Add("runtime", _runtime);
settings.Add("rendermode", _rendermode);
await SystemService.UpdateSystemInfoAsync(settings);
AddModuleMessage(Localizer["Configuration Updated. Please Select Restart Application For These Changes To Be Activated."], MessageType.Success);
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Saving Configuration");
AddModuleMessage(Localizer["An Error Occurred Updating The Configuration"], MessageType.Error);
}
}
private async Task RestartApplication()
{
try

View File

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
@ -6,5 +6,7 @@ namespace Oqtane.Services
public interface ISystemService
{
Task<Dictionary<string, string>> GetSystemInfoAsync();
Task UpdateSystemInfoAsync(Dictionary<string, string> settings);
}
}

View File

@ -22,5 +22,10 @@ namespace Oqtane.Services
{
return await GetJsonAsync<Dictionary<string, string>>(Apiurl);
}
public async Task UpdateSystemInfoAsync(Dictionary<string, string> settings)
{
await PostJsonAsync(Apiurl, settings);
}
}
}

View File

@ -37,5 +37,23 @@ namespace Oqtane.Controllers
return systeminfo;
}
[HttpPost]
[Authorize(Roles = RoleNames.Host)]
public void Post([FromBody] Dictionary<string, string> settings)
{
foreach(KeyValuePair<string, string> kvp in settings)
{
switch (kvp.Key)
{
case "runtime":
_configManager.AddOrUpdateSetting("Runtime", kvp.Value, false);
break;
case "rendermode":
_configManager.AddOrUpdateSetting("RenderMode", kvp.Value, false);
break;
}
}
}
}
}