Files
chapter-organizer/WebApp/Components/Pages/NoteHistoryDialog.razor
T
poprhythm 5c4aaf91df Add Note and NoteHistory entities with configurations and service implementation
This commit introduces the Note and NoteHistory entities, along with their respective configurations for Entity Framework Core. The AppDbContext has been updated to include DbSet properties for both entities. A new INotesService interface and its implementation, NotesService, have been created to handle CRUD operations for notes, including history tracking. Additionally, several Blazor components have been added for note management, including dialogs for editing notes and viewing note history. The UI has been enhanced to support markdown content rendering and improved user interaction for note creation and editing. These changes contribute to a comprehensive note-taking feature within the application.
2026-01-15 21:47:01 -05:00

126 lines
3.6 KiB
Plaintext

@using Core.Entities
@using WebApp.Services
@using MudBlazor
@inject INotesService NotesService
@inject IDialogService DialogService
<MudDialog>
<DialogContent>
@if (_isLoading)
{
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-4" />
}
else if (!_history.Any())
{
<MudText Typo="Typo.body1" Align="Align.Center" Class="my-4">
No history available for this note.
</MudText>
}
else
{
<MudTable Items="@_history" Hover="true" Striped="true" Dense="true">
<HeaderContent>
<MudTh>Date/Time</MudTh>
<MudTh>User</MudTh>
<MudTh>Change Type</MudTh>
<MudTh>Title</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date/Time">
@context.ModifiedAt.ToString("g")
</MudTd>
<MudTd DataLabel="User">
@(context.ModifiedBy ?? "Unknown")
</MudTd>
<MudTd DataLabel="Change Type">
<MudChip T="string" Size="Size.Small"
Color="@GetChangeTypeColor(context.ChangeType)">
@context.ChangeType
</MudChip>
</MudTd>
<MudTd DataLabel="Title">
@context.Title
</MudTd>
<MudTd DataLabel="Actions">
<MudButton StartIcon="@Icons.Material.Filled.Visibility"
OnClick="() => ViewVersion(context)"
Variant="Variant.Text"
Size="Size.Small">
View
</MudButton>
</MudTd>
</RowTemplate>
</MudTable>
}
</DialogContent>
<DialogActions>
<MudButton OnClick="Close">Close</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public int NoteId { get; set; }
private List<NoteHistory> _history = [];
private bool _isLoading = true;
protected override async Task OnInitializedAsync()
{
await LoadHistory();
}
private async Task LoadHistory()
{
try
{
_history = (await NotesService.GetNoteHistoryAsync(NoteId)).ToList();
}
catch (Exception ex)
{
// Error handling - could show snackbar if we had access
}
finally
{
_isLoading = false;
}
}
private Color GetChangeTypeColor(string changeType)
{
return changeType switch
{
"Created" => Color.Success,
"Updated" => Color.Info,
"Deleted" => Color.Error,
_ => Color.Default
};
}
private async Task ViewVersion(NoteHistory history)
{
var parameters = new DialogParameters
{
["History"] = history
};
var options = new DialogOptions
{
MaxWidth = MaxWidth.Large,
FullWidth = true,
CloseButton = true
};
await DialogService.ShowAsync<NoteVersionViewDialog>("View Version", parameters, options);
}
private void Close()
{
MudDialog.Close();
}
}