Export Option

Added export function
This commit is contained in:
2026-04-01 10:34:06 +02:00
parent cf3d7557aa
commit 142c318d33
14 changed files with 628 additions and 87 deletions
+91 -2
View File
@@ -48,6 +48,15 @@ public partial class OptionsViewModel : ObservableObject
[ObservableProperty]
private OptionsTab selectedTab = OptionsTab.Notifications;
[ObservableProperty]
private DateTime exportStartDate = DateTime.Today;
[ObservableProperty]
private DateTime exportEndDate = DateTime.Today;
[ObservableProperty]
private ExportLayout selectedExportLayout = ExportLayout.DaySummary;
public ObservableCollection<AppearanceColorItemViewModel> AppearanceColors { get; } = new();
public ObservableCollection<AppearanceTextItemViewModel> StatusTexts { get; } = new();
public ObservableCollection<ActivityManageItemViewModel> Activities { get; } = new();
@@ -57,8 +66,33 @@ public partial class OptionsViewModel : ObservableObject
public bool IsAppearanceTabSelected => SelectedTab == OptionsTab.Appearance;
public bool IsNotificationsTabSelected => SelectedTab == OptionsTab.Notifications;
public bool IsDataManagementTabSelected => SelectedTab == OptionsTab.DataManagement;
public bool IsExportTabSelected => SelectedTab == OptionsTab.Export;
public string NotificationVibrationButtonText => NotificationVibrationEnabled ? "Aktiv" : "Inaktiv";
public bool IsDayViewExportLayoutSelected => SelectedExportLayout == ExportLayout.DayView;
public bool IsWeekBlockExportLayoutSelected => SelectedExportLayout == ExportLayout.WeekBlock;
public bool IsDaySummaryExportLayoutSelected => SelectedExportLayout == ExportLayout.DaySummary;
public string ExportRangeSummary
{
get
{
var start = ExportStartDate.Date;
var end = ExportEndDate.Date;
var totalDays = (end - start).Days + 1;
return totalDays == 1
? $"1 Tag ausgewählt: {start:dd.MM.yyyy}"
: $"{totalDays} Tage ausgewählt: {start:dd.MM.yyyy} bis {end:dd.MM.yyyy}";
}
}
public string SelectedExportLayoutDescription => SelectedExportLayout switch
{
ExportLayout.DayView => "Tagesansicht: Jeder Tag wird mit allen einzelnen Einträgen, Tätigkeiten, Dauer und Symptomen exportiert.",
ExportLayout.WeekBlock => "Wochenblock: Der Zeitraum wird in Wochen gruppiert. Pro Tag siehst du Vormittag, Nachmittag und die wichtigsten Details.",
_ => "Tageszusammenfassung: Jeder Tag erscheint kompakt in einer Zeile, ähnlich wie bei Monats- und Jahresexporten."
};
public IAsyncRelayCommand DeleteAllDataCommand { get; }
public IAsyncRelayCommand SaveAppearanceCommand { get; }
@@ -76,10 +110,15 @@ public partial class OptionsViewModel : ObservableObject
public IAsyncRelayCommand<NotificationScheduleItemViewModel> DeleteScheduleCommand { get; }
public IAsyncRelayCommand SaveDatabaseLocationCommand { get; }
public IAsyncRelayCommand ClearExportsCommand { get; }
public IAsyncRelayCommand ExportSelectedRangeCommand { get; }
public IRelayCommand ToggleNotificationVibrationCommand { get; }
public IRelayCommand ShowAppearanceTabCommand { get; }
public IRelayCommand ShowNotificationsTabCommand { get; }
public IRelayCommand ShowDataManagementTabCommand { get; }
public IRelayCommand ShowExportTabCommand { get; }
public IRelayCommand SelectDayViewExportLayoutCommand { get; }
public IRelayCommand SelectWeekBlockExportLayoutCommand { get; }
public IRelayCommand SelectDaySummaryExportLayoutCommand { get; }
public OptionsViewModel(
HealthEntryRepository healthEntryRepository,
@@ -120,6 +159,7 @@ public partial class OptionsViewModel : ObservableObject
DeleteScheduleCommand = new AsyncRelayCommand<NotificationScheduleItemViewModel>(DeleteScheduleAsync);
SaveDatabaseLocationCommand = new AsyncRelayCommand(SaveDatabaseLocationAsync);
ClearExportsCommand = new AsyncRelayCommand(ClearExportsAsync);
ExportSelectedRangeCommand = new AsyncRelayCommand(ExportSelectedRangeAsync);
ToggleNotificationVibrationCommand = new RelayCommand(() =>
{
@@ -129,6 +169,11 @@ public partial class OptionsViewModel : ObservableObject
ShowAppearanceTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Appearance);
ShowNotificationsTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Notifications);
ShowDataManagementTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.DataManagement);
ShowExportTabCommand = new RelayCommand(() => SelectedTab = OptionsTab.Export);
SelectDayViewExportLayoutCommand = new RelayCommand(() => SelectedExportLayout = ExportLayout.DayView);
SelectWeekBlockExportLayoutCommand = new RelayCommand(() => SelectedExportLayout = ExportLayout.WeekBlock);
SelectDaySummaryExportLayoutCommand = new RelayCommand(() => SelectedExportLayout = ExportLayout.DaySummary);
}
partial void OnDeleteConfirmationTextChanged(string value)
@@ -141,6 +186,7 @@ public partial class OptionsViewModel : ObservableObject
OnPropertyChanged(nameof(IsAppearanceTabSelected));
OnPropertyChanged(nameof(IsNotificationsTabSelected));
OnPropertyChanged(nameof(IsDataManagementTabSelected));
OnPropertyChanged(nameof(IsExportTabSelected));
}
partial void OnNotificationVibrationEnabledChanged(bool value)
@@ -148,6 +194,30 @@ public partial class OptionsViewModel : ObservableObject
OnPropertyChanged(nameof(NotificationVibrationButtonText));
}
partial void OnExportStartDateChanged(DateTime value)
{
if (ExportEndDate.Date < value.Date)
ExportEndDate = value.Date;
OnPropertyChanged(nameof(ExportRangeSummary));
}
partial void OnExportEndDateChanged(DateTime value)
{
if (ExportStartDate.Date > value.Date)
ExportStartDate = value.Date;
OnPropertyChanged(nameof(ExportRangeSummary));
}
partial void OnSelectedExportLayoutChanged(ExportLayout value)
{
OnPropertyChanged(nameof(IsDayViewExportLayoutSelected));
OnPropertyChanged(nameof(IsWeekBlockExportLayoutSelected));
OnPropertyChanged(nameof(IsDaySummaryExportLayoutSelected));
OnPropertyChanged(nameof(SelectedExportLayoutDescription));
}
public async Task LoadAsync()
{
await LoadAppearanceAsync();
@@ -509,6 +579,24 @@ public partial class OptionsViewModel : ObservableObject
return Task.CompletedTask;
}
private async Task ExportSelectedRangeAsync()
{
try
{
var result = await _pdfExportService.ExportRangeAsync(
ExportStartDate.Date,
ExportEndDate.Date,
SelectedExportLayout);
StatusText = $"Export erstellt: {result.FileName}";
await ExportUiHelper.ShowExportSavedActionsAsync(result);
}
catch (Exception ex)
{
StatusText = ex.Message;
}
}
private async Task ClearExportsAsync()
{
var confirm = await Shell.Current.DisplayAlertAsync(
@@ -544,6 +632,7 @@ public partial class OptionsViewModel : ObservableObject
{
Appearance,
Notifications,
DataManagement
DataManagement,
Export
}
}
}