Files
LehrerApp/LehrerApp.Desktop/Views/Groups/GroupDocumentationTabView.axaml.cs

70 lines
2.8 KiB
C#

using Avalonia.Controls;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Desktop.ViewModels.Groups;
using LehrerApp.Desktop.ViewModels.Students;
using LehrerApp.Desktop.Views.Shared;
using LehrerApp.Desktop.Views.Students;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Groups;
public partial class GroupDocumentationTabView : UserControl
{
public GroupDocumentationTabView() => InitializeComponent();
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is not GroupDocumentationTabViewModel vm) return;
vm.OnEditDocumentation = ShowDocumentationDialog;
vm.OnConfirmDeleteDocumentation = ShowDeleteDocumentationDialog;
vm.OnConductParentCall = ShowParentCallSessionDialog;
}
private async Task<Documentation?> ShowDocumentationDialog(
Guid groupId, List<StudentOption> studentOptions, Documentation? editing)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var options = new List<StudentOption> { GroupDocumentationTabViewModel.WholeGroupOption };
options.AddRange(studentOptions);
var vm = new DocumentationDialogViewModel(editing?.StudentId ?? Guid.Empty, editing,
App.Services.GetRequiredService<IAttachmentStorage>(), options, groupId);
if (editing is null)
{
vm.SelectedStudent = GroupDocumentationTabViewModel.WholeGroupOption;
vm.TypeName = DocumentationTypeDisplay.Label(DocumentationType.Planning);
}
var dialog = new DocumentationDialog { DataContext = vm };
var saved = await dialog.ShowDialog<bool>(owner);
if (!saved) vm.DiscardUnsavedAttachments();
return saved ? vm.Result : null;
}
private async Task<Documentation?> ShowParentCallSessionDialog(Documentation documentation, string studentTitle)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var vm = new ParentCallSessionViewModel(documentation, studentTitle);
var dialog = new ParentCallSessionDialog { DataContext = vm };
var saved = await dialog.ShowDialog<bool>(owner);
return saved ? vm.Result : null;
}
private async Task<bool> ShowDeleteDocumentationDialog(DocumentationItem item)
{
var info = new ConfirmDialogInfo
{
Title = "Eintrag löschen?",
Message = $"\"{item.Model.Title}\" ({item.StudentName}) wird als gelöscht markiert und nicht mehr angezeigt.",
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);
}
}