Settings so halb und a bissi aufgeräumt ...
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Jugenddienst_Stunden.Models;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -10,15 +11,12 @@ using System.Windows.Input;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged
|
||||
{
|
||||
public string Name => AppInfo.Name;
|
||||
public string Surname => AppInfo.VersionString;
|
||||
public string MoreInfoUrl => "https://aka.ms/maui";
|
||||
public string Message => "Hier werden deine geleisteten Arbeitsstunden aufgelistet";
|
||||
/// <summary>
|
||||
/// Stundenliste
|
||||
/// </summary>
|
||||
internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged {
|
||||
|
||||
public string LoadOverview => "Lade Summen für " + DateTime.Today.ToString("MMMM");
|
||||
//public static DateTime GetDay = DateTime.Today;
|
||||
//public string ShowDay => "Zeit an Tag " + GetDay.ToString("ddd d. MMM") + ": ";
|
||||
|
||||
public ICommand NewEntryCommand { get; }
|
||||
public ICommand SelectEntryCommand { get; }
|
||||
@@ -30,32 +28,19 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
public event EventHandler<string> AlertEvent;
|
||||
public event EventHandler<string> InfoEvent;
|
||||
|
||||
private Settings Settings { get; set; }
|
||||
private HoursBase HoursBase = new HoursBase();
|
||||
internal Settings Settings = new Settings();
|
||||
|
||||
private bool isRefreshing;
|
||||
public bool IsRefreshing
|
||||
{
|
||||
get => isRefreshing;
|
||||
set
|
||||
{
|
||||
if (isRefreshing != value)
|
||||
{
|
||||
isRefreshing = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
||||
public string Title
|
||||
{
|
||||
|
||||
private string _title = HoursBase.name + " " + HoursBase.surname;
|
||||
public string Title {
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
private Hours _hour;
|
||||
public Hours Hours
|
||||
{
|
||||
public Hours Hours {
|
||||
get => _hour;
|
||||
}
|
||||
|
||||
@@ -67,26 +52,26 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <summary>
|
||||
/// Liste der Tageszeiten
|
||||
/// </summary>
|
||||
private ObservableCollection<DayTime> _dayTimes = new ObservableCollection<DayTime>();
|
||||
public ObservableCollection<DayTime> DayTimes
|
||||
{
|
||||
private List<DayTime> _dayTimes = new List<DayTime>();
|
||||
public List<DayTime> DayTimes {
|
||||
get => _dayTimes;
|
||||
set => SetProperty(ref _dayTimes, value);
|
||||
set {
|
||||
SetProperty(ref _dayTimes, value);
|
||||
OnPropertyChanged(nameof(DayTimes));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mindest-Datum für den Datepicker
|
||||
/// </summary>
|
||||
public DateTime MinimumDate
|
||||
{
|
||||
public DateTime MinimumDate {
|
||||
get => DateTime.Today.AddDays(-365);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Höchst-Datum für den Datepicker
|
||||
/// </summary>
|
||||
public DateTime MaximumDate
|
||||
{
|
||||
public DateTime MaximumDate {
|
||||
get => DateTime.Today.AddDays(60);
|
||||
}
|
||||
|
||||
@@ -94,13 +79,10 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// Heutiges Datum, wenn das Datum geändert wird, wird auch der Tag geladen
|
||||
/// </summary>
|
||||
private DateTime dateToday = DateTime.Today;
|
||||
public DateTime DateToday
|
||||
{
|
||||
public DateTime DateToday {
|
||||
get => dateToday;
|
||||
set
|
||||
{
|
||||
if (dateToday != value)
|
||||
{
|
||||
set {
|
||||
if (dateToday != value) {
|
||||
dateToday = value;
|
||||
//GetDay = value;
|
||||
//OnPropertyChanged();
|
||||
@@ -113,56 +95,69 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Geleistete Stunden
|
||||
/// </summary>
|
||||
public string? ZeitCalculated
|
||||
{
|
||||
get => _hour.zeit_total;
|
||||
public string? ZeitCalculated {
|
||||
get => Hours.Zeit_total;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Sollstunden
|
||||
/// </summary>
|
||||
public string? Nominal
|
||||
{
|
||||
get => _hour.nominal;
|
||||
public string? Nominal {
|
||||
get => Hours.Nominal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Differenz zwischen Soll und geleisteten Stunden
|
||||
/// </summary>
|
||||
public string? Overtime
|
||||
{
|
||||
get => _hour.overtime;
|
||||
public string? Overtime {
|
||||
get => Hours.overtime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Restüberstunden insgesamt
|
||||
/// </summary>
|
||||
public string OvertimeMonth
|
||||
{
|
||||
get => _hour.overtime_month;
|
||||
public string OvertimeMonth {
|
||||
get => Hours.overtime_month;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Resturlaub
|
||||
/// </summary>
|
||||
public string Holiday
|
||||
{
|
||||
get => _hour.holiday;
|
||||
public string Holiday {
|
||||
get => Hours.holiday;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seite neu laden
|
||||
/// </summary>
|
||||
private bool isRefreshing;
|
||||
public bool IsRefreshing {
|
||||
get => isRefreshing;
|
||||
set {
|
||||
if (isRefreshing != value) {
|
||||
isRefreshing = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dürfen Gemeinden verwendet werden?
|
||||
/// </summary>
|
||||
public bool GemeindeAktivSet { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dürfen Projekte verwendet werden?
|
||||
/// </summary>
|
||||
public bool ProjektAktivSet { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// CTOR
|
||||
/// </summary>
|
||||
public StundenViewModel()
|
||||
{
|
||||
|
||||
_hour = new Types.Hours();
|
||||
public StundenViewModel() {
|
||||
_hour = new Hours();
|
||||
|
||||
LoadDataCommand = new AsyncRelayCommand(LoadData);
|
||||
NewEntryCommand = new AsyncRelayCommand(NewEntryAsync);
|
||||
@@ -171,18 +166,24 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
RefreshCommand = new Command(async () => await RefreshItemsAsync());
|
||||
|
||||
Task task = LoadDay(DateTime.Today);
|
||||
|
||||
|
||||
|
||||
LoadSettingsAsync();
|
||||
}
|
||||
|
||||
private async void LoadSettingsAsync() {
|
||||
Settings = await HoursBase.LoadSettings();
|
||||
|
||||
GemeindeAktivSet = Settings.GemeindeAktivSet;
|
||||
ProjektAktivSet = Settings.ProjektAktivSet;
|
||||
|
||||
OnPropertyChanged(nameof(GemeindeAktivSet));
|
||||
OnPropertyChanged(nameof(ProjektAktivSet));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Öffnet eine neue Stundeneingabe
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task NewEntryAsync()
|
||||
{
|
||||
private async Task NewEntryAsync() {
|
||||
//Hier muss das Datum übergeben werden
|
||||
//await Shell.Current.GoToAsync(nameof(Views.StundePage));
|
||||
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?date={dateToday:yyyy-MM-dd}");
|
||||
@@ -191,99 +192,72 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <summary>
|
||||
/// Öffnet eine bestehende Stundeneingabe
|
||||
/// </summary>
|
||||
/// <param name="entry"></param>
|
||||
/// <returns></returns>
|
||||
private async Task SelectEntryAsync(DayTime entry)
|
||||
{
|
||||
if (entry != null && entry.id != null)
|
||||
{
|
||||
private async Task SelectEntryAsync(DayTime entry) {
|
||||
if (entry != null && entry.Id != null) {
|
||||
//var navigationParameters = new Dictionary<string, object> { { "load", entry.id } };
|
||||
//await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}", navigationParameters);
|
||||
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?load={entry.id}");
|
||||
}
|
||||
else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
|
||||
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?load={entry.Id}");
|
||||
} else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
|
||||
}
|
||||
|
||||
private async Task RefreshList()
|
||||
{
|
||||
private async Task RefreshList() {
|
||||
OnPropertyChanged(nameof(DayTimes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lädt die Monatssummen für die Übersicht
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
_hour = await Models.Stunde.LoadData();
|
||||
private async Task LoadData() {
|
||||
try {
|
||||
_hour = await HoursBase.LoadData();
|
||||
RefreshProperties();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Lädt die Arbeitszeiten für einen Tag
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
public async Task LoadDay(DateTime date)
|
||||
{
|
||||
public async Task LoadDay(DateTime date) {
|
||||
DayTotal = new TimeOnly(0);
|
||||
|
||||
try
|
||||
{
|
||||
await LoadSettings();
|
||||
DayTimes = await Models.Stunde.LoadDay(date);
|
||||
LoadSettingsAsync();
|
||||
try {
|
||||
DayTimes = await HoursBase.LoadDay(date);
|
||||
|
||||
//TODO: Hier muss noch die Berechnung der Stunden erfolgen
|
||||
//Es werden im Moment nur die eingetragenen Stunden gezählt
|
||||
//Auf der Website bekommt der Benutzer hingegen die berechneten Stunden angezeigt (Nachstunden außerhalb des Stundenplanes zählen mehr ...)
|
||||
|
||||
TimeSpan span = TimeSpan.Zero;
|
||||
foreach (DayTime dt in DayTimes)
|
||||
{
|
||||
span += dt.end - dt.begin;
|
||||
foreach (DayTime dt in DayTimes) {
|
||||
span += dt.End - dt.Begin;
|
||||
}
|
||||
DayTotal = TimeOnly.FromTimeSpan(span);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DayTimes = new ObservableCollection<DayTime>();
|
||||
} catch (Exception e) {
|
||||
DayTimes = new List<DayTime>();
|
||||
//TODO: hier könnte auch ein Fehler kommen, dann wäre InfoEvent falsch.
|
||||
InfoEvent?.Invoke(this, e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
OnPropertyChanged(nameof(DayTotal));
|
||||
//OnPropertyChanged(nameof(DayTimes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task LoadSettings()
|
||||
{
|
||||
Settings = await Models.Stunde.LoadSettings();
|
||||
}
|
||||
|
||||
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
|
||||
{
|
||||
if (query.ContainsKey("date"))
|
||||
{
|
||||
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||
if (query.ContainsKey("date")) {
|
||||
await LoadDay(Convert.ToDateTime(query["date"]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task RefreshItemsAsync()
|
||||
{
|
||||
private async Task RefreshItemsAsync() {
|
||||
IsRefreshing = true;
|
||||
|
||||
// Fügen Sie hier die Logik zum Aktualisieren der Daten hinzu
|
||||
@@ -296,8 +270,7 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <summary>
|
||||
/// Refreshes all properties
|
||||
/// </summary>
|
||||
private void RefreshProperties()
|
||||
{
|
||||
private void RefreshProperties() {
|
||||
OnPropertyChanged(nameof(Nominal));
|
||||
OnPropertyChanged(nameof(Overtime));
|
||||
OnPropertyChanged(nameof(OvertimeMonth));
|
||||
@@ -309,14 +282,10 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
OnPropertyChanged(nameof(MaximumDate));
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
|
||||
try {
|
||||
base.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
AlertEvent?.Invoke(this, ex.Message);
|
||||
//Console.WriteLine($"Fehler bei OnPropertyChanged: {ex.Message}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user