feat: Anhänge je Stunde, Klausur-Sitzplan mischen, Gefährdungsbeurteilungs-Assistent
Lesson bekommt dieselbe Anhang-Infrastruktur wie Documentation (Material, Arbeitsblätter, Experimentunterlagen), samt Fix einer Sync-Lücke, die Anhang- Dateibytes bisher nur für Documentation statt generisch übertragen hat (IHasAttachments). Sitzplan-Tab bekommt einen "Plätze mischen"-Button für Klausursitzpläne. Neu: mehrschrittiger Gefährdungsbeurteilungs-Assistent mit optionalem KI-Entwurf (ai-backend/gbu.php) und PDF-Export, Format bewusst als JSON-Anhang statt eigener Datenbank-Entität. Details und Architekturentscheidungen in TODO.md (4.2, 7.1.5, 10.1.8). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.Services;
|
||||
using LehrerApp.Desktop.ViewModels.Students;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -655,9 +656,11 @@ public partial class LessonDialogViewModel : ObservableObject
|
||||
private readonly IAlternativeLessonPathRepository _alternativePaths;
|
||||
private readonly ITimetableSlotRepository _timetableSlots;
|
||||
private readonly PeriodScheduleService _periodSchedule;
|
||||
private readonly IAttachmentStorage _attachmentStorage;
|
||||
private readonly Guid _unitId;
|
||||
private readonly Guid _groupId;
|
||||
private readonly Lesson? _editingLesson;
|
||||
private readonly List<string> _newlyUploadedStorageIds = [];
|
||||
|
||||
[ObservableProperty] private string _dateText = DateOnly.FromDateTime(DateTime.Today).ToString("dd.MM.yyyy");
|
||||
[ObservableProperty] private int? _lessonNumber;
|
||||
@@ -684,6 +687,10 @@ public partial class LessonDialogViewModel : ObservableObject
|
||||
public string[] ShorthandSuggestions { get; }
|
||||
public ObservableCollection<PhaseStepEditItem> Phases { get; } = [];
|
||||
|
||||
// Anhänge (Material/Arbeitsblätter, Experiment-/Gefährdungsbeurteilungsdokumente).
|
||||
public ObservableCollection<AttachmentItem> Attachments { get; } = [];
|
||||
[ObservableProperty] private string _attachmentError = "";
|
||||
|
||||
/// Vom Code-Behind gesetzt (Fenster als Owner für den Zuweisen-Dialog): fragt nach dem
|
||||
/// alternativen Ablauf, dem eine Phase zugeordnet werden soll (Auswahl oder Neuanlage
|
||||
/// per Combobox-Dialog). null zurückgegeben = abgebrochen.
|
||||
@@ -713,11 +720,13 @@ public partial class LessonDialogViewModel : ObservableObject
|
||||
|
||||
public LessonDialogViewModel(ILessonRepository lessons, IShorthandCodeRepository shorthandCodes,
|
||||
IAlternativeLessonPathRepository alternativePaths, ITimetableSlotRepository timetableSlots,
|
||||
PeriodScheduleService periodSchedule, Guid unitId, Guid groupId, string groupName, string subjectName,
|
||||
PeriodScheduleService periodSchedule, IAttachmentStorage attachmentStorage,
|
||||
Guid unitId, Guid groupId, string groupName, string subjectName,
|
||||
List<string> materialSuggestions, List<string> shorthandHistorySuggestions, Lesson? editingLesson)
|
||||
{
|
||||
_lessons = lessons; _alternativePaths = alternativePaths;
|
||||
_timetableSlots = timetableSlots; _periodSchedule = periodSchedule;
|
||||
_attachmentStorage = attachmentStorage;
|
||||
_unitId = unitId; _groupId = groupId; _editingLesson = editingLesson;
|
||||
GroupSubjectDisplay = string.IsNullOrWhiteSpace(subjectName)
|
||||
? $"{groupName} · kein Fach hinterlegt (siehe Lerngruppe)" : $"{groupName} · {subjectName}";
|
||||
@@ -746,6 +755,8 @@ public partial class LessonDialogViewModel : ObservableObject
|
||||
Reflection = editingLesson.Reflection ?? "";
|
||||
StatusName = LessonStatusDisplay.ToName(editingLesson.Status);
|
||||
foreach (var p in editingLesson.Phases) AddPhaseInternal(p);
|
||||
foreach (var att in editingLesson.Attachments)
|
||||
Attachments.Add(new AttachmentItem(att.StorageId, att.FileName, att.SizeBytes, att.UploadedAt));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -925,6 +936,39 @@ public partial class LessonDialogViewModel : ObservableObject
|
||||
_ => "#B71C1C", // Dunkelrot: deutlich überplant
|
||||
};
|
||||
|
||||
// ── Anhänge ────────────────────────────────────────────────────────────
|
||||
|
||||
public void AddAttachment(string fileName, Stream content)
|
||||
{
|
||||
AttachmentError = "";
|
||||
if (content.Length > IAttachmentStorage.MaxSizeBytes)
|
||||
{
|
||||
AttachmentError = $"Datei zu groß (max. {IAttachmentStorage.MaxSizeBytes / 1024 / 1024} MB).";
|
||||
return;
|
||||
}
|
||||
var storageId = _attachmentStorage.Upload(fileName, content);
|
||||
_newlyUploadedStorageIds.Add(storageId);
|
||||
Attachments.Add(new AttachmentItem(storageId, fileName, content.Length, DateTime.UtcNow));
|
||||
}
|
||||
|
||||
public Stream? OpenAttachment(AttachmentItem item) => _attachmentStorage.OpenRead(item.StorageId);
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveAttachment(AttachmentItem? item)
|
||||
{
|
||||
if (item is null) return;
|
||||
_attachmentStorage.Delete(item.StorageId);
|
||||
_newlyUploadedStorageIds.Remove(item.StorageId);
|
||||
Attachments.Remove(item);
|
||||
}
|
||||
|
||||
/// Vom Code-Behind beim Abbrechen aufgerufen: neu hochgeladene, nie gespeicherte Anhänge
|
||||
/// wieder entfernen, damit keine verwaisten Blobs in der Datenbank zurückbleiben.
|
||||
public void DiscardUnsavedAttachments()
|
||||
{
|
||||
foreach (var id in _newlyUploadedStorageIds) _attachmentStorage.Delete(id);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Save()
|
||||
{
|
||||
@@ -960,7 +1004,12 @@ public partial class LessonDialogViewModel : ObservableObject
|
||||
Result.HomeworkCheckDismissed = HomeworkCheckDismissed;
|
||||
Result.Reflection = string.IsNullOrWhiteSpace(Reflection) ? null : Reflection.Trim();
|
||||
Result.Status = LessonStatusDisplay.FromName(StatusName);
|
||||
Result.Attachments = Attachments.Select(a => new DocumentAttachment
|
||||
{
|
||||
StorageId = a.StorageId, FileName = a.FileName, SizeBytes = a.SizeBytes, UploadedAt = a.UploadedAt,
|
||||
}).ToList();
|
||||
_lessons.Save(Result);
|
||||
_newlyUploadedStorageIds.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user