This commit is contained in:
2024-10-13 20:26:09 +02:00
parent d7d7db8dd4
commit bc1a2367c0
8 changed files with 164 additions and 132 deletions

View File

@@ -87,6 +87,8 @@
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
@@ -97,6 +99,7 @@
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-windows10.0.19041.0|AnyCPU'">

View File

@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using Jugenddienst_Stunden.Types;
using System.Collections.ObjectModel;
namespace Jugenddienst_Stunden.Models;
@@ -31,7 +32,7 @@ internal class Stunde : ObservableObject {
name = Preferences.Default.Get("name", "Johannes");
surname = Preferences.Default.Get("surname", "Fink");
apiUrl = Preferences.Default.Get("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
if (string.IsNullOrEmpty(apiKey)) {
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
@@ -107,39 +108,38 @@ internal class Stunde : ObservableObject {
/// <param name="date"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static async Task<List<DayTime>> LoadDay(DateTime date) {
public static async Task<ObservableCollection<DayTime>> LoadDay(DateTime date) {
if (string.IsNullOrEmpty(apiKey)) {
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
}
List<DayTime> daytimes = new List<DayTime>();
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
//await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
// "Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
// "OK");
} else {
var tokendata = new TokenData(apiKey);
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
if (data == "null") {
throw new Exception("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
}
if (data == "\"Lalala\"") {
throw new Exception("Problem mit Token");
}
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
//daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data);
daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
}
//Hours = hours;
var tokendata = new TokenData(apiKey);
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
if (data == "null") {
throw new Exception("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
}
if (data == "\"Lalala\"") {
throw new Exception("Problem mit Token");
}
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
ObservableCollection<DayTime> daytimes = System.Text.Json.JsonSerializer.Deserialize<ObservableCollection<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
//daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
//List<DayTime> daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
return daytimes;
}
/// <summary>

View File

@@ -7,38 +7,38 @@ namespace Jugenddienst_Stunden.Types;
/// </summary>
public class DayTime {
public int? id { get; set; }
public int? EmployeeId { get; set; }
public int EmployeeId { get; set; }
public DateTime day { get; set; }
public int? wday { get; set; }
public int wday { get; set; }
public TimeOnly begin { get; set; }
public TimeOnly end { get; set; }
public string? description { get; set; }
public string description { get; set; }
public string? free { get; set; }
public bool? approved { get; set; }
public int? type { get; set; }
public int? projekt { get; set; }
public int? gemeinde { get; set; }
public TimeOnly? night { get; set; }
public Dictionary<string, TimeOnly>? total { get; set; }
public TimeOnly? end_print { get; set; }
public TimeSpan? TimeSpanVon { get; set; }
public TimeSpan? TimeSpanBis { get; set; }
public Collection<Projekt>? Projekte { get; set; }
public Collection<Gemeinde>? Gemeinden { get; set; }
public Collection<Freistellung>? Freistellungen { get; set; }
public TimeOnly night { get; set; }
public Dictionary<string, TimeOnly> total { get; set; }
public TimeOnly end_print { get; set; }
public TimeSpan TimeSpanVon { get; set; }
public TimeSpan TimeSpanBis { get; set; }
public Collection<Projekt> Projekte { get; set; }
public Collection<Gemeinde> Gemeinden { get; set; }
public Collection<Freistellung> Freistellungen { get; set; }
/// <summary>
/// Gets the active Gemeinde based on the gemeinde ID.
/// </summary>
public Gemeinde? GemeindeAktiv { get; set; }
public Gemeinde GemeindeAktiv { get; set; }
/// <summary>
/// Gets the active Projekt based on the projekt ID.
/// </summary>
public Projekt? ProjektAktiv { get; set; }
public Projekt ProjektAktiv { get; set; }
/// <summary>
/// Gets the active Freistellung based on the Freistellung ID
/// </summary>
public Freistellung? FreistellungAktiv { get; set; }
public Freistellung FreistellungAktiv { get; set; }
}

View File

@@ -20,7 +20,7 @@ public class Hours : ObservableObject {
//public Dictionary<int,decimal> zeit_total_daily;
public List<TimeDay> zeit_total_daily_api;
public List<DayTime> daytime;
public List<DayTime>? daytime;
//public List<string> wochensumme;
public string overtime_month;
public string overtime;

View File

@@ -26,6 +26,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
public ObservableCollection<Gemeinde> OptionsGemeinde { get; private set; }
public ObservableCollection<Projekt> OptionsProjekt { get; private set; }
public ObservableCollection<Freistellung> OptionsFreistellung { get; private set; }
public ObservableCollection<DayTime> DayTimes { get; set; }
//private Gemeinde _selectedGemeinde;
public Gemeinde SelectedOptionGemeinde {
@@ -62,7 +63,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
}
}
public List<DayTime> DayTimes { get; set; }
public ICommand SaveCommand { get; private set; }
@@ -78,7 +79,6 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
//DeleteCommand = new AsyncRelayCommand(Delete);
DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
}
public StundeViewModel(DayTime stunde) {

View File

@@ -1,89 +1,72 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Networking;
using ZXing.Net.Maui;
using Jugenddienst_Stunden.Types;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Jugenddienst_Stunden.Types;
using System.Globalization;
using System;
using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace Jugenddienst_Stunden.ViewModels;
internal class StundenViewModel : ObservableObject, IQueryAttributable {
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";
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 string ShowDay => "Zeit an Tag " + GetDay.ToString("ddd d. MMM") + ": ";
public int id { get; set; }
public ICommand NewEntryCommand { get; }
public ICommand SelectEntryCommand { get; }
public ICommand LoadDataCommand { get; private set; }
public event EventHandler<string> AlertEvent;
public event EventHandler<string> InfoEvent;
public object Stunden { get; }
private List<DayTime> _stunde;
public List<DayTime> Stunde {
get => _stunde;
private string _title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
public string Title {
get => _title;
set => SetProperty(ref _title, value);
}
private Hours _hour;
public Hours Hours {
get => _hour;
}
public string ZeitDone {
get => _hour.zeit;
}
public string ZeitCalculated {
get => _hour.zeit_total;
}
public string Nominal {
get => _hour.nominal;
}
public string Overtime {
get => _hour.overtime;
}
public string OvertimeMonth {
get => _hour.overtime_month;
}
public string Holiday {
get => _hour.holiday;
}
/// <summary>
/// Gesamtstunden an einem Tag
/// </summary>
public TimeOnly DayTotal { get; set; }
public List<DayTime> DayTimes {
get => _hour.daytime;
set {
if (_hour.daytime != value) {
_hour.daytime = value;
OnPropertyChanged();
}
}
/// <summary>
/// Liste der Tageszeiten
/// </summary>
private ObservableCollection<DayTime> _dayTimes = new ObservableCollection<DayTime>();
public ObservableCollection<DayTime> DayTimes {
get => _dayTimes;
set => SetProperty(ref _dayTimes, value);
}
public DateTime MinimumDate {
//get => _hour.MinDate;
//get => DateTime.Today.AddDays(-21);
/// <summary>
/// Mindest-Datum für den Datepicker
/// </summary>
public static DateTime MinimumDate {
get => DateTime.Today.AddDays(-365);
}
public DateTime MaximumDate {
//get => _hour.MaxDate;
/// <summary>
/// Höchst-Datum für den Datepicker
/// </summary>
public static DateTime MaximumDate {
get => DateTime.Today.AddDays(60);
}
/// <summary>
/// Heutiges Datum, wenn das Datum geändert wird, wird auch der Tag geladen
/// </summary>
private DateTime dateToday = DateTime.Today;
public DateTime DateToday {
get => dateToday;
@@ -91,62 +74,96 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable {
if (dateToday != value) {
dateToday = value;
GetDay = value;
OnPropertyChanged();
_ = LoadDay(value); // Use discard operator to explicitly ignore the returned Task
//RefreshProperties();
OnPropertyChanged(nameof(TimeDay));
OnPropertyChanged(nameof(ShowDay));
OnPropertyChanged(nameof(DayTimes));
//OnPropertyChanged();
_ = LoadDay(value);
}
}
}
public DateTime Date {
get => _hour.Date;
/// <summary>
/// Monatsübersicht: Geleistete Stunden
/// </summary>
public string? ZeitCalculated {
get => _hour.zeit_total;
}
public List<TimeDay> ZeitTotalDaily {
get => _hour.zeit_total_daily_api;
/// <summary>
/// Monatsübersicht: Sollstunden
/// </summary>
public string? Nominal {
get => _hour.nominal;
}
public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
/// <summary>
/// Monatsübersicht: Differenz zwischen Soll und geleisteten Stunden
/// </summary>
public string? Overtime {
get => _hour.overtime;
}
/// <summary>
/// Monatsübersicht: Restüberstunden insgesamt
/// </summary>
public string OvertimeMonth {
get => _hour.overtime_month;
}
/// <summary>
/// Monatsübersicht: Resturlaub
/// </summary>
public string Holiday {
get => _hour.holiday;
}
public List<TimeDay> TimeDay { get; set; }
public static string apiKey = Preferences.Default.Get("apiKey", "");
/// <summary>
/// CTOR
/// </summary>
public StundenViewModel() {
_hour = new Types.Hours();
LoadDataCommand = new AsyncRelayCommand(LoadData);
NewEntryCommand = new AsyncRelayCommand(NewEntryAsync);
SelectEntryCommand = new AsyncRelayCommand<DayTime>(SelectEntryAsync);
_ = LoadDay(DateTime.Today);
OnPropertyChanged(nameof(DayTimes));
Task task = LoadDay(DateTime.Today);
}
/// <summary>
/// Öffnet eine neue Stundeneingabe
/// </summary>
/// <returns></returns>
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.ToString("yyyy-MM-dd")}");
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?date={dateToday:yyyy-MM-dd}");
}
/// <summary>
/// Öffnet eine bestehende Stundeneingabe
/// </summary>
/// <param name="entry"></param>
/// <returns></returns>
private async Task SelectEntryAsync(DayTime entry) {
if (entry != null && entry.id != null) {
var navigationParameters = new Dictionary<string, object> {{ "load", entry.id }};
var navigationParameters = new Dictionary<string, object> { { "load", entry.id } };
//await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?load={entry.id}");
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}", navigationParameters);
} else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
}
/// <summary>
/// Lädt die Monatssummen für die Übersicht
/// </summary>
/// <returns></returns>
private async Task LoadData() {
try {
_hour = await Models.Stunde.LoadData();
@@ -156,54 +173,67 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable {
}
}
/// <summary>
/// Lädt die Arbeitszeiten für einen Tag
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public async Task LoadDay(DateTime date) {
try {
_hour.daytime = await Models.Stunde.LoadDay(date);
////if (_hour.zeit_total_daily_api != null) {
////TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay.Day).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay.Day, Hours = 0 } };
//RefreshProperties();
DayTotal = new TimeOnly(0);
try {
DayTimes = await Models.Stunde.LoadDay(date);
//TODO: Hier muss noch die Berechnung der Stunden erfolgen
//Hier werden im Moment noch nur die eingetragenen Stunden gezählt
//Auf der Website bekommt der Benutzer die berechneten Stunden angezeigt (Nachstunden außerhalb des Stundenplanes zählen mehr ...)
TimeSpan span = TimeSpan.Zero;
foreach (DayTime dt in _hour.daytime) {
foreach (DayTime dt in DayTimes) {
span += dt.end - dt.begin;
}
DayTotal = TimeOnly.FromTimeSpan(span);
OnPropertyChanged(nameof(ShowDay));
OnPropertyChanged(nameof(TimeDay));
} catch (Exception e) {
DayTimes = new ObservableCollection<DayTime>();
//TODO: hier könnte auch ein Fehler kommen, dann wäre InfoEvent falsch.
InfoEvent?.Invoke(this, e.Message);
} finally {
OnPropertyChanged(nameof(DayTotal));
OnPropertyChanged(nameof(DayTimes));
////}
} catch (Exception e) {
DayTimes = new List<DayTime>();
DayTotal = new TimeOnly(0);
OnPropertyChanged(nameof(DayTotal));
InfoEvent?.Invoke(this, e.Message);
}
}
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
if (query.ContainsKey("date")) {
await LoadDay(Convert.ToDateTime(query["date"]));
}
}
/// <summary>
/// Refreshes all properties
/// </summary>
private void RefreshProperties() {
OnPropertyChanged(nameof(Nominal));
OnPropertyChanged(nameof(Overtime));
OnPropertyChanged(nameof(OvertimeMonth));
OnPropertyChanged(nameof(ZeitCalculated));
OnPropertyChanged(nameof(ZeitDone));
OnPropertyChanged(nameof(Holiday));
OnPropertyChanged(nameof(Hours));
OnPropertyChanged(nameof(Title));
OnPropertyChanged(nameof(ZeitTotalDaily));
OnPropertyChanged(nameof(TimeDay));
OnPropertyChanged(nameof(MinimumDate));
OnPropertyChanged(nameof(MaximumDate));
OnPropertyChanged(nameof(ShowDay));
//OnPropertyChanged(nameof(DateToday));
}
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
try {
base.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
} catch (Exception ex) {
AlertEvent?.Invoke(this, ex.Message);
//Console.WriteLine($"Fehler bei OnPropertyChanged: {ex.Message}");
}
}

View File

@@ -46,10 +46,7 @@
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="5,10,5,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
@@ -84,7 +81,6 @@
</HorizontalStackLayout>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>

View File

@@ -2,6 +2,9 @@ using Jugenddienst_Stunden.ViewModels;
namespace Jugenddienst_Stunden.Views;
/// <summary>
/// Code-Behind f<>r die Stunden-<2D>bersicht
/// </summary>
public partial class StundenPage : ContentPage {
/// <summary>