CORS, Theme, Better flow and dotnet tools

This commit is contained in:
2023-01-04 09:38:00 -07:00
parent a3938d1916
commit 978e698da5
72 changed files with 528 additions and 774 deletions

View File

@ -1,6 +1,7 @@
{
"coverage-gutters.coverageBaseDir": "../.vscode/TestResults/*",
"cSpell.words": [
"ASPNETCORE",
"Blazor",
"Serilog",
"Setpoint"

View File

@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Runtime.WebAssembly.Sdk" Version="7.0.0" />
<PackageReference Include="MudBlazor" Version="6.0.13" />
<PackageReference Include="Serilog.AspNetCore.Ingestion" Version="1.0.0-dev-00032" />
<PackageReference Include="Serilog.Sinks.BrowserConsole" Version="1.0.0" />
<PackageReference Include="Serilog.Sinks.BrowserHttp" Version="1.0.0-dev-00032" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />

View File

@ -3,15 +3,5 @@
<PageTitle>Counter</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Counter</MudText>
<MudText Class="mb-4">Current count: @currentCount</MudText>
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
<MudText Class="mb-4">Current count: @_CurrentCount</MudText>
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>

View File

@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Components;
namespace Expose.MyIT.Client.Pages;
public partial class Counter
{
[Inject] protected ILogger<Counter>? Logger { get; set; }
private int _CurrentCount = 0;
private void IncrementCount()
{
if (Logger is null)
throw new NullReferenceException(nameof(Logger));
Logger.LogWarning("Someone has clicked me!");
_CurrentCount++;
}
}

View File

@ -1,5 +1,4 @@
@page "/fetchdata"
@using Expose.MyIT.Shared
@using Expose.MyIT.Shared.ViewModels
<PageTitle>Weather forecast</PageTitle>

View File

@ -1,5 +1,4 @@
@page "/fetchServiceShoporders"
@using Expose.MyIT.Shared
@using Expose.MyIT.Shared.ViewModels
<PageTitle>Service-Shop Orders</PageTitle>
@ -13,12 +12,21 @@ else
{
<MudTable Items="_ServiceShopOrders" Hover="true" SortLabel="Sort By" Elevation="0">
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<ServiceShopOrder, object>(x=>x.CreatedDate)">CreatedDate</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Id)">Id</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Name)">Name</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.BookingNames)">Booking Names</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Type)">Type</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.State)">State</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.ItemNumber)">Item Number</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Descending" SortBy="new Func<ServiceShopOrder, object>(x=>x.CreatedDate)">Created Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.DecidedDate)">Decided Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Recipient)">Recipient</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Requestor)">Requestor</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Id">@context.Id</MudTd>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="BookingNames">@context.BookingNames</MudTd>
<MudTd DataLabel="BookingNames">@string.Join(' ', context.BookingNames)</MudTd>
<MudTd DataLabel="Type">@context.Type</MudTd>
<MudTd DataLabel="State">@context.State</MudTd>
<MudTd DataLabel="ItemNumber">@context.ItemNumber</MudTd>

View File

@ -27,6 +27,7 @@ public partial class FetchServiceShopOrders
if (Http is null)
throw new NullReferenceException(nameof(Http));
string controllerName = MyIT.Shared.Models.Stateless.Methods.IServiceShopOrderController.GetRouteName();
_ServiceShopOrders = await Http.GetFromJsonAsync<ServiceShopOrder[]>($"api/{controllerName}");
string actionName = nameof(MyIT.Shared.Models.Stateless.Methods.ISsaOrderController.GetAllSsaOrders).Substring(3, 3);
_ServiceShopOrders = await Http.GetFromJsonAsync<ServiceShopOrder[]>($"api/{controllerName}/{actionName}");
}
}

View File

@ -1,34 +0,0 @@
@page "/fetchssaorders"
@using Expose.MyIT.Shared
@using Expose.MyIT.Shared.ViewModels
<PageTitle>SSA Orders</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">SSA Orders</MudText>
@if (_SsaOrders == null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
}
else
{
<MudTable Items="_SsaOrders" Hover="true" SortLabel="Sort By" Elevation="0">
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<SsaOrder, object>(x=>x.CreatedDate)">CreatedDate</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Id">@context.Id</MudTd>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="BookingNames">@context.BookingNames</MudTd>
<MudTd DataLabel="Type">@context.Type</MudTd>
<MudTd DataLabel="State">@context.State</MudTd>
<MudTd DataLabel="ItemNumber">@context.ItemNumber</MudTd>
<MudTd DataLabel="CreatedDate">@context.CreatedDate</MudTd>
<MudTd DataLabel="DecidedDate">@context.DecidedDate</MudTd>
<MudTd DataLabel="Recipient">@context.Recipient</MudTd>
<MudTd DataLabel="Requestor">@context.Requestor</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>
}

View File

@ -1,32 +0,0 @@
using Expose.MyIT.Shared.ViewModels;
using Microsoft.AspNetCore.Components;
using System.Net.Http.Json;
namespace Expose.MyIT.Client.Pages;
public partial class FetchSsaOrders
{
[Inject] protected HttpClient? Http { get; set; }
private SsaOrder[]? _SsaOrders;
//Id
//Name
//BookingNames
//Type
//State
//ItemNumber
//CreatedDate
//DecidedDate
//Recipient
//Requestor
protected override async Task OnInitializedAsync()
{
if (Http is null)
throw new NullReferenceException(nameof(Http));
string controllerName = MyIT.Shared.Models.Stateless.Methods.ISsaOrderController.GetRouteName();
_SsaOrders = await Http.GetFromJsonAsync<SsaOrder[]>($"api/{controllerName}");
}
}

View File

@ -14,11 +14,10 @@ internal class Program
LoggingLevelSwitch levelSwitch = new();
LoggerConfiguration loggerConfiguration = new();
_ = loggerConfiguration.WriteTo.BrowserConsole();
Uri uri = new(builder.HostEnvironment.BaseAddress);
_ = loggerConfiguration.MinimumLevel.ControlledBy(levelSwitch);
// string baseAddress = builder.HostEnvironment.BaseAddress;
string baseAddress = "https://localhost:7130/";
_ = loggerConfiguration.Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n"));
_ = loggerConfiguration.WriteTo.BrowserHttp($"{baseAddress}ingest", controlLevelSwitch: levelSwitch);
// _ = loggerConfiguration.WriteTo.BrowserHttp($"{baseAddress}ingest", controlLevelSwitch: levelSwitch);
Log.Logger = loggerConfiguration.CreateLogger();
Serilog.ILogger log = Log.ForContext<Program>();
try
@ -26,7 +25,7 @@ internal class Program
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
_ = builder.Services.AddScoped(serviceProvider => new HttpClient { BaseAddress = new Uri(baseAddress) });
_ = builder.Services.AddScoped(serviceProvider => new HttpClient { BaseAddress = new Uri($"http://{uri.Host}:50199") });
_ = builder.Services.AddMudServices();
log.Information("Building Web Host");

View File

@ -4,12 +4,15 @@
<MudDialogProvider />
<MudSnackbarProvider />
<MudThemeProvider @ref="@_MudThemeProvider" @bind-IsDarkMode="@_IsDarkMode"/>
<MudLayout>
<MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudSpacer />
<MudIconButton Icon="@Icons.Custom.Brands.MudBlazor" Color="Color.Inherit" Link="https://mudblazor.com/" Target="_blank" />
<MudIconButton Icon="@Icons.Custom.Brands.GitHub" Color="Color.Inherit" Link="https://github.com/MudBlazor/MudBlazor/" Target="_blank" />
<MudSwitch @bind-Checked="@_IsDarkMode" Color="Color.Primary" Class="ma-4" T="bool" Label="Toggle Light/Dark Mode"/>
</MudAppBar>
<MudDrawer @bind-Open="_DrawerOpen" Elevation="1">
<MudDrawerHeader>

View File

@ -1,8 +1,22 @@
namespace Expose.MyIT.Client.Shared;
using MudBlazor;
namespace Expose.MyIT.Client.Shared;
public partial class MainLayout
{
bool _DrawerOpen = true;
private bool _IsDarkMode;
private MudThemeProvider? _MudThemeProvider;
void DrawerToggle() => _DrawerOpen = !_DrawerOpen;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _MudThemeProvider is not null)
{
_IsDarkMode = await _MudThemeProvider.GetSystemPreference();
StateHasChanged();
}
}
}

View File

@ -31,6 +31,7 @@
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
</body>
</html>