Skip to content

Commit

Permalink
Improved First Start experience (#400)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
csharpfritz and github-actions[bot] authored Mar 8, 2024
1 parent 4813ca9 commit c7f7221
Show file tree
Hide file tree
Showing 33 changed files with 543 additions and 341 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ TagzApp.Web.db
*.userosscache
*.sln.docstates

# Ignore vim swap files
*.swp

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

Expand Down
1 change: 1 addition & 0 deletions scripts/AddSqliteSecurityMigration.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet ef migrations add --context TagzApp.Security.SecurityContext -p ..\src\TagzApp.Storage.Sqlite.Security\ -s ..\src\TagzApp.Web %1
9 changes: 5 additions & 4 deletions src/TagzApp.Blazor.Client/Components/Pages/Waterfall.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else

@code {

private SortedList<DateTimeOffset, TagzApp.ViewModels.Data.ContentModel> _Content = new();
private SortedList<string, TagzApp.ViewModels.Data.ContentModel> _Content = new();

WaterfallModal Modal = new();
ContentModel ModalContent = null!;
Expand All @@ -57,7 +57,8 @@ else
foreach (var content in existingContent)
{
_Content.Add(content.Timestamp, content);
if (_Content.ContainsKey(content.Timestamp.ToString("yyyyMMddHHmmss") + content.ProviderId)) continue;
_Content.Add(content.Timestamp.ToString("yyyyMMddHHmmss") + content.ProviderId, content);
}

await base.OnInitializedAsync();
Expand Down Expand Up @@ -96,7 +97,7 @@ else
return;
}

_Content.Add(content.Timestamp, content);
_Content.Add(content.Timestamp.ToString("yyyyMMddHHmmss") + content.ProviderId, content);
StateHasChanged();
});

Expand Down Expand Up @@ -136,7 +137,7 @@ else
{
if (item is ContentModel content)
{
_Content.Add(content.Timestamp, content);
_Content.Add(content.Timestamp.ToString("yyyyMMddHHmmss") + content.ProviderId, content);
}
}
_PauseQueue.Clear();
Expand Down
12 changes: 10 additions & 2 deletions src/TagzApp.Blazor/Components/Admin/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/Admin/Index"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = RolesAndPolicies.Role.Admin)]
@* @attribute [Authorize(Roles = "Admin")] *@
@inject NavigationManager NavigationManager
@layout Admin.Shared.AdminLayout


Expand All @@ -10,9 +11,16 @@

@code {

[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

protected override Task OnInitializedAsync()
{

var user = HttpContext.User;
if (!user.IsInRole("Admin"))
{
NavigationManager.NavigateTo("/");
}
return base.OnInitializedAsync();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@page "/admin/modalcustomization"

@attribute [Authorize(policy: RolesAndPolicies.Policy.AdminRoleOnly)]
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Authorization
@using System.Drawing
@layout AdminLayout
@inject IJSRuntime JSRuntime
@inject ModalConfiguration Config
@inject NavigationManager NavigationManager
@rendermode InteractiveServer

<div class="row" style="min-height: 300px">
Expand Down Expand Up @@ -108,6 +108,19 @@
private string _BackgroundImage;
private string _BackgroundImageMimeType;

[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

protected override Task OnInitializedAsync()
{
var user = HttpContext.User;
if (!user.IsInRole("Admin"))
{
NavigationManager.NavigateTo("/");
}
return base.OnInitializedAsync();
}

async Task SaveChanges()
{

Expand Down
40 changes: 38 additions & 2 deletions src/TagzApp.Blazor/Components/Admin/Pages/Users.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@
@using Microsoft.EntityFrameworkCore
@layout Admin.Shared.AdminLayout
@inject UserManager<TagzAppUser> UserManager
@inject NavigationManager NavigationManager
@inject ApplicationConfiguration AppConfig
@inject IJSRuntime Js
@rendermode InteractiveServer

<h3>User Roles Management</h3>

@if (AppConfig.SingleUserMode) {
<div>You're in Single User Mode

<p class="alert alert-primary" role="alert">Converting to Multi-User Mode is a one-way operation that cannot be reversed. You will need to register as a new user and login with that user immediately to be granted Admin access. After that, you can add more users with various roles.
</p>

<button type="button" class="btn btn-danger" @onclick="ConvertUserMode">Change to Multi-User Mode</button>

</div>
} else {
<table>
<tr>
@*<th>User ID</th>*@
Expand All @@ -29,17 +42,29 @@
</table>

<ManageRoles @ref="ManageRolesDialog" CurrentUser="SelectedUser" OnComplete="CloseManageRoles" />
}

@code {

[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

private List<TagzAppUser> UserList { get; set; } = [];

private TagzAppUser SelectedUser { get; set; } = new();

private ManageRoles ManageRolesDialog = new();

override protected async Task OnInitializedAsync()
override protected async Task OnParametersSetAsync()
{

if (AppConfig.SingleUserMode) return;
var user = HttpContext.User;
if (!user.IsInRole("Admin"))
{
NavigationManager.NavigateTo("/");
}

UserList = await UserManager.Users.ToListAsync();
}

Expand All @@ -54,4 +79,15 @@
SelectedUser = null;
}

}
private async Task ConvertUserMode()
{
var accepted = await Js.InvokeAsync<bool>("confirm", "Are you sure you would like to convert to multi-user mode? This is a one-way operation and cannot be reversed");
if (accepted) {
AppConfig.SingleUserMode = false;
await AppConfig.SaveConfiguration(ConfigureTagzAppFactory.Current);
Program.Restart();
NavigationManager.NavigateTo("/");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<li class="nav-item"><NavLink class="nav-link" href="/Admin/ModalCustomization">Modal Customization</NavLink></li>

@* NOTE: Temporary placeholder *@
<li class="nav-item"><NavLink class="nav-link" href="/Admin/YouTubeChat">YouTubeChat</NavLink></li>
@* <li class="nav-item"><NavLink class="nav-link" href="/Admin/YouTubeChat">YouTubeChat</NavLink></li>
*@

</ul>
4 changes: 2 additions & 2 deletions src/TagzApp.Blazor/Components/Layout/Footer.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<footer class="border-top footer text-muted text-center">
&copy; 2023 - TagzApp.Web -
&copy; 2023,2024 - TagzApp.Web -
<a href="/Privacy">Privacy</a> -
Running on .NET @fxVersion -
<a target="_blank" href="https://github.com/FritzAndFriends/TagzApp">Source Code</a>
</footer>

@code {
string fxVersion = System.Environment.Version.ToString();
}
}
2 changes: 1 addition & 1 deletion src/TagzApp.Blazor/Components/Layout/Header.razor
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

}
}
10 changes: 6 additions & 4 deletions src/TagzApp.Blazor/Components/LoginView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
@using TagzApp.Blazor.Components.Account
@inject IdentityUserAccessor UserMgr
@inject NavigationManager NavigationManager
@inject ApplicationConfiguration AppConfig
@implements IDisposable

<AuthorizeView Roles="@RolesAndPolicies.Role.Admin">
<Authorized>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Admin/Index">
<span class="bi bi-gear-fill-nav-menu" aria-hidden="true"></span> Admin
<NavLink class="nav-link" href="Admin/Index" title="System Configuration and Administration features">
<span class="bi bi-gear-fill-nav-menu" aria-hidden="true"></span> System Admin
</NavLink>
</div>
</Authorized>
</AuthorizeView>


@if (!AppConfig.SingleUserMode) {
<AuthorizeView>
<Authorized>
<div class="nav-item px-3">
Expand Down Expand Up @@ -46,6 +47,7 @@
</div>
</NotAuthorized>
</AuthorizeView>
}

@code {

Expand Down Expand Up @@ -96,4 +98,4 @@
}


}
}
65 changes: 34 additions & 31 deletions src/TagzApp.Blazor/Components/Pages/FirstStartConfiguration.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
@page "/FirstStartConfiguration"
@using Microsoft.AspNetCore.Components.Sections
@rendermode InteractiveServer
@rendermode @(new InteractiveServerRenderMode(false))

<PageTitle>First Start Configuration</PageTitle>

<h1>First Start Configuration</h1>

@if (CurrentConfig != null && CurrentConfig is EmptyConfigureTagzApp)
{
var config = CurrentConfig as EmptyConfigureTagzApp;
if (!string.IsNullOrEmpty(config.Message))
{
<div class="alert alert-danger" role="alert">
@config.Message
</div>
}
}

@* Add a form to allow selection of a provider and setting a connection string *@
<form @onsubmit="@OnFormValidate">
<EditForm FormName="SiteConfig" Model="Config" OnValidSubmit="OnFormValidate">

<DataAnnotationsValidator />
<ValidationSummary />

<p>
Let's get some initial configuration for TagzApp to work properly. Would you like a basic configuration with all
Expand All @@ -19,21 +32,13 @@
<div class="form-group">

<InputRadioGroup @bind-Value="Config.ConfigurationType">
<div>
<InputRadio class="form-check-input" Value="@("basic")" /> Basic
<div>
<InputRadio class="form-check-input" Value="@("basic")" /> Basic
<InputRadio class="form-check-input" Value="@("advanced")" @onclick="@(() => Console.WriteLine("Hello from advanced mode!"))" /> Advanced
</div>
</InputRadioGroup>
@* <label for="provider" class="me-3">Configuration Type:</label>
<input class="form-check-input" type="radio" id="configurationType_basic" name="configurationType" value="Basic" checked="checked">
<label class="form-check-label" for="configurationType_basic">
Basic
</label>
<input class="form-check-input" type="radio" id="configurationType_advanced" name="configurationType" value="Advanced">
<label class="form-check-label" for="configurationType_advanced">
Advanced
</label>
*@ </div>

</div>

<p>
We'll start with
Expand All @@ -42,17 +47,18 @@
</p>

<div class="form-group config-basic">
<label for="provider">Provider</label>
<select class="form-control" id="provider" @bind="Config.Provider">
<label for="provider">Basic Provider</label>
<InputSelect class="form-control" id="provider" @bind-Value="Config.Provider"
@onchange="PrecalculateBasicConnectionString">
<option value="">- SELECT -</option>
<option value="Postgres">Postgres</option>
<option value="Sqlite">Sqlite</option>
<option value="InMemory">InMemory</option>
</select>
<option value="Sqlite">Sqlite - Good for a personal install</option>
<option value="InMemory">InMemory - Good for Testing</option>
</InputSelect>
</div>
<div class="form-group config-basic">
<label for="connectionString">Connection String</label>
<input type="text" class="form-control" id="connectionString" @bind="Config.ConnectionString" />
<InputText class="form-control" id="connectionString" @bind-Value="Config.ConnectionString" />
@* Add a validation message *@
<span asp-validation-for="ConnectionString" class="text-danger"></span>
</div>
Expand All @@ -67,16 +73,16 @@
@* Add fields to select a provider and connectionstring *@
<div class="form-group config-advanced">
<label for="contentProvider">Content Database Provider</label>
<select class="form-control" id="contentProvider" @bind="Config.ContentProvider" >
<InputSelect class="form-control" id="contentProvider" @bind-Value="Config.ContentProvider">
<option value="">- SELECT -</option>
<option value="Postgres">Postgres</option>
<option value="Sqlite">Sqlite</option>
<option value="InMemory">InMemory</option>
</select>
<option value="InMemory">InMemory - Good for testing</option>
</InputSelect>
</div>
<div class="form-group config-advanced">
<label for="connectionString">Content Connection String</label>
<InputText class="form-control" id="connectionString" Value="Config.ContentConnectionString" />
<InputText class="form-control" id="connectionString" @bind-Value="Config.ContentConnectionString" />

<ValidationMessage For="@(() => Config.ContentConnectionString)" class="text-danger"></ValidationMessage>

Expand All @@ -88,19 +94,16 @@
</p>
<div class="form-group config-advanced">
<label for="contentProvider">Security Database Provider</label>
<select class="form-control" id="securityProvider" @bind="Config.SecurityProvider">
<InputSelect class="form-control" id="securityProvider" @bind-Value="Config.SecurityProvider">
<option value="">- SELECT -</option>
<option value="Postgres">Postgres</option>
<option value="Sqlite">Sqlite</option>
</select>
</InputSelect>

</div>
<div class="form-group config-advanced">
<label for="connectionString">Security Connection String</label>
<input type="text" class="form-control" id="securityConnectionString" @bind="Config.SecurityConnectionString" />

@* Add a validation message *@
<span asp-validation-for="SecurityConnectionString" class="text-danger"></span>
<InputText class="form-control" id="securityConnectionString" @bind-Value="Config.SecurityConnectionString" />

</div>

Expand All @@ -110,4 +113,4 @@
<button type="submit" class="btn btn-primary form-control">Submit</button>
</div>

</form>
</EditForm>
Loading

0 comments on commit c7f7221

Please sign in to comment.