428 lines
15 KiB
Text
428 lines
15 KiB
Text
@inherits LayoutComponentBase
|
|
@implements IDisposable
|
|
@inject IProjectService ProjectService
|
|
@inject ISettingsService SettingsService
|
|
@inject IThemeService ThemeService
|
|
@inject OllamaSettings OllamaSettings
|
|
|
|
<div class="page">
|
|
<div class="main-content">
|
|
<aside class="sidebar">
|
|
<div class="nav-section">
|
|
<button class="nav-section-header" @onclick='() => ToggleSection("file")'>
|
|
<span class="nav-icon">@(activeSection == "file" ? "▼" : "▶")</span>
|
|
Datei
|
|
</button>
|
|
@if (activeSection == "file")
|
|
{
|
|
<div class="nav-section-body">
|
|
<button class="nav-item" @onclick="CreateNewProject">Neues Projekt</button>
|
|
<button class="nav-item" @onclick="OpenEditor">Editor öffnen</button>
|
|
<div class="nav-separator"></div>
|
|
<button class="nav-item" @onclick="ExitApp">Beenden</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
<div class="nav-section">
|
|
<button class="nav-section-header" @onclick='() => ToggleSection("extras")'>
|
|
<span class="nav-icon">@(activeSection == "extras" ? "▼" : "▶")</span>
|
|
Extras
|
|
</button>
|
|
@if (activeSection == "extras")
|
|
{
|
|
<div class="nav-section-body">
|
|
<button class="nav-item" @onclick='() => NavigateTo("/settings")'>Einstellungen</button>
|
|
<button class="nav-item" @onclick='() => NavigateTo("/models")'>Modelle verwalten</button>
|
|
<button class="nav-item" @onclick='() => NavigateTo("/assistant")'>Assistent</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
<div class="nav-section">
|
|
<button class="nav-section-header" @onclick='() => ToggleSection("projects")'>
|
|
<span class="nav-icon">@(activeSection == "projects" ? "▼" : "▶")</span>
|
|
Projekte
|
|
</button>
|
|
@if (activeSection == "projects")
|
|
{
|
|
<div class="nav-section-body">
|
|
<button class="nav-item nav-item-toggle" @onclick='() => showProjectList = !showProjectList'>
|
|
<span class="nav-icon">@(showProjectList ? "▼" : "▶")</span>
|
|
Liste vorhandener Projekte
|
|
</button>
|
|
@if (showProjectList)
|
|
{
|
|
<div class="nav-sublist">
|
|
@if (projects == null)
|
|
{
|
|
<span class="nav-hint">Lade Projekte...</span>
|
|
}
|
|
else if (projects.Count == 0)
|
|
{
|
|
<span class="nav-hint">Keine Projekte vorhanden.</span>
|
|
}
|
|
else
|
|
{
|
|
@foreach (var p in projects)
|
|
{
|
|
<button class="nav-item nav-item-sub @(p.Id == currentProjectId ? "active" : "")" @onclick='() => SelectProject(p)'>@p.Name</button>
|
|
}
|
|
}
|
|
</div>
|
|
}
|
|
<div class="nav-separator"></div>
|
|
<button class="nav-item" @onclick="CreateNewProject">Projekt erstellen</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
@if (currentProjectId > 0 && fileTree != null)
|
|
{
|
|
<div class="nav-section nav-section-open">
|
|
<div class="nav-section-header">
|
|
<span>Projektdateien</span>
|
|
<span class="nav-header-actions">
|
|
<button class="nav-item-icon" @onclick="RefreshFileTree" title="Dateibaum aktualisieren">↻</button>
|
|
</span>
|
|
</div>
|
|
<div class="nav-section-body">
|
|
@foreach (var item in fileTree)
|
|
{
|
|
<div class="tree-item @(item.IsDirectory ? "dir" : "file") @(item.FullPath == currentFilePath ? "active" : "")"
|
|
@onclick="() => OpenFile(item)">
|
|
<span class="tree-icon">@(item.IsDirectory ? "📁" : "📄")</span>
|
|
<span class="tree-name">@item.Name</span>
|
|
@if (item.IsDirectory)
|
|
{
|
|
<button class="tree-rename" @onclick="() => BeginNewFile(item)" @onclick:stopPropagation title="Neue Datei">+</button>
|
|
}
|
|
else
|
|
{
|
|
<button class="tree-rename" @onclick="() => BeginRename(item)" @onclick:stopPropagation title="Umbenennen">✎</button>
|
|
}
|
|
</div>
|
|
@foreach (var child in item.Children)
|
|
{
|
|
<div class="tree-item file tree-child @(child.FullPath == currentFilePath ? "active" : "")"
|
|
@onclick="() => OpenFile(child)">
|
|
<span class="tree-icon">📄</span>
|
|
<span class="tree-name">@child.Name</span>
|
|
<button class="tree-rename" @onclick="() => BeginRename(child)" @onclick:stopPropagation title="Umbenennen">✎</button>
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (showRenameDialog)
|
|
{
|
|
<div class="modal-overlay">
|
|
<div class="modal-dialog">
|
|
<div class="modal-title">Datei umbenennen</div>
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<label>Neuer Name</label>
|
|
<input @bind="renameNewName" placeholder="neuer_name.md" />
|
|
</div>
|
|
</div>
|
|
<div class="modal-actions">
|
|
<button @onclick="CancelRename">Abbrechen</button>
|
|
<button @onclick="ConfirmRename" disabled="@(string.IsNullOrWhiteSpace(renameNewName))" class="primary">Umbenennen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (showNewFileDialog)
|
|
{
|
|
<div class="modal-overlay">
|
|
<div class="modal-dialog">
|
|
<div class="modal-title">Neue Datei</div>
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<label>Dateiname</label>
|
|
<input @bind="newFileName" placeholder="meine_datei.md" />
|
|
</div>
|
|
</div>
|
|
<div class="modal-actions">
|
|
<button @onclick="CancelNewFile">Abbrechen</button>
|
|
<button @onclick="ConfirmNewFile" disabled="@(string.IsNullOrWhiteSpace(newFileName))" class="primary">Erstellen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</aside>
|
|
|
|
<main class="detail-panel">
|
|
@Body
|
|
</main>
|
|
</div>
|
|
|
|
<footer class="status-bar">
|
|
<span class="status-dot connected"></span>
|
|
<span class="status-text">@statusText</span>
|
|
@if (isBusy)
|
|
{
|
|
<progress value="@operationProgress" max="100"></progress>
|
|
}
|
|
</footer>
|
|
</div>
|
|
|
|
@code {
|
|
private string? activeSection;
|
|
private bool showProjectList;
|
|
private List<Project>? projects;
|
|
private List<FileTreeItem>? fileTree;
|
|
private int currentProjectId;
|
|
private string? currentFilePath;
|
|
private string statusText = "Bereit";
|
|
private bool isBusy;
|
|
private double operationProgress;
|
|
private bool showRenameDialog;
|
|
private string renameNewName = string.Empty;
|
|
private FileTreeItem? renameTarget;
|
|
private bool showNewFileDialog;
|
|
private string newFileName = string.Empty;
|
|
private FileTreeItem? newFileParentDir;
|
|
|
|
[Inject]
|
|
private NavigationManager Navigation { get; set; } = default!;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await SettingsService.InitializeAsync();
|
|
Navigation.LocationChanged += OnLocationChanged;
|
|
await LoadProjects();
|
|
await LoadProjectContext();
|
|
await AutoLoadLastProject();
|
|
}
|
|
|
|
private async Task AutoLoadLastProject()
|
|
{
|
|
if (currentProjectId > 0) return;
|
|
var lastId = await SettingsService.GetLastProjectIdAsync();
|
|
if (lastId == null) return;
|
|
var project = projects?.FirstOrDefault(p => p.Id == lastId.Value);
|
|
if (project != null)
|
|
{
|
|
await SettingsService.InitializeAsync(lastId.Value);
|
|
await SelectProject(project);
|
|
}
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
var theme = OllamaSettings.Theme;
|
|
if (!string.IsNullOrEmpty(theme))
|
|
await ThemeService.ApplyTheme(theme);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Navigation.LocationChanged -= OnLocationChanged;
|
|
}
|
|
|
|
private async void OnLocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e)
|
|
{
|
|
await LoadProjects();
|
|
await LoadProjectContext();
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task LoadProjectContext()
|
|
{
|
|
currentProjectId = SettingsService.CurrentProjectId ?? 0;
|
|
currentFilePath = SettingsService.CurrentFilePath;
|
|
|
|
if (currentProjectId > 0)
|
|
{
|
|
await LoadFileTree();
|
|
}
|
|
else
|
|
{
|
|
fileTree = null;
|
|
}
|
|
}
|
|
|
|
private async Task LoadFileTree()
|
|
{
|
|
try
|
|
{
|
|
fileTree = await ProjectService.GetProjectFileTreeAsync(currentProjectId);
|
|
}
|
|
catch
|
|
{
|
|
fileTree = new();
|
|
}
|
|
}
|
|
|
|
private async Task LoadProjects()
|
|
{
|
|
try
|
|
{
|
|
projects = await ProjectService.GetAllProjectsAsync();
|
|
}
|
|
catch
|
|
{
|
|
projects = new();
|
|
}
|
|
}
|
|
|
|
private void ToggleSection(string section)
|
|
{
|
|
activeSection = activeSection == section ? null : section;
|
|
}
|
|
|
|
private void ExitApp()
|
|
{
|
|
activeSection = null;
|
|
Navigation.NavigateTo("/");
|
|
}
|
|
|
|
private void CreateNewProject()
|
|
{
|
|
activeSection = null;
|
|
Navigation.NavigateTo("/editor/newproject");
|
|
}
|
|
|
|
private void OpenEditor()
|
|
{
|
|
activeSection = null;
|
|
Navigation.NavigateTo("/editor");
|
|
}
|
|
|
|
private void NavigateTo(string path)
|
|
{
|
|
activeSection = null;
|
|
Navigation.NavigateTo(path);
|
|
}
|
|
|
|
private async Task SelectProject(Project project)
|
|
{
|
|
activeSection = "files";
|
|
SettingsService.CurrentProjectId = project.Id;
|
|
currentProjectId = project.Id;
|
|
SettingsService.CurrentFilePath = null;
|
|
await SettingsService.SaveLastProjectIdAsync(project.Id);
|
|
await SettingsService.LoadProjectSettingsAsync();
|
|
await LoadFileTree();
|
|
Navigation.NavigateTo($"/editor/index/{project.Id}");
|
|
}
|
|
|
|
private async Task RefreshFileTree()
|
|
{
|
|
await LoadFileTree();
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void BeginRename(FileTreeItem item)
|
|
{
|
|
renameTarget = item;
|
|
renameNewName = item.Name;
|
|
showRenameDialog = true;
|
|
}
|
|
|
|
private void CancelRename()
|
|
{
|
|
showRenameDialog = false;
|
|
renameTarget = null;
|
|
renameNewName = string.Empty;
|
|
}
|
|
|
|
private async Task ConfirmRename()
|
|
{
|
|
if (renameTarget == null || string.IsNullOrWhiteSpace(renameNewName)) return;
|
|
|
|
try
|
|
{
|
|
var dir = Path.GetDirectoryName(renameTarget.FullPath)!;
|
|
var newPath = Path.Combine(dir, renameNewName);
|
|
if (File.Exists(newPath))
|
|
{
|
|
statusText = "Datei existiert bereits.";
|
|
return;
|
|
}
|
|
File.Move(renameTarget.FullPath, newPath);
|
|
|
|
if (currentFilePath == renameTarget.FullPath)
|
|
SettingsService.CurrentFilePath = newPath;
|
|
|
|
statusText = $"Umbenannt zu: {renameNewName}";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statusText = $"Fehler: {ex.Message}";
|
|
}
|
|
finally
|
|
{
|
|
showRenameDialog = false;
|
|
renameTarget = null;
|
|
renameNewName = string.Empty;
|
|
await LoadFileTree();
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private void BeginNewFile(FileTreeItem dir)
|
|
{
|
|
newFileParentDir = dir;
|
|
newFileName = string.Empty;
|
|
showNewFileDialog = true;
|
|
}
|
|
|
|
private void CancelNewFile()
|
|
{
|
|
showNewFileDialog = false;
|
|
newFileParentDir = null;
|
|
newFileName = string.Empty;
|
|
}
|
|
|
|
private async Task ConfirmNewFile()
|
|
{
|
|
if (newFileParentDir == null || string.IsNullOrWhiteSpace(newFileName)) return;
|
|
|
|
try
|
|
{
|
|
var path = Path.Combine(newFileParentDir.FullPath, newFileName);
|
|
if (!path.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
|
|
path += ".md";
|
|
if (File.Exists(path))
|
|
{
|
|
statusText = "Datei existiert bereits.";
|
|
return;
|
|
}
|
|
File.WriteAllText(path, $"# {Path.GetFileNameWithoutExtension(path)}\n\n");
|
|
statusText = $"Erstellt: {Path.GetFileName(path)}";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statusText = $"Fehler: {ex.Message}";
|
|
}
|
|
finally
|
|
{
|
|
showNewFileDialog = false;
|
|
newFileParentDir = null;
|
|
newFileName = string.Empty;
|
|
await LoadFileTree();
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private void OpenFile(FileTreeItem item)
|
|
{
|
|
if (item.IsDirectory) return;
|
|
activeSection = null;
|
|
SettingsService.CurrentFilePath = item.FullPath;
|
|
Navigation.NavigateTo($"/editor/file/{currentProjectId}?t={DateTime.Now.Ticks}");
|
|
}
|
|
|
|
public void SetStatus(string text, bool busy = false, double progress = 0)
|
|
{
|
|
statusText = text;
|
|
isBusy = busy;
|
|
operationProgress = progress;
|
|
StateHasChanged();
|
|
}
|
|
}
|