Files
LehrerApp/LehrerApp.Desktop/Views/Groups/PlanningTabView.axaml.cs
T
admin 8495e1b8d0 KI-gestützte Planungsunterstützung (4.5.9) + Kompetenzkatalog-Import (8.1.2)
KI-Unterstützung: neuer Einstellungen-Tab (Anmeldung, Guthaben) und Button im
Planungs-Tab, der Einheiten+Stunden als JSON an ein neues PHP-Backend (ai-backend/)
sendet und die Antwort als prüfbare Vorschlagsliste zurückbringt. Provider-Aufruf,
Guthabenverwaltung und Abrechnung nach echten Token-Kosten laufen serverseitig, der
Desktop-Client sieht nie einen LLM-API-Key. Zentral abgesichert: eine von der KI
zurückgegebene Stunden-Id, die zu keiner echten Lesson der Einheit passt, wird nie
als Update übernommen, sondern immer als neue Stunde behandelt.

Kompetenzkatalog-Import (8.1.2): JSON-Export/Import für Kompetenzkataloge.
2026-08-16 01:31:14 +02:00

168 lines
7.0 KiB
C#

using Avalonia.Controls;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Core.Services;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels.Groups;
using LehrerApp.Desktop.Views.Shared;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Groups;
public partial class PlanningTabView : UserControl
{
public PlanningTabView() => InitializeComponent();
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is PlanningTabViewModel vm)
{
vm.OnAddUnit = groupId => ShowUnitDialog(groupId, editingUnit: null);
vm.OnEditUnit = unit => ShowUnitDialog(unit.GroupId, editingUnit: unit);
vm.OnConfirmDeleteUnit = ShowDeleteUnitDialog;
vm.OnPickCopyTarget = ShowCopyUnitDialog;
vm.OnAddLesson = (unitId, groupId, materials, shorthands) =>
ShowLessonDialog(unitId, groupId, materials, shorthands, editingLesson: null);
vm.OnEditLesson = (lesson, materials, shorthands) =>
ShowLessonDialog(lesson.UnitId, lesson.GroupId, materials, shorthands, editingLesson: lesson);
vm.OnConfirmDeleteLesson = ShowDeleteLessonDialog;
vm.OnPickMoveTarget = ShowMoveLessonDialog;
vm.OnShowLesson = ShowLessonViewerDialog;
vm.OnGenerateLessonSeries = ShowGenerateLessonSeriesDialog;
vm.OnAiAssist = ShowAiAssistDialog;
}
}
private async Task<bool> ShowUnitDialog(Guid groupId, Unit? editingUnit)
{
if (DataContext is not PlanningTabViewModel vm) return false;
var dialogVm = new UnitDialogViewModel(
App.Services.GetRequiredService<IUnitRepository>(),
App.Services.GetRequiredService<ICompetencyDomainRepository>(),
groupId, vm.SubjectId, vm.GradeLevel, vm.SubjectName, editingUnit);
var dialog = new UnitDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return false;
var ok = await dialog.ShowDialog<bool>(owner);
return ok && dialogVm.Result is not null;
}
private async Task<bool> ShowDeleteUnitDialog(UnitSummary unit)
{
var info = new ConfirmDialogInfo
{
Title = "Einheit löschen?",
Message = $"\"{unit.Title}\" wird inkl. aller zugehörigen Stunden endgültig gelöscht.",
ConfirmText = "Löschen",
};
var dialog = new ConfirmDialog { DataContext = info };
var owner = TopLevel.GetTopLevel(this) as Window;
return owner is not null && await dialog.ShowDialog<bool>(owner);
}
private async Task<CopyUnitTarget?> ShowCopyUnitDialog(Unit unit)
{
var dialogVm = new CopyUnitDialogViewModel(
App.Services.GetRequiredService<IGroupRepository>(), unit.GroupId);
var dialog = new CopyUnitDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var ok = await dialog.ShowDialog<bool>(owner);
return ok ? dialogVm.Result : null;
}
private async Task<bool> ShowLessonDialog(Guid unitId, Guid groupId,
List<string> materialSuggestions, List<string> shorthandHistorySuggestions, Lesson? editingLesson)
{
var dialogVm = new LessonDialogViewModel(
App.Services.GetRequiredService<ILessonRepository>(),
App.Services.GetRequiredService<IShorthandCodeRepository>(),
App.Services.GetRequiredService<IAlternativeLessonPathRepository>(),
App.Services.GetRequiredService<ITimetableSlotRepository>(),
App.Services.GetRequiredService<PeriodScheduleService>(),
unitId, groupId, materialSuggestions, shorthandHistorySuggestions, editingLesson);
var dialog = new LessonDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return false;
var ok = await dialog.ShowDialog<bool>(owner);
return ok && dialogVm.Result is not null;
}
private async Task<bool> ShowDeleteLessonDialog(LessonSummary lesson)
{
var info = new ConfirmDialogInfo
{
Title = "Stunde löschen?",
Message = $"Die Stunde vom {lesson.DateDisplay} wird endgültig gelöscht.",
ConfirmText = "Löschen",
};
var dialog = new ConfirmDialog { DataContext = info };
var owner = TopLevel.GetTopLevel(this) as Window;
return owner is not null && await dialog.ShowDialog<bool>(owner);
}
private async Task<MoveLessonTarget?> ShowMoveLessonDialog(Lesson lesson)
{
var dialogVm = new MoveLessonDialogViewModel(lesson.Date);
var dialog = new MoveLessonDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var ok = await dialog.ShowDialog<bool>(owner);
return ok ? dialogVm.Result : null;
}
private async Task ShowLessonViewerDialog(Lesson lesson)
{
var viewerVm = new LessonViewerViewModel(lesson,
App.Services.GetRequiredService<IAlternativeLessonPathRepository>());
var dialog = new LessonViewerDialog { DataContext = viewerVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is not null) await dialog.ShowDialog(owner);
}
private async Task<LessonSeriesResult?> ShowGenerateLessonSeriesDialog(Unit unit)
{
var dialogVm = new GenerateLessonSeriesDialogViewModel(
App.Services.GetRequiredService<ITimetableSlotRepository>(),
App.Services.GetRequiredService<ILessonRepository>(),
App.Services.GetRequiredService<ISchoolHolidayRepository>(),
App.Services.GetRequiredService<PublicHolidayService>(),
App.Services.GetRequiredService<SchoolCalendarSettingsService>(),
unit.Id, unit.GroupId, unit.StartDate, unit.EndDate);
var dialog = new GenerateLessonSeriesDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var ok = await dialog.ShowDialog<bool>(owner);
if (ok && dialogVm.Result is { } result)
App.Services.GetRequiredService<NotificationService>().ShowSuccess(result.Summary);
return ok ? dialogVm.Result : null;
}
private async Task<bool> ShowAiAssistDialog(Unit unit)
{
var dialogVm = new AiAssistDialogViewModel(
App.Services.GetRequiredService<AiPlanningService>(),
App.Services.GetRequiredService<AiSettingsService>(),
App.Services.GetRequiredService<ILessonRepository>(),
unit);
var dialog = new AiAssistDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return false;
await dialog.ShowDialog<bool>(owner);
return dialogVm.Result;
}
}