Skip to content

Commit

Permalink
Merge pull request #1451 from sbwalker/dev
Browse files Browse the repository at this point in the history
allow host to change runtime and rendermode settings in System Info
  • Loading branch information
sbwalker committed Jun 6, 2021
2 parents cf99f04 + 54cd360 commit aa30caa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
30 changes: 27 additions & 3 deletions Oqtane.Client/Modules/Admin/SystemInfo/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Oqtane.Client/Services/Interfaces/ISystemService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Oqtane.Services
{
public interface ISystemService
{
Task<Dictionary<string, string>> GetSystemInfoAsync();

Task UpdateSystemInfoAsync(Dictionary<string, string> settings);
}
}
5 changes: 5 additions & 0 deletions Oqtane.Client/Services/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public SystemService(HttpClient http, SiteState siteState) : base(http)
{
return await GetJsonAsync<Dictionary<string, string>>(Apiurl);
}

public async Task UpdateSystemInfoAsync(Dictionary<string, string> settings)
{
await PostJsonAsync(Apiurl, settings);
}
}
}
18 changes: 18 additions & 0 deletions Oqtane.Server/Controllers/SystemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,23 @@ public SystemController(IWebHostEnvironment environment, IConfigManager configMa
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;
}
}
}

}
}

0 comments on commit aa30caa

Please sign in to comment.