feat: implement Blazor web interface for GM session management
Deploy Telegram Bot / deploy (push) Has been cancelled
Deploy Telegram Bot / deploy (push) Has been cancelled
- Created GmRelay.Web project (Blazor Server) - Created GmRelay.Shared library for domain models and rendering - Refactored GmRelay.Bot to use the Shared library - Integrated Telegram Login widget with server-side HMAC verification - Added Dashboard, Group Details, and Edit Session pages - Enabled bot notifications and in-place message updates from web actions - Updated .NET Aspire orchestration and Docker Compose configuration
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
@page "/session/edit/{SessionId:guid}"
|
||||
@using GmRelay.Web.Services
|
||||
@using GmRelay.Shared.Domain
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@attribute [Authorize]
|
||||
@inject SessionService SessionService
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Edit Session - GM-Relay</PageTitle>
|
||||
|
||||
<div class="container mt-4">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/">Dashboard</a></li>
|
||||
<li class="breadcrumb-item active">Edit Session</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h2>Edit Session</h2>
|
||||
|
||||
@if (session == null)
|
||||
{
|
||||
<p>Loading session details...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card shadow-sm mt-4">
|
||||
<div class="card-body">
|
||||
<EditForm Model="@model" OnValidSubmit="HandleSubmit">
|
||||
<div class="mb-3">
|
||||
<label class="form-label font-weight-bold">Game Title</label>
|
||||
<InputText @bind-Value="model.Title" class="form-control" placeholder="e.g. D&D 5e: Dragon's Hoard" />
|
||||
<div class="form-text">Changing this will update all sessions in the same batch.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label font-weight-bold">Scheduled Time (Moscow UTC+3)</label>
|
||||
<input type="datetime-local" @bind="model.ScheduledAtLocal" class="form-control" />
|
||||
<div class="form-text">Current: @session.ScheduledAt.FormatMoscow()</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label font-weight-bold">Join Link</label>
|
||||
<InputText @bind-Value="model.JoinLink" class="form-control" placeholder="Discord or VTT link" />
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<button type="submit" class="btn btn-success" disabled="@isSubmitting">
|
||||
@(isSubmitting ? "Saving..." : "Save Changes")
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-secondary ms-2" @onclick="GoBack">Cancel</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger mt-3">@errorMessage</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid SessionId { get; set; }
|
||||
private WebSession? session;
|
||||
private SessionEditModel model = new();
|
||||
private bool isSubmitting = false;
|
||||
private string? errorMessage;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
session = await SessionService.GetSessionAsync(SessionId);
|
||||
if (session != null)
|
||||
{
|
||||
model.Title = session.Title;
|
||||
// Convert UTC to Moscow for the picker
|
||||
model.ScheduledAtLocal = session.ScheduledAt.ToMoscow();
|
||||
model.JoinLink = session.JoinLink;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSubmit()
|
||||
{
|
||||
isSubmitting = true;
|
||||
errorMessage = null;
|
||||
|
||||
try
|
||||
{
|
||||
// The value from <input type="datetime-local"> is considered as "unspecified" or local to browser.
|
||||
// We treat it as Moscow time (UTC+3) and convert to UTC.
|
||||
var utcTime = new DateTimeOffset(model.ScheduledAtLocal, TimeSpan.FromHours(3)).ToUniversalTime().UtcDateTime;
|
||||
|
||||
await SessionService.UpdateSessionAsync(SessionId, model.Title, utcTime, model.JoinLink);
|
||||
Navigation.NavigateTo($"/group/{session!.GroupId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = "Failed to save changes: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GoBack() => Navigation.NavigateTo("/");
|
||||
|
||||
public class SessionEditModel
|
||||
{
|
||||
public string Title { get; set; } = "";
|
||||
public DateTime ScheduledAtLocal { get; set; } = DateTime.Now;
|
||||
public string JoinLink { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
@page "/Error"
|
||||
@using System.Diagnostics
|
||||
|
||||
<PageTitle>Error</PageTitle>
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
|
||||
@code{
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private string? RequestId { get; set; }
|
||||
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
protected override void OnInitialized() =>
|
||||
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
@page "/group/{GroupId:guid}"
|
||||
@using GmRelay.Web.Services
|
||||
@using GmRelay.Shared.Domain
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@attribute [Authorize]
|
||||
@inject SessionService SessionService
|
||||
|
||||
<PageTitle>Group Sessions - GM-Relay</PageTitle>
|
||||
|
||||
<div class="container mt-4">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/">Dashboard</a></li>
|
||||
<li class="breadcrumb-item active">Group Sessions</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h2>Upcoming Sessions</h2>
|
||||
|
||||
<div class="mt-4">
|
||||
@if (sessions == null)
|
||||
{
|
||||
<p>Loading sessions...</p>
|
||||
}
|
||||
else if (sessions.Count == 0)
|
||||
{
|
||||
<div class="alert alert-info">No upcoming sessions found for this group.</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Time (MSK)</th>
|
||||
<th>Status</th>
|
||||
<th>Link</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var session in sessions)
|
||||
{
|
||||
<tr>
|
||||
<td>@session.Title</td>
|
||||
<td>@session.ScheduledAt.FormatMoscow()</td>
|
||||
<td>
|
||||
<span class="badge @GetStatusClass(session.Status)">@session.Status</span>
|
||||
</td>
|
||||
<td><a href="@session.JoinLink" target="_blank" class="text-truncate d-inline-block" style="max-width: 150px;">Link</a></td>
|
||||
<td>
|
||||
<a href="/session/edit/@session.Id" class="btn btn-sm btn-outline-secondary">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid GroupId { get; set; }
|
||||
private List<WebSession>? sessions;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
sessions = await SessionService.GetUpcomingSessionsAsync(GroupId);
|
||||
}
|
||||
|
||||
private string GetStatusClass(string status) => status switch
|
||||
{
|
||||
SessionStatus.Confirmed => "bg-success",
|
||||
SessionStatus.Cancelled => "bg-danger",
|
||||
SessionStatus.ConfirmationSent => "bg-warning text-dark",
|
||||
_ => "bg-secondary"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
@page "/"
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using GmRelay.Web.Services
|
||||
@attribute [Authorize]
|
||||
@inject SessionService SessionService
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
|
||||
<PageTitle>Dashboard - GM-Relay</PageTitle>
|
||||
|
||||
<div class="container mt-4">
|
||||
<h2>Welcome, @userName!</h2>
|
||||
<p class="text-muted">Select a group to manage your game sessions.</p>
|
||||
|
||||
<div class="row mt-4">
|
||||
@if (groups == null)
|
||||
{
|
||||
<p>Loading groups...</p>
|
||||
}
|
||||
else if (groups.Count == 0)
|
||||
{
|
||||
<div class="col-12">
|
||||
<div class="card bg-light">
|
||||
<div class="card-body text-center">
|
||||
<p class="mb-0">You don't have any groups registered yet. Use the bot in a Telegram group first!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var group in groups)
|
||||
{
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card h-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@group.Name</h5>
|
||||
<p class="card-text text-muted">ID: @group.TelegramChatId</p>
|
||||
<a href="/group/@group.Id" class="btn btn-primary">View Sessions</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<WebGameGroup>? groups;
|
||||
private string userName = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
userName = user.Identity?.Name ?? "Game Master";
|
||||
|
||||
var telegramIdClaim = user.FindFirst("TelegramId")?.Value;
|
||||
if (long.TryParse(telegramIdClaim, out var telegramId))
|
||||
{
|
||||
groups = await SessionService.GetGroupsForGmAsync(telegramId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
@page "/login"
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@inject NavigationManager Navigation
|
||||
@inject IConfiguration Configuration
|
||||
|
||||
<PageTitle>Login - GM-Relay</PageTitle>
|
||||
|
||||
<div class="container">
|
||||
<div class="row justify-content-center mt-5">
|
||||
<div class="col-md-6 text-center">
|
||||
<h3>GM-Relay Control Panel</h3>
|
||||
<p class="text-muted">Please log in as a Game Master to manage your sessions.</p>
|
||||
|
||||
<div class="mt-4">
|
||||
@if (Navigation.Uri.Contains("error=auth_failed"))
|
||||
{
|
||||
<div class="alert alert-danger">Authentication failed. Please try again.</div>
|
||||
}
|
||||
|
||||
@* Telegram Login Widget *@
|
||||
<div id="telegram-login-container">
|
||||
<script async src="https://telegram.org/js/telegram-widget.js?22"
|
||||
data-telegram-login="@BotUsername"
|
||||
data-size="large"
|
||||
data-auth-url="@AuthUrl"
|
||||
data-request-access="write"></script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string BotUsername => Configuration["Telegram:BotUsername"] ?? "GmRelayBot";
|
||||
private string AuthUrl => Navigation.ToAbsoluteUri("/auth/telegram").ToString();
|
||||
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask is not null)
|
||||
{
|
||||
var user = (await AuthStateTask).User;
|
||||
if (user.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
Navigation.NavigateTo("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@page "/not-found"
|
||||
@layout MainLayout
|
||||
|
||||
<h3>Not Found</h3>
|
||||
<p>Sorry, the content you are looking for does not exist.</p>
|
||||
Reference in New Issue
Block a user