-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
667 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dotnet.defaultSolution": "Masa.Stack.Components.sln" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<CascadingAuthenticationState> | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> | ||
<NotAuthorized> | ||
@if (!context.User.Identity.IsAuthenticated) | ||
{ | ||
<RedirectToLogin /> | ||
} | ||
else | ||
{ | ||
<p>You are not authorized to access this resource.</p> | ||
} | ||
</NotAuthorized> | ||
</AuthorizeRouteView> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
</CascadingAuthenticationState> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Masa.Blazor" Version="1.0.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.3" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.13" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.3" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@page "/authentication/{action}" | ||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication | ||
<RemoteAuthenticatorView Action="@Action" > | ||
<LoggingIn> | ||
<h2>Checking login state.</h2> | ||
</LoggingIn> | ||
<LogInFailed> | ||
<h2>Your have canceled the Login action.</h2> | ||
</LogInFailed> | ||
<LogOutSucceeded> | ||
<h2>The Logout action was completed successfully.</h2> | ||
</LogOutSucceeded> | ||
</RemoteAuthenticatorView> | ||
|
||
@code { | ||
[Parameter] public string Action { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@page "/counter" | ||
|
||
<PageTitle>Counter</PageTitle> | ||
|
||
<h1>Counter</h1> | ||
|
||
<p role="status">Current count: @_currentCount</p> | ||
|
||
<MButton Color="primary" OnClick="IncrementCount">Click me</MButton> | ||
|
||
@code { | ||
private int _currentCount = 0; | ||
|
||
private void IncrementCount() | ||
{ | ||
_currentCount++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@page "/fetchdata" | ||
@inject HttpClient Http | ||
@attribute [Authorize] | ||
|
||
<PageTitle>Weather forecast</PageTitle> | ||
|
||
<h1>Weather forecast</h1> | ||
|
||
<p>This component demonstrates fetching data from the server.</p> | ||
|
||
@if (_forecasts == null) | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
else | ||
{ | ||
<MDataTable Headers="_headers" Items="_forecasts" ItemsPerPage="5"> | ||
<ItemColContent> | ||
@if (context.Header.Value == nameof(WeatherForecast.Date)) | ||
{ | ||
@context.Item.Date.ToShortDateString() | ||
} | ||
else | ||
{ | ||
@context.Value | ||
} | ||
</ItemColContent> | ||
</MDataTable> | ||
} | ||
|
||
@code { | ||
private WeatherForecast[]? _forecasts; | ||
|
||
private List<DataTableHeader<WeatherForecast>> _headers = new() | ||
{ | ||
new() { Text = "Date", Value = nameof(WeatherForecast.Date) }, | ||
new() { Text = "Temp. (C)", Value = nameof(WeatherForecast.TemperatureC) }, | ||
new() { Text = "Temp. (F)", Value = nameof(WeatherForecast.TemperatureF) }, | ||
new() { Text = "Summary", Value = nameof(WeatherForecast.Summary), Sortable = false } | ||
}; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
_forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json"); | ||
} | ||
|
||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
public string? Summary { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@page "/" | ||
|
||
<PageTitle>Index</PageTitle> | ||
|
||
<h1>Hello, world!</h1> | ||
|
||
Welcome to your new app. | ||
|
||
<SurveyPrompt Title="This is fire-new Blazor UI!" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using MasaWasmApp; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
|
||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.RootComponents.Add<App>("#app"); | ||
builder.RootComponents.Add<HeadOutlet>("head::after"); | ||
|
||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||
|
||
builder.Services.AddMasaBlazor(); | ||
|
||
builder.Services.AddOidcAuthentication(options => | ||
{ | ||
builder.Configuration.Bind("oidc", options.ProviderOptions); | ||
}); | ||
|
||
builder.Services.AddAuthorizationCore(options => | ||
{ | ||
options.FallbackPolicy = options.DefaultPolicy; | ||
}); | ||
|
||
await builder.Build().RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:58793", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
"applicationUrl": "http://localhost:5001", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
"applicationUrl": "https://localhost:7245;http://localhost:5001", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@inherits LayoutComponentBase | ||
|
||
<MApp> | ||
<MAppBar App> | ||
<MAppBarNavIcon @onclick="() => _drawer = !_drawer"></MAppBarNavIcon> | ||
<MToolbarTitle>MASA Blazor</MToolbarTitle> | ||
<MSpacer></MSpacer> | ||
<MButton Text Color="primary" Target="_blank" Href="https://docs.masastack.com/blazor/introduction/why-masa-blazor">About</MButton> | ||
</MAppBar> | ||
|
||
<MNavigationDrawer App @bind-Value="_drawer"> | ||
<MList Nav Routable> | ||
<MListItem Href="/" ActiveClass="primary--text"> | ||
<MListItemIcon> | ||
<MIcon>mdi-home</MIcon> | ||
</MListItemIcon> | ||
<MListItemContent> | ||
<MListItemTitle>Home</MListItemTitle> | ||
</MListItemContent> | ||
</MListItem> | ||
<MListItem Href="/counter" ActiveClass="primary--text"> | ||
<MListItemIcon> | ||
<MIcon>mdi-plus</MIcon> | ||
</MListItemIcon> | ||
<MListItemContent> | ||
<MListItemTitle>Counter</MListItemTitle> | ||
</MListItemContent> | ||
</MListItem> | ||
<MListItem Href="/fetchdata" ActiveClass="primary--text"> | ||
<MListItemIcon> | ||
<MIcon>mdi-list-box</MIcon> | ||
</MListItemIcon> | ||
<MListItemContent> | ||
<MListItemTitle>Fetch data</MListItemTitle> | ||
</MListItemContent> | ||
</MListItem> | ||
</MList> | ||
</MNavigationDrawer> | ||
|
||
<MMain> | ||
<MContainer Fluid> | ||
<MErrorHandler> | ||
@Body | ||
</MErrorHandler> | ||
</MContainer> | ||
</MMain> | ||
</MApp> | ||
|
||
@code { | ||
|
||
private bool? _drawer; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@inject NavigationManager Navigation | ||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication | ||
@code { | ||
protected override void OnInitialized() | ||
{ | ||
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<MAlert Type="AlertTypes.Info" Text Icon="@("mdi-pencil")" Class="mt-2"> | ||
<strong>@Title</strong> | ||
|
||
<span class="text-nowrap"> | ||
More Information go to | ||
<a target="_blank" | ||
class="font-weight-bold" | ||
href="https://docs.masastack.com/blazor/introduction/why-masa-blazor"> | ||
MASA Blazor | ||
</a>. | ||
</span> | ||
</MAlert> | ||
|
||
@code { | ||
|
||
// Demonstrates how a parent component can supply parameters | ||
[Parameter] | ||
public string? Title { get; set; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@using System.Net.Http | ||
@using System.Net.Http.Json | ||
@using Microsoft.AspNetCore.Authorization | ||
@using Microsoft.AspNetCore.Components.Forms | ||
@using Microsoft.AspNetCore.Components.Routing | ||
@using Microsoft.AspNetCore.Components.Web | ||
@using Microsoft.AspNetCore.Components.Web.Virtualization | ||
@using Microsoft.AspNetCore.Components.WebAssembly.Http | ||
@using Microsoft.JSInterop | ||
@using BlazorComponent | ||
@using Masa.Blazor | ||
@using Masa.Blazor.Presets | ||
@using MasaWasmApp | ||
@using MasaWasmApp.Shared | ||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication | ||
@using Microsoft.AspNetCore.Components.Authorization | ||
@* authorization all blazor pages *@ | ||
@* https://stackoverflow.com/questions/60687879/require-authorization-on-all-blazor-pages *@ | ||
@* @attribute [Authorize] *@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"oidc": { | ||
"Authority": "https://localhost:5000/", | ||
"ClientId": "blazor", | ||
"DefaultScopes": [ | ||
"openid", | ||
"profile" | ||
], | ||
"PostLogoutRedirectUri": "/", | ||
"ResponseType": "code" | ||
} | ||
} |
Oops, something went wrong.