Merge pull request #1451 from sbwalker/dev

allow host to change runtime and rendermode settings in System Info
This commit is contained in:
Shaun Walker 2021-06-06 11:00:58 -04:00 committed by GitHub
commit aa30caa1a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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> <Label For="runtime" HelpText="Blazor Runtime (Server or WebAssembly)" ResourceKey="BlazorRuntime">Blazor Runtime: </Label>
</td> </td>
<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> </td>
</tr> </tr>
<tr> <tr>
<td> <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>
<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> </td>
</tr> </tr>
<tr> <tr>
@ -62,6 +68,7 @@
</td> </td>
</tr> </tr>
</table> </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; <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" /> <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() private async Task RestartApplication()
{ {
try try

View File

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