Files
LehrerApp/LehrerApp.Desktop/Views/Planning/TimetableView.axaml.cs
T
2026-08-24 21:52:00 +02:00

100 lines
3.9 KiB
C#

using Avalonia.Controls;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Core.Services;
using LehrerApp.Desktop.ViewModels.Planning;
using LehrerApp.Desktop.ViewModels.Groups;
using LehrerApp.Desktop.Views.Groups;
using LehrerApp.Desktop.Services;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Planning;
public partial class TimetableView : UserControl
{
public TimetableView() => InitializeComponent();
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is TimetableViewModel vm)
{
vm.OnEditSlot = ShowSlotDialog;
vm.OnAddSubstitution = ShowSubstitutionDialog;
vm.OnImportWebUntisTimetable = ShowWebUntisTimetableDialog;
vm.OnOpenLessonViewer = ShowLessonViewerDialog;
vm.OnOpenTeachingMode = ShowTeachingMode;
}
}
private async Task ShowWebUntisTimetableDialog()
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return;
var vm = new WebUntisTimetableImportViewModel(
App.Services.GetRequiredService<WebUntisIntegrationService>(),
App.Services.GetRequiredService<WebUntisSettingsService>(),
App.Services.GetRequiredService<ITimetableSlotRepository>(),
App.Services.GetRequiredService<IGroupRepository>());
var dialog = new WebUntisTimetableImportDialog { DataContext = vm };
vm.OnCreateGroup = dialog.CreateGroupAsync;
await vm.InitializeAsync();
await dialog.ShowDialog<bool>(owner);
}
private async Task ShowTeachingMode(Lesson lesson)
{
var owner = TopLevel.GetTopLevel(this) as Window;
var group = App.Services.GetRequiredService<IGroupRepository>().GetById(lesson.GroupId);
if (owner is null || group is null) return;
var teachingModeVm = new TeachingModeViewModel(lesson, group,
App.Services.GetRequiredService<IAlternativeLessonPathRepository>(),
App.Services.GetRequiredService<SeatingPlanTabViewModel>());
var window = new TeachingModeWindow { DataContext = teachingModeVm };
await window.ShowDialog(owner);
}
private async Task ShowLessonViewerDialog(Lesson lesson)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return;
var viewerVm = new LessonViewerViewModel(lesson,
App.Services.GetRequiredService<IAlternativeLessonPathRepository>());
var dialog = new LessonViewerDialog { DataContext = viewerVm };
await dialog.ShowDialog(owner);
}
private async Task ShowSlotDialog(TimetableCellItem cell)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null || cell.Weekday is null) return;
var vm = new TimetableSlotDialogViewModel(
App.Services.GetRequiredService<ITimetableSlotRepository>(),
App.Services.GetRequiredService<IGroupRepository>(),
App.Services.GetRequiredService<ISubjectRepository>(),
App.Services.GetRequiredService<SchoolYearService>(),
cell.Weekday.Value, cell.PeriodNumber, cell.Slot);
var dialog = new TimetableSlotDialog { DataContext = vm };
await dialog.ShowDialog(owner);
}
private async Task ShowSubstitutionDialog()
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return;
var vm = new SubstitutionEntryDialogViewModel(
App.Services.GetRequiredService<ISubstitutionEntryRepository>(),
App.Services.GetRequiredService<IGroupRepository>(),
App.Services.GetRequiredService<IUnitRepository>(),
App.Services.GetRequiredService<ILessonRepository>());
var dialog = new SubstitutionEntryDialog { DataContext = vm };
await dialog.ShowDialog(owner);
}
}