New page Stammdaten -> JSON-Editor edits the data files of the selected year
and mandator (default Transactions.json) as plain JSON in Monaco (BlazorMonaco
3.5.0, loaded on demand): highlighting, folding, live syntax errors, search
and replace with regex, format.
RawDataRepository saves only validated text: strict JSON (unknown properties
rejected with line/column), unique non-empty Ids, transactions referencing
existing accounts, accounts still used by transactions not removed. It refuses
if the file changed since loading, backs up the previous version to
backup/{mandator}/{year}/json-{timestamp}/, and saves through BaseRepository
so caches are refreshed.
- Hub MaximumReceiveMessageSize raised to 8 MB (files are several hundred KB)
- unsaved-guard.js asks before leaving with unsaved changes; NavigationLock
doesn't apply because routing between per-page interactive pages is static
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
3.9 KiB
Text
93 lines
3.9 KiB
Text
@page "/json-editor"
|
|
@rendermode InteractiveServer
|
|
@using BlazorMonaco.Editor
|
|
|
|
<PageTitle>JSON-Editor</PageTitle>
|
|
|
|
@if (file is null)
|
|
{
|
|
<Loading/>
|
|
return;
|
|
}
|
|
|
|
<div class="json-editor">
|
|
<div class="toolbar">
|
|
<FluentSelect TOption="string" Label="Datei" Width="230px"
|
|
Items="@repository.FileNames"
|
|
OptionText="@(n => n)"
|
|
OptionValue="@(n => n)"
|
|
SelectedOption="@fileName"
|
|
SelectedOptionChanged="@OnFileChanged"/>
|
|
|
|
<div class="actions">
|
|
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size16.Save())"
|
|
Disabled="@(dirty == false || saving || monacoLoaded == false)" Loading="@saving"
|
|
OnClick="SaveAsync">Speichern</FluentButton>
|
|
<FluentButton Appearance="Appearance.Neutral" IconStart="@(new Icons.Regular.Size16.ArrowClockwise())"
|
|
Disabled="@(monacoLoaded == false)" OnClick="ReloadAsync">Neu laden</FluentButton>
|
|
<span class="separator"></span>
|
|
<FluentButton Appearance="Appearance.Neutral" IconStart="@(new Icons.Regular.Size16.Search())"
|
|
Disabled="@(monacoLoaded == false)" title="Suchen (Ctrl+F)"
|
|
OnClick="@(() => RunEditorActionAsync("actions.find"))">Suchen</FluentButton>
|
|
<FluentButton Appearance="Appearance.Neutral" IconStart="@(new Icons.Regular.Size16.ArrowSwap())"
|
|
Disabled="@(monacoLoaded == false)" title="Suchen und ersetzen (Ctrl+H)"
|
|
OnClick="@(() => RunEditorActionAsync("editor.action.startFindReplaceAction"))">Ersetzen</FluentButton>
|
|
<FluentButton Appearance="Appearance.Neutral" IconStart="@(new Icons.Regular.Size16.TextAlignLeft())"
|
|
Disabled="@(monacoLoaded == false)" title="Formatieren (Shift+Alt+F)"
|
|
OnClick="@(() => RunEditorActionAsync("editor.action.formatDocument"))">Formatieren</FluentButton>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="status">
|
|
<span>@Location / @fileName</span>
|
|
<span>@SizeLabel</span>
|
|
@if (dirty)
|
|
{
|
|
<span class="dirty">● Ungespeicherte Änderungen</span>
|
|
}
|
|
</div>
|
|
|
|
@if (errors.Count > 0)
|
|
{
|
|
<FluentMessageBar Intent="MessageIntent.Error" AllowDismiss="false" Title="Nicht gespeichert">
|
|
<ul class="errors">
|
|
@foreach (var error in errors)
|
|
{
|
|
<li>
|
|
@if (LineOf(error) is { } line)
|
|
{
|
|
<button type="button" class="link" title="Zu Zeile @line springen" @onclick="@(() => GoToLineAsync(line))">@error</button>
|
|
}
|
|
else
|
|
{
|
|
@error
|
|
}
|
|
</li>
|
|
}
|
|
</ul>
|
|
</FluentMessageBar>
|
|
}
|
|
|
|
<div class="editor-frame">
|
|
@if (monacoError is not null)
|
|
{
|
|
<FluentMessageBar Intent="MessageIntent.Error" AllowDismiss="false">Der Editor konnte nicht geladen werden: @monacoError</FluentMessageBar>
|
|
}
|
|
else if (monacoLoaded)
|
|
{
|
|
<StandaloneCodeEditor @ref="editor" Id="json-editor" CssClass="monaco-host"
|
|
ConstructionOptions="EditorOptions"
|
|
OnDidInit="OnEditorInit"
|
|
OnDidChangeModelContent="OnContentChanged"/>
|
|
}
|
|
else
|
|
{
|
|
<Loading/>
|
|
}
|
|
</div>
|
|
|
|
<div class="hint">
|
|
Gespeichert wird nur gültiges JSON mit bekannten Feldern, eindeutigen Ids und (bei Buchungen) existierenden Konten.
|
|
Vor dem Speichern wird die bisherige Datei unter backup/… gesichert. Suchen und Ersetzen können reguläre Ausdrücke (.*).
|
|
</div>
|
|
</div>
|