Improved UI experience for the Main page
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using DiscordBotCore.Bot;
|
||||
using DiscordBotCore.PluginManagement.Loading;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WebUI.Models;
|
||||
using ILogger = DiscordBotCore.Logging.ILogger;
|
||||
|
||||
namespace WebUI.Controllers;
|
||||
@@ -8,25 +8,64 @@ namespace WebUI.Controllers;
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
public HomeController(ILogger logger)
|
||||
private readonly IDiscordBotApplication _discordBotApplication;
|
||||
private readonly IPluginLoader _pluginLoader;
|
||||
|
||||
public HomeController(ILogger logger, IDiscordBotApplication discordBotApplication, IPluginLoader pluginLoader)
|
||||
{
|
||||
_logger = logger;
|
||||
_discordBotApplication = discordBotApplication;
|
||||
_pluginLoader = pluginLoader;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
_logger.Log("Index page loaded", this);
|
||||
ViewBag.IsRunning = _discordBotApplication.IsReady;
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> StartApplication()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
if (_discordBotApplication.IsReady)
|
||||
{
|
||||
_logger.Log("Application already started", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
await _discordBotApplication.StartAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> StopApplication()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
if (!_discordBotApplication.IsReady)
|
||||
{
|
||||
_logger.Log("Application already stopped", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
await _discordBotApplication.StopAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public JsonResult GetLogs()
|
||||
{
|
||||
var logText = _logger.GetLogsHistory();
|
||||
var logs = logText.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
||||
return Json(logs);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> LoadPlugins()
|
||||
{
|
||||
_logger.Log("Loading plugins", this);
|
||||
await _pluginLoader.LoadPlugins();
|
||||
_logger.Log("Plugins loaded", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user