Add shared export infrastructure

This commit is contained in:
2026-08-18 21:21:56 +02:00
parent 41bf2c0756
commit 26461bd2f2
13 changed files with 336 additions and 63 deletions
@@ -1,7 +1,8 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels.Groups;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Groups;
@@ -15,15 +16,9 @@ public partial class ExamEvaluationDialog : Window
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null) return;
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Klausurauswertung exportieren",
SuggestedFileName = $"Auswertung_{vm.ExamTitle}.csv",
FileTypeChoices = [new FilePickerFileType("CSV-Dateien") { Patterns = ["*.csv"] }],
});
if (file is null) return;
await File.WriteAllTextAsync(file.Path.LocalPath, vm.ExportCsv());
var export = ExportFile.Csv("Klausurauswertung exportieren",
$"Auswertung_{vm.ExamTitle}.csv", vm.ExportCsv());
await App.Services.GetRequiredService<ExportService>().SaveAsync(topLevel.StorageProvider, export);
}
private void OnClose(object? sender, RoutedEventArgs e) => Close();
@@ -1,7 +1,8 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels.Groups;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Groups;
@@ -15,15 +16,9 @@ public partial class ReportGradeDialog : Window
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null) return;
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Zeugnisnoten exportieren",
SuggestedFileName = $"Zeugnisnoten_{vm.GroupLabel}.csv",
FileTypeChoices = [new FilePickerFileType("CSV-Dateien") { Patterns = ["*.csv"] }],
});
if (file is null) return;
await File.WriteAllTextAsync(file.Path.LocalPath, vm.ExportCsv());
var export = ExportFile.Csv("Zeugnisnoten exportieren",
$"Zeugnisnoten_{vm.GroupLabel}.csv", vm.ExportCsv());
await App.Services.GetRequiredService<ExportService>().SaveAsync(topLevel.StorageProvider, export);
}
private void OnClose(object? sender, RoutedEventArgs e) => Close();
@@ -7,12 +7,14 @@
<StackPanel Margin="20,16" Spacing="16">
<!-- Zeitraum -->
<Grid ColumnDefinitions="Auto,Auto,Auto" HorizontalAlignment="Left">
<Grid ColumnDefinitions="Auto,Auto,Auto,Auto" HorizontalAlignment="Left">
<ComboBox Grid.Column="0" ItemsSource="{Binding PeriodModeOptions}"
SelectedItem="{Binding PeriodMode}" Margin="0,0,8,0"/>
<ComboBox Grid.Column="1" ItemsSource="{Binding MonthOptions}" SelectedItem="{Binding SelectedMonth}"
Margin="0,0,8,0" IsVisible="{Binding IsMonthMode}"/>
<ComboBox Grid.Column="2" ItemsSource="{Binding YearOptions}" SelectedItem="{Binding SelectedYear}"/>
<Button Grid.Column="3" Content="Als CSV exportieren" Margin="16,0,0,0"
Click="OnExportClick"/>
</Grid>
<!-- Pflichtstunden (6.3.2) -->
@@ -1,8 +1,23 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels.Workload;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Workload;
public partial class WorkloadEvaluationView : UserControl
{
public WorkloadEvaluationView() => InitializeComponent();
private async void OnExportClick(object? sender, RoutedEventArgs e)
{
if (DataContext is not WorkloadEvaluationViewModel vm) return;
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null) return;
var export = ExportFile.Csv("Arbeitszeitauswertung exportieren",
vm.ExportSuggestedFileName, vm.ExportCsv());
await App.Services.GetRequiredService<ExportService>().SaveAsync(topLevel.StorageProvider, export);
}
}