306 lines
11 KiB
Plaintext
306 lines
11 KiB
Plaintext
@using Notemark.Models
|
|
@using Notemark.Services
|
|
@inject IVaultService VaultService
|
|
@inject IJSRuntime JSRuntime
|
|
@inject NavigationManager Navigation
|
|
|
|
@if (IsOpen)
|
|
{
|
|
<div class="vault-backdrop" @onclick="Close"></div>
|
|
<div class="vault-modal @(isUnlocked ? "vault-wide" : "vault-compact")">
|
|
@if (!isUnlocked)
|
|
{
|
|
<!-- Locked PIN Entry Screen -->
|
|
<div class="vault-pin-screen">
|
|
<div class="vault-pin-icon">🔐</div>
|
|
<h2>Master Vault</h2>
|
|
<p>Enter administrator PIN to access all server documents.</p>
|
|
|
|
<div class="pin-form">
|
|
<input type="password"
|
|
class="pin-input @(hasError ? "pin-error" : "")"
|
|
placeholder="Enter PIN..."
|
|
@bind="pinInput"
|
|
@bind:event="oninput"
|
|
@onkeydown="OnPinKeyDown"
|
|
autofocus />
|
|
<button type="button" class="btn-unlock" @onclick="SubmitPin">
|
|
Unlock
|
|
</button>
|
|
</div>
|
|
|
|
@if (hasError)
|
|
{
|
|
<div class="pin-error-msg">⚠️ Incorrect PIN code. Access denied.</div>
|
|
}
|
|
|
|
<div class="vault-pin-footer">
|
|
<button type="button" class="btn-cancel" @onclick="Close">Cancel</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<!-- Unlocked Document Archive -->
|
|
<div class="vault-content">
|
|
<div class="vault-header">
|
|
<div class="vault-header-title">
|
|
<span class="vault-badge">🗄️ Master Vault</span>
|
|
<h2>All Server Documents (@allDocs.Count)</h2>
|
|
</div>
|
|
<div class="vault-header-actions">
|
|
<button type="button" class="btn-lock-vault" @onclick="LockVault" title="Lock the vault again">
|
|
🔒 Lock Vault
|
|
</button>
|
|
<button type="button" class="btn-close-vault" @onclick="Close" title="Close">✕</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="vault-toolbar">
|
|
<div class="vault-search">
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="11" cy="11" r="8"></circle>
|
|
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
|
</svg>
|
|
<input type="text" placeholder="Search across all server documents, snippets or #tags..." @bind="searchQuery" @bind:event="oninput" />
|
|
@if (!string.IsNullOrEmpty(searchQuery))
|
|
{
|
|
<button class="btn-clear-search" @onclick="() => searchQuery = string.Empty">✕</button>
|
|
}
|
|
</div>
|
|
|
|
@if (allTags.Any())
|
|
{
|
|
<div class="vault-tags">
|
|
<button class="tag-chip @(string.IsNullOrEmpty(selectedTag) ? "active" : "")" @onclick="() => selectedTag = string.Empty">
|
|
All
|
|
</button>
|
|
@foreach (var tag in allTags)
|
|
{
|
|
<button class="tag-chip @(selectedTag == tag ? "active" : "")" @onclick="() => selectedTag = (selectedTag == tag ? string.Empty : tag)">
|
|
#@tag
|
|
</button>
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<div class="vault-body">
|
|
@if (isLoadingDocs)
|
|
{
|
|
<div class="vault-loading">
|
|
<div class="spinner"></div>
|
|
<p>Loading documents...</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
var filtered = GetFilteredDocs();
|
|
if (!filtered.Any())
|
|
{
|
|
<div class="vault-empty">
|
|
<p>No documents found matching your filter.</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="vault-grid">
|
|
@foreach (var doc in filtered)
|
|
{
|
|
<div class="vault-card" @onclick="() => OpenDocument(doc.Id)">
|
|
<div class="vault-card-top">
|
|
<h3 class="vault-card-title">@doc.Title</h3>
|
|
<div class="vault-card-actions" @onclick:stopPropagation="true">
|
|
@if (doc.IsFlagged)
|
|
{
|
|
<span class="flag-icon" title="Flagged">🚩</span>
|
|
}
|
|
<button class="btn-doc-delete" @onclick="() => DeleteDocument(doc.Id)" title="Delete note permanently">
|
|
🗑️
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<p class="vault-card-snippet">@doc.Snippet</p>
|
|
|
|
@if (doc.Tags.Any())
|
|
{
|
|
<div class="vault-card-tags" @onclick:stopPropagation="true">
|
|
@foreach (var tag in doc.Tags)
|
|
{
|
|
<span class="vault-tag-pill" @onclick="() => selectedTag = tag">#@tag</span>
|
|
}
|
|
</div>
|
|
}
|
|
|
|
<div class="vault-card-meta">
|
|
<span class="vault-card-date">Modified @FormatDate(doc.LastModifiedAt)</span>
|
|
<span class="vault-card-id" title="Session ID"><code>@doc.Id[..Math.Min(8, doc.Id.Length)]...</code></span>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public bool IsOpen { get; set; }
|
|
[Parameter] public EventCallback<bool> IsOpenChanged { get; set; }
|
|
[Parameter] public EventCallback<string> OnSelectDocument { get; set; }
|
|
|
|
private bool isUnlocked = false;
|
|
private string pinInput = "";
|
|
private bool hasError = false;
|
|
private bool isLoadingDocs = false;
|
|
private string searchQuery = "";
|
|
private string selectedTag = "";
|
|
private List<DocumentMetadata> allDocs = new();
|
|
private List<string> allTags = new();
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (IsOpen)
|
|
{
|
|
try
|
|
{
|
|
var stored = await JSRuntime.InvokeAsync<string?>("sessionStorage.getItem", "notemark_vault_unlocked");
|
|
if (stored == "true")
|
|
{
|
|
isUnlocked = true;
|
|
await LoadAllDocs();
|
|
}
|
|
else
|
|
{
|
|
isUnlocked = false;
|
|
pinInput = "";
|
|
hasError = false;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
isUnlocked = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task OnPinKeyDown(KeyboardEventArgs e)
|
|
{
|
|
if (e.Key == "Enter")
|
|
{
|
|
await SubmitPin();
|
|
}
|
|
}
|
|
|
|
private async Task SubmitPin()
|
|
{
|
|
hasError = false;
|
|
if (VaultService.VerifyPin(pinInput))
|
|
{
|
|
isUnlocked = true;
|
|
pinInput = "";
|
|
try
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("sessionStorage.setItem", "notemark_vault_unlocked", "true");
|
|
}
|
|
catch { }
|
|
await LoadAllDocs();
|
|
}
|
|
else
|
|
{
|
|
hasError = true;
|
|
}
|
|
}
|
|
|
|
private async Task LoadAllDocs()
|
|
{
|
|
isLoadingDocs = true;
|
|
StateHasChanged();
|
|
try
|
|
{
|
|
allDocs = await VaultService.GetAllDocumentsAsync();
|
|
allTags = allDocs.SelectMany(d => d.Tags)
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
|
.OrderBy(t => t)
|
|
.ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine($"[Vault Load Error] {ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
isLoadingDocs = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private List<DocumentMetadata> GetFilteredDocs()
|
|
{
|
|
var list = allDocs.AsEnumerable();
|
|
|
|
if (!string.IsNullOrEmpty(selectedTag))
|
|
{
|
|
list = list.Where(d => d.Tags.Any(t => t.Equals(selectedTag, StringComparison.OrdinalIgnoreCase)));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchQuery))
|
|
{
|
|
var q = searchQuery.Trim().ToLowerInvariant();
|
|
list = list.Where(d => d.Title.ToLowerInvariant().Contains(q) ||
|
|
d.Snippet.ToLowerInvariant().Contains(q) ||
|
|
d.Id.ToLowerInvariant().Contains(q) ||
|
|
d.Tags.Any(t => t.ToLowerInvariant().Contains(q)));
|
|
}
|
|
|
|
return list.OrderByDescending(d => d.LastModifiedAt).ToList();
|
|
}
|
|
|
|
private async Task OpenDocument(string id)
|
|
{
|
|
await OnSelectDocument.InvokeAsync(id);
|
|
await Close();
|
|
}
|
|
|
|
private async Task DeleteDocument(string id)
|
|
{
|
|
try
|
|
{
|
|
await VaultService.DeleteDocumentAsync(id);
|
|
await LoadAllDocs();
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private async Task LockVault()
|
|
{
|
|
isUnlocked = false;
|
|
pinInput = "";
|
|
hasError = false;
|
|
try
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("sessionStorage.removeItem", "notemark_vault_unlocked");
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private async Task Close()
|
|
{
|
|
IsOpen = false;
|
|
await IsOpenChanged.InvokeAsync(false);
|
|
}
|
|
|
|
private string FormatDate(DateTime date)
|
|
{
|
|
var diff = DateTime.UtcNow - date;
|
|
if (diff.TotalMinutes < 1) return "Just now";
|
|
if (diff.TotalMinutes < 60) return $"{(int)diff.TotalMinutes}m ago";
|
|
if (diff.TotalHours < 24) return $"{(int)diff.TotalHours}h ago";
|
|
if (diff.TotalDays < 7) return $"{(int)diff.TotalDays}d ago";
|
|
return date.ToLocalTime().ToString("MMM dd, yyyy HH:mm");
|
|
}
|
|
}
|