Bisher musste man aus dem Stunden-Editor raus, die KI-Hilfe für die ganze Einheit aufrufen und die gewünschte Stunde in der freien Anweisung erst benennen. Neuer Button "KI-Unterstützung für diese Stunde" im LessonDialog öffnet denselben AiAssistDialog im neuen Fokus-Modus. AiPlanningRequest.FocusLessonId weist die KI im Systemprompt an, sich auf genau diese Stunde zu beschränken; zusätzlich wie beim Umfangs-Umschalter client-seitig hart durchgesetzt in Send() und ApplyResponse, statt der KI-Antwort blind zu vertrauen. Da "Übernehmen" direkt ins Repository speichert, wären die noch offenen Feldwerte des ursprünglichen LessonDialog danach veraltet gewesen - der Dialog schließt sich deshalb nach einer angewendeten KI-Änderung automatisch mit dem frischen Stand statt ihn mit alten Werten zu überschreiben. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
73 lines
2.9 KiB
C#
73 lines
2.9 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using LehrerApp.Core.Interfaces;
|
|
using LehrerApp.Core.Models;
|
|
using LehrerApp.Desktop.Services;
|
|
using LehrerApp.Desktop.ViewModels.Groups;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace LehrerApp.Desktop.Views.Groups;
|
|
|
|
public partial class LessonDialog : Window
|
|
{
|
|
public LessonDialog() => InitializeComponent();
|
|
|
|
protected override void OnDataContextChanged(EventArgs e)
|
|
{
|
|
base.OnDataContextChanged(e);
|
|
if (DataContext is LessonDialogViewModel vm)
|
|
vm.OnPickAlternativePath = ShowAlternativePathDialog;
|
|
}
|
|
|
|
private async Task<AlternativeLessonPath?> ShowAlternativePathDialog(Guid? currentId)
|
|
{
|
|
var dialogVm = new AlternativePathDialogViewModel(
|
|
App.Services.GetRequiredService<IAlternativeLessonPathRepository>(), currentId);
|
|
var dialog = new AlternativePathDialog { DataContext = dialogVm };
|
|
|
|
var ok = await dialog.ShowDialog<bool>(this);
|
|
return ok ? dialogVm.Result : null;
|
|
}
|
|
|
|
private void OnSave(object? s, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is LessonDialogViewModel vm && vm.SaveCommand.CanExecute(null))
|
|
{
|
|
vm.SaveCommand.Execute(null);
|
|
if (vm.Result is not null) Close(true);
|
|
}
|
|
}
|
|
|
|
private void OnCancel(object? s, RoutedEventArgs e) => Close(false);
|
|
|
|
/// KI-Unterstützung mit Fokus auf genau diese (bereits gespeicherte) Stunde, statt den Umweg
|
|
/// über die Einheiten-Übersicht nehmen zu müssen (4.5.22, Nutzer-Feedback). Die Übernahme im
|
|
/// AiAssistDialog speichert direkt ins Repository — dieser Dialog schließt sich danach mit dem
|
|
/// frisch geladenen Stand, statt seine eigenen (jetzt veralteten) Feldwerte zu speichern.
|
|
private async void OnAiAssist(object? s, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is not LessonDialogViewModel vm || vm.EditingLesson is null) return;
|
|
|
|
var unitRepo = App.Services.GetRequiredService<IUnitRepository>();
|
|
var unit = unitRepo.GetById(vm.UnitId);
|
|
if (unit is null) return;
|
|
|
|
var lessonRepo = App.Services.GetRequiredService<ILessonRepository>();
|
|
var currentLesson = lessonRepo.GetByUnit(vm.UnitId).FirstOrDefault(l => l.Id == vm.EditingLesson.Id);
|
|
if (currentLesson is null) return;
|
|
|
|
var dialogVm = new AiAssistDialogViewModel(
|
|
App.Services.GetRequiredService<AiPlanningService>(),
|
|
App.Services.GetRequiredService<AiSettingsService>(),
|
|
lessonRepo, unit, focusLesson: currentLesson);
|
|
|
|
var dialog = new AiAssistDialog { DataContext = dialogVm };
|
|
var ok = await dialog.ShowDialog<bool>(this);
|
|
if (!ok) return;
|
|
|
|
var updated = lessonRepo.GetByUnit(vm.UnitId).FirstOrDefault(l => l.Id == vm.EditingLesson.Id);
|
|
if (updated is not null) vm.MarkAppliedExternally(updated);
|
|
Close(true);
|
|
}
|
|
}
|