From 502dc96ec24f74f86352015b2e3f3f48845584fb Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Mon, 20 Jun 2022 18:15:31 -0500 Subject: [PATCH] chore: Add initial Blazor Server project with MudBlazor --- src/Recyclarr.Gui/App.razor | 11 +++++ src/Recyclarr.Gui/Data/WeatherForecast.cs | 13 ++++++ .../Data/WeatherForecastService.cs | 21 +++++++++ src/Recyclarr.Gui/Pages/Counter.razor | 17 +++++++ src/Recyclarr.Gui/Pages/Error.cshtml | 42 ++++++++++++++++++ src/Recyclarr.Gui/Pages/Error.cshtml.cs | 27 +++++++++++ src/Recyclarr.Gui/Pages/FetchData.razor | 42 ++++++++++++++++++ src/Recyclarr.Gui/Pages/Index.razor | 7 +++ src/Recyclarr.Gui/Pages/_Host.cshtml | 8 ++++ src/Recyclarr.Gui/Pages/_Layout.cshtml | 31 +++++++++++++ src/Recyclarr.Gui/Program.cs | 33 ++++++++++++++ .../Properties/launchSettings.json | 28 ++++++++++++ src/Recyclarr.Gui/Recyclarr.Gui.csproj | 15 +++++++ src/Recyclarr.Gui/Shared/MainLayout.razor | 34 ++++++++++++++ src/Recyclarr.Gui/Shared/NavMenu.razor | 5 +++ src/Recyclarr.Gui/_Imports.razor | 11 +++++ .../appsettings.Development.json | 10 +++++ src/Recyclarr.Gui/appsettings.json | 10 +++++ src/Recyclarr.Gui/wwwroot/favicon.ico | Bin 0 -> 4286 bytes src/Recyclarr.sln | 6 +++ 20 files changed, 371 insertions(+) create mode 100644 src/Recyclarr.Gui/App.razor create mode 100644 src/Recyclarr.Gui/Data/WeatherForecast.cs create mode 100644 src/Recyclarr.Gui/Data/WeatherForecastService.cs create mode 100644 src/Recyclarr.Gui/Pages/Counter.razor create mode 100644 src/Recyclarr.Gui/Pages/Error.cshtml create mode 100644 src/Recyclarr.Gui/Pages/Error.cshtml.cs create mode 100644 src/Recyclarr.Gui/Pages/FetchData.razor create mode 100644 src/Recyclarr.Gui/Pages/Index.razor create mode 100644 src/Recyclarr.Gui/Pages/_Host.cshtml create mode 100644 src/Recyclarr.Gui/Pages/_Layout.cshtml create mode 100644 src/Recyclarr.Gui/Program.cs create mode 100644 src/Recyclarr.Gui/Properties/launchSettings.json create mode 100644 src/Recyclarr.Gui/Recyclarr.Gui.csproj create mode 100644 src/Recyclarr.Gui/Shared/MainLayout.razor create mode 100644 src/Recyclarr.Gui/Shared/NavMenu.razor create mode 100644 src/Recyclarr.Gui/_Imports.razor create mode 100644 src/Recyclarr.Gui/appsettings.Development.json create mode 100644 src/Recyclarr.Gui/appsettings.json create mode 100644 src/Recyclarr.Gui/wwwroot/favicon.ico diff --git a/src/Recyclarr.Gui/App.razor b/src/Recyclarr.Gui/App.razor new file mode 100644 index 00000000..843f201a --- /dev/null +++ b/src/Recyclarr.Gui/App.razor @@ -0,0 +1,11 @@ + + + + + + Not found + +

Sorry, there's nothing at this address.

+
+
+
\ No newline at end of file diff --git a/src/Recyclarr.Gui/Data/WeatherForecast.cs b/src/Recyclarr.Gui/Data/WeatherForecast.cs new file mode 100644 index 00000000..7c713e66 --- /dev/null +++ b/src/Recyclarr.Gui/Data/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Recyclarr.Gui.Data +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/src/Recyclarr.Gui/Data/WeatherForecastService.cs b/src/Recyclarr.Gui/Data/WeatherForecastService.cs new file mode 100644 index 00000000..f30bb10d --- /dev/null +++ b/src/Recyclarr.Gui/Data/WeatherForecastService.cs @@ -0,0 +1,21 @@ +namespace Recyclarr.Gui.Data +{ + public class WeatherForecastService + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + public Task GetForecastAsync(DateTime startDate) + { + var rng = new Random(); + return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = startDate.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }).ToArray()); + } + } +} diff --git a/src/Recyclarr.Gui/Pages/Counter.razor b/src/Recyclarr.Gui/Pages/Counter.razor new file mode 100644 index 00000000..0cc164c3 --- /dev/null +++ b/src/Recyclarr.Gui/Pages/Counter.razor @@ -0,0 +1,17 @@ +@page "/counter" + +Counter + +Counter +Current count: @currentCount +Click me + + +@code { + private int currentCount = 0; + + private void IncrementCount() + { + currentCount++; + } +} diff --git a/src/Recyclarr.Gui/Pages/Error.cshtml b/src/Recyclarr.Gui/Pages/Error.cshtml new file mode 100644 index 00000000..d82ecac4 --- /dev/null +++ b/src/Recyclarr.Gui/Pages/Error.cshtml @@ -0,0 +1,42 @@ +@page +@model Recyclarr.Gui.Pages.ErrorModel + + + + + + + + Error + + + + + +
+
+

Error.

+

An error occurred while processing your request.

+ + @if (Model.ShowRequestId) + { +

+ Request ID: @Model.RequestId +

+ } + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+
+
+ + + diff --git a/src/Recyclarr.Gui/Pages/Error.cshtml.cs b/src/Recyclarr.Gui/Pages/Error.cshtml.cs new file mode 100644 index 00000000..1f214afd --- /dev/null +++ b/src/Recyclarr.Gui/Pages/Error.cshtml.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; + +namespace Recyclarr.Gui.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } +} diff --git a/src/Recyclarr.Gui/Pages/FetchData.razor b/src/Recyclarr.Gui/Pages/FetchData.razor new file mode 100644 index 00000000..6b41e6bc --- /dev/null +++ b/src/Recyclarr.Gui/Pages/FetchData.razor @@ -0,0 +1,42 @@ +@page "/fetchdata" +@using Recyclarr.Gui.Data +@inject WeatherForecastService ForecastService + +Weather forecast + +Weather forecast +This component demonstrates fetching data from the server. +@if (forecasts == null) +{ + +} +else +{ + + + Date + Temp. (C) + Temp. (F) + Summary + + + @context.Date + @context.TemperatureC + @context.TemperatureF + @context.Summary + + + + + +} + + +@code { + private WeatherForecast[]? forecasts; + + protected override async Task OnInitializedAsync() + { + forecasts = await ForecastService.GetForecastAsync(DateTime.Now); + } +} diff --git a/src/Recyclarr.Gui/Pages/Index.razor b/src/Recyclarr.Gui/Pages/Index.razor new file mode 100644 index 00000000..7994d546 --- /dev/null +++ b/src/Recyclarr.Gui/Pages/Index.razor @@ -0,0 +1,7 @@ +@page "/" + +Index + +Hello, world! +Welcome to your new app, powered by MudBlazor! +You can find documentation and examples on our website here: www.mudblazor.com diff --git a/src/Recyclarr.Gui/Pages/_Host.cshtml b/src/Recyclarr.Gui/Pages/_Host.cshtml new file mode 100644 index 00000000..6d282722 --- /dev/null +++ b/src/Recyclarr.Gui/Pages/_Host.cshtml @@ -0,0 +1,8 @@ +@page "/" +@namespace Recyclarr.Gui.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_Layout"; +} + + \ No newline at end of file diff --git a/src/Recyclarr.Gui/Pages/_Layout.cshtml b/src/Recyclarr.Gui/Pages/_Layout.cshtml new file mode 100644 index 00000000..32673979 --- /dev/null +++ b/src/Recyclarr.Gui/Pages/_Layout.cshtml @@ -0,0 +1,31 @@ +@using Microsoft.AspNetCore.Components.Web +@namespace Recyclarr.Gui.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers + + + + + + + + + + + + + @RenderBody() + +
+ + An error has occurred. This application may no longer respond until reloaded. + + + An unhandled exception has occurred. See browser dev tools for details. + + Reload + 🗙 +
+ + + + diff --git a/src/Recyclarr.Gui/Program.cs b/src/Recyclarr.Gui/Program.cs new file mode 100644 index 00000000..9c3b0abd --- /dev/null +++ b/src/Recyclarr.Gui/Program.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Recyclarr.Gui.Data; +using MudBlazor.Services; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorPages(); +builder.Services.AddServerSideBlazor(); +builder.Services.AddSingleton(); +builder.Services.AddMudServices(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); + +app.UseStaticFiles(); + +app.UseRouting(); + +app.MapBlazorHub(); +app.MapFallbackToPage("/_Host"); + +app.Run(); \ No newline at end of file diff --git a/src/Recyclarr.Gui/Properties/launchSettings.json b/src/Recyclarr.Gui/Properties/launchSettings.json new file mode 100644 index 00000000..8a8f3b2b --- /dev/null +++ b/src/Recyclarr.Gui/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:61949", + "sslPort": 44393 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Recyclarr.Gui": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Recyclarr.Gui/Recyclarr.Gui.csproj b/src/Recyclarr.Gui/Recyclarr.Gui.csproj new file mode 100644 index 00000000..d675fc56 --- /dev/null +++ b/src/Recyclarr.Gui/Recyclarr.Gui.csproj @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/Recyclarr.Gui/Shared/MainLayout.razor b/src/Recyclarr.Gui/Shared/MainLayout.razor new file mode 100644 index 00000000..926047b8 --- /dev/null +++ b/src/Recyclarr.Gui/Shared/MainLayout.razor @@ -0,0 +1,34 @@ +@inherits LayoutComponentBase + + + + + + + + + + + + + + + Recyclarr.Gui + + + + + + @Body + + + + +@code { + bool _drawerOpen = true; + + void DrawerToggle() + { + _drawerOpen = !_drawerOpen; + } +} \ No newline at end of file diff --git a/src/Recyclarr.Gui/Shared/NavMenu.razor b/src/Recyclarr.Gui/Shared/NavMenu.razor new file mode 100644 index 00000000..07724847 --- /dev/null +++ b/src/Recyclarr.Gui/Shared/NavMenu.razor @@ -0,0 +1,5 @@ + + Home + Counter + Fetch data + diff --git a/src/Recyclarr.Gui/_Imports.razor b/src/Recyclarr.Gui/_Imports.razor new file mode 100644 index 00000000..4914d1a5 --- /dev/null +++ b/src/Recyclarr.Gui/_Imports.razor @@ -0,0 +1,11 @@ +@using System.Net.Http +@using Microsoft.AspNetCore.Authorization +@using Microsoft.AspNetCore.Components.Authorization +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using MudBlazor +@using Recyclarr.Gui +@using Recyclarr.Gui.Shared diff --git a/src/Recyclarr.Gui/appsettings.Development.json b/src/Recyclarr.Gui/appsettings.Development.json new file mode 100644 index 00000000..51737579 --- /dev/null +++ b/src/Recyclarr.Gui/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "DetailedErrors": true, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/Recyclarr.Gui/appsettings.json b/src/Recyclarr.Gui/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/src/Recyclarr.Gui/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/src/Recyclarr.Gui/wwwroot/favicon.ico b/src/Recyclarr.Gui/wwwroot/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..47ad60e4f6a1b34f80fe0a4a2b2c733434e200ac GIT binary patch literal 4286 zcmeI0&r4KM6vv;;Y7nV5wGhE*)6Rv2xR6PrO%`Dh<*2EN8fj_S&V>yU5&i|OWDv1v z(W+%gM2LjAXw|}n4*qJiS%kzOF@4VCoyVCw&lDGdF(cnO=bn4c_j})c=e{@Sc@_NC z)_Qzuz1Jr_?=;?df8===vCQ)AdC!=0KZQb}qKxt$lzZTK^+0amX+8M3+LD}Kz0y{H znEOZm^=#+h9Qo6r<}fvG4jk2B3KRtJD5mhM-Fz97R|h^wezt39IjH%CO-1EL#i)&g zF|aE<3ZpOU*ac%C9_XGS?-ls1`9|Mgca)YJqqY&OD2K6Gv;?{bYBO7H124$?X>$EF zXYUSuvH7l6)EJJ(4$mIrNpJ!#!6ewTyy9=%>iw4MA6*M-bJ*cbOY)M?<}|Pwn_$B)A$3PdT(>!ar-UjNvI-J5Q{WcE#e$yJpG4LKpPLclRo&J=GOHVX` zMIe5&a=4Zn;T!;w{YJdq)-aa+3H9NY9$wh)eyB0u2D*N4{!L%G;go)R3G#+tITI!? z)X!Y&n1y>zw2q?B{#PomTC}C#-a2at_m6m}FTT{F-^%%4vo*3NgRnlxuVQWj{m;}) zgQ$MfYZn{Vx^7s`^SLb+^%HBuyo9>IQ>p=bQ9S?@#%IO+Z zV;{RfyfL_*v(&i#rn+kP)rY46%!>}svi$nZo<;cNId1n~{S5J<^KACDi8`rOO>0Z^ zIeT*EmZNmGyC2E9R86t+ZXE|j&ok9li?%$AxJ8Qkd|$s2yr*#f;FrhNFHzy%#2#iCmSW