Settings geht noch nicht ganz
This commit is contained in:
@@ -37,11 +37,6 @@ class Auth {
|
||||
/// <summary>
|
||||
/// Stundeneintrag speichern
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="isNewItem"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
|
||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ internal class Stunde : ObservableObject {
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
//Default-Werte zum Testen
|
||||
public static string apiKey = Preferences.Default.Get("apiKey", "");
|
||||
public static int EmployeeId = Preferences.Default.Get("employeeId", 0);
|
||||
public static string name = Preferences.Default.Get("name", "");
|
||||
@@ -21,8 +20,6 @@ internal class Stunde : ObservableObject {
|
||||
|
||||
public static async Task<Hours> LoadData() {
|
||||
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
@@ -31,9 +28,6 @@ internal class Stunde : ObservableObject {
|
||||
|
||||
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);
|
||||
|
||||
@@ -56,20 +50,51 @@ internal class Stunde : ObservableObject {
|
||||
return hours;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Einstellungen
|
||||
/// </summary>
|
||||
public static async Task<Settings> LoadSettings()
|
||||
{
|
||||
|
||||
Settings settings;
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None)
|
||||
{
|
||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?settings", tokendata.apiKey);
|
||||
|
||||
if (data == "null")
|
||||
{
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
if (data == "\"Lalala\"")
|
||||
{
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
if (data == null)
|
||||
{
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
settings = JsonConvert.DeserializeObject<Settings>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basisdaten: Mitarbeiterdaten, Projekte, Gemeinden, Freistellungen.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static async Task<Hours> LoadBasicData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
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);
|
||||
|
||||
@@ -94,9 +119,6 @@ internal class Stunde : ObservableObject {
|
||||
/// <summary>
|
||||
/// Zeiten eines Tages holen
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static async Task<ObservableCollection<DayTime>> LoadDay(DateTime date) {
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
@@ -104,9 +126,6 @@ internal class Stunde : ObservableObject {
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
@@ -134,8 +153,6 @@ internal class Stunde : ObservableObject {
|
||||
/// <summary>
|
||||
/// Einzelnen Stundeneintrag holen
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<DayTime> LoadEntry(int id) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
@@ -171,8 +188,6 @@ internal class Stunde : ObservableObject {
|
||||
/// <summary>
|
||||
/// Eintrag speichern
|
||||
/// </summary>
|
||||
/// <param name="stunde"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
@@ -187,14 +202,9 @@ internal class Stunde : ObservableObject {
|
||||
/// <summary>
|
||||
/// Eintrag löschen
|
||||
/// </summary>
|
||||
/// <param name="stunde"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<DayTime> DeleteEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
public static async Task DeleteEntry(DayTime stunde) {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
await Auth.DeleteItemAsync(tokendata.url + "/entry/" + stunde.id, tokendata.apiKey);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace Jugenddienst_Stunden.Types;
|
||||
/// <summary>
|
||||
/// Represents a day time entry for an employee.
|
||||
/// </summary>
|
||||
public class DayTime {
|
||||
public class DayTime
|
||||
{
|
||||
/// <summary>
|
||||
/// ID des Stundeneintrages
|
||||
/// </summary>
|
||||
@@ -103,4 +104,7 @@ public class DayTime {
|
||||
/// Gets the active Freistellung based on the Freistellung ID
|
||||
/// </summary>
|
||||
public Freistellung FreistellungAktiv { get; set; }
|
||||
|
||||
public bool ProjektAktivSet { get; set; } = false;
|
||||
public bool GemeindeAktivSet { get; set; } = false;
|
||||
}
|
||||
|
||||
15
Jugenddienst Stunden/Types/Settings.cs
Normal file
15
Jugenddienst Stunden/Types/Settings.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Einstellungen
|
||||
/// </summary>
|
||||
public class Settings
|
||||
{
|
||||
public bool ProjektAktivSet { get; set; }
|
||||
public bool GemeindeAktivSet { get; set; }
|
||||
public Collection<Projekt> Projekte { get; set; }
|
||||
public Collection<Gemeinde> Gemeinden { get; set; }
|
||||
public Collection<Freistellung> Freistellungen { get; set; }
|
||||
}
|
||||
@@ -6,15 +6,38 @@ using System.Windows.Input;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
internal class StundeViewModel : ObservableObject, IQueryAttributable
|
||||
{
|
||||
|
||||
public int id { get; set; }
|
||||
|
||||
public string SubTitle { get; set; } = DateTime.Today.ToString("dddd, d. MMMM yyyy");
|
||||
|
||||
private Settings _settings;
|
||||
public Settings Settings
|
||||
{
|
||||
get => _settings; set
|
||||
{
|
||||
if (_settings != value)
|
||||
{
|
||||
_settings = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DayTime _stunde;
|
||||
public DayTime Stunde { get => _stunde; }
|
||||
public DayTime Stunde
|
||||
{
|
||||
get => _stunde;
|
||||
set
|
||||
{
|
||||
if (_stunde != value)
|
||||
{
|
||||
_stunde = value;
|
||||
OnPropertyChanged(nameof(Stunde));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Title { get; set; } = "Eintrag bearbeiten";
|
||||
|
||||
@@ -29,10 +52,13 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
public ObservableCollection<DayTime> DayTimes { get; set; }
|
||||
|
||||
//private Gemeinde _selectedGemeinde;
|
||||
public Gemeinde SelectedOptionGemeinde {
|
||||
public Gemeinde SelectedOptionGemeinde
|
||||
{
|
||||
get => _stunde.GemeindeAktiv;
|
||||
set {
|
||||
if (_stunde.GemeindeAktiv != value) {
|
||||
set
|
||||
{
|
||||
if (_stunde.GemeindeAktiv != value)
|
||||
{
|
||||
//_selectedGemeinde = value;
|
||||
_stunde.GemeindeAktiv = value;
|
||||
OnPropertyChanged(nameof(SelectedOptionGemeinde));
|
||||
@@ -41,10 +67,13 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
}
|
||||
|
||||
//private Projekt _selectedProjekt;
|
||||
public Projekt SelectedOptionProjekt {
|
||||
public Projekt SelectedOptionProjekt
|
||||
{
|
||||
get => _stunde.ProjektAktiv;
|
||||
set {
|
||||
if (_stunde.ProjektAktiv != value) {
|
||||
set
|
||||
{
|
||||
if (_stunde.ProjektAktiv != value)
|
||||
{
|
||||
//_selectedProjekt = value;
|
||||
_stunde.ProjektAktiv = value;
|
||||
OnPropertyChanged(nameof(SelectedOptionProjekt));
|
||||
@@ -53,10 +82,13 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
}
|
||||
|
||||
//private Freistellung _selectedFreistellung;
|
||||
public Freistellung SelectedOptionFreistellung {
|
||||
public Freistellung SelectedOptionFreistellung
|
||||
{
|
||||
get => _stunde.FreistellungAktiv;
|
||||
set {
|
||||
if (_stunde.FreistellungAktiv != value) {
|
||||
set
|
||||
{
|
||||
if (_stunde.FreistellungAktiv != value)
|
||||
{
|
||||
_stunde.FreistellungAktiv = value;
|
||||
OnPropertyChanged(nameof(SelectedOptionFreistellung));
|
||||
}
|
||||
@@ -72,7 +104,8 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
//public ICommand LoadDataCommand { get; private set; }
|
||||
|
||||
|
||||
public StundeViewModel() {
|
||||
public StundeViewModel()
|
||||
{
|
||||
_stunde = new DayTime();
|
||||
|
||||
SaveCommand = new AsyncRelayCommand(Save);
|
||||
@@ -81,15 +114,18 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
|
||||
}
|
||||
|
||||
public StundeViewModel(DayTime stunde) {
|
||||
public StundeViewModel(DayTime stunde)
|
||||
{
|
||||
_stunde = stunde;
|
||||
|
||||
SaveCommand = new AsyncRelayCommand(Save);
|
||||
DeleteConfirmCommand = new AsyncRelayCommand(DeleteConfirm);
|
||||
}
|
||||
|
||||
private async Task LoadData() {
|
||||
try {
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
Hours _hours = await Models.Stunde.LoadBasicData();
|
||||
OptionsProjekt = new ObservableCollection<Projekt>(_hours.Projekte);
|
||||
OptionsGemeinde = new ObservableCollection<Gemeinde>(_hours.Gemeinden);
|
||||
@@ -98,91 +134,121 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
OnPropertyChanged(nameof(OptionsProjekt));
|
||||
OnPropertyChanged(nameof(OptionsFreistellung));
|
||||
_stunde.EmployeeId = _hours.EmployeeId;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
async Task Save() {
|
||||
async Task Save()
|
||||
{
|
||||
bool exceptionOccurred = false;
|
||||
try {
|
||||
try
|
||||
{
|
||||
await Models.Stunde.SaveEntry(_stunde);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
exceptionOccurred = true;
|
||||
}
|
||||
if (!exceptionOccurred) {
|
||||
if (_stunde.id != null) {
|
||||
if (!exceptionOccurred)
|
||||
{
|
||||
if (_stunde.id != null)
|
||||
{
|
||||
await Shell.Current.GoToAsync($"..?saved={_stunde.id}");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Delete() {
|
||||
private async Task Delete()
|
||||
{
|
||||
await Models.Stunde.DeleteEntry(_stunde);
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
}
|
||||
|
||||
private async Task DeleteConfirm() {
|
||||
if (ConfirmEvent != null) {
|
||||
private async Task DeleteConfirm()
|
||||
{
|
||||
if (ConfirmEvent != null)
|
||||
{
|
||||
bool answer = await ConfirmEvent.Invoke("Achtung", "Löschen kann nicht ungeschehen gemacht werden. Fortfahren?");
|
||||
if (answer) {
|
||||
if (answer)
|
||||
{
|
||||
//Löschen
|
||||
await Models.Stunde.DeleteEntry(_stunde);
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
} else { //nicht Löschen
|
||||
}
|
||||
else
|
||||
{ //nicht Löschen
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private async Task LoadSettings()
|
||||
{
|
||||
Settings = await Models.Stunde.LoadSettings();
|
||||
}
|
||||
|
||||
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||
/// <summary>
|
||||
/// Anwenden der Query-Parameter
|
||||
/// </summary>
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
|
||||
{
|
||||
await LoadSettings();
|
||||
var probe = query;
|
||||
if (query.ContainsKey("load")) {
|
||||
if (query.ContainsKey("load"))
|
||||
{
|
||||
|
||||
//DateTime heute = DateTime.Now;
|
||||
_stunde = await Models.Stunde.LoadEntry(Convert.ToInt32(query["load"]));
|
||||
if (System.String.IsNullOrEmpty(_stunde.description)) {
|
||||
Stunde = await Models.Stunde.LoadEntry(Convert.ToInt32(query["load"]));
|
||||
if (System.String.IsNullOrEmpty(Stunde.description))
|
||||
{
|
||||
AlertEvent?.Invoke(this, "Eintrag hat keine Daten zurückgegeben");
|
||||
}
|
||||
SubTitle = _stunde.day.ToString("dddd, d. MMMM yyyy");
|
||||
SubTitle = Stunde.day.ToString("dddd, d. MMMM yyyy");
|
||||
|
||||
OptionsProjekt = new ObservableCollection<Projekt>(_stunde.Projekte);
|
||||
OptionsGemeinde = new ObservableCollection<Gemeinde>(_stunde.Gemeinden);
|
||||
OptionsFreistellung = new ObservableCollection<Freistellung>(_stunde.Freistellungen);
|
||||
OptionsProjekt = new ObservableCollection<Projekt>(Stunde.Projekte);
|
||||
OptionsGemeinde = new ObservableCollection<Gemeinde>(Stunde.Gemeinden);
|
||||
OptionsFreistellung = new ObservableCollection<Freistellung>(Stunde.Freistellungen);
|
||||
OnPropertyChanged(nameof(OptionsGemeinde));
|
||||
OnPropertyChanged(nameof(OptionsProjekt));
|
||||
OnPropertyChanged(nameof(OptionsFreistellung));
|
||||
|
||||
//OptionsProjekt.FirstOrDefault(x => x.Id == _stunde.projekt);
|
||||
|
||||
SelectedOptionGemeinde = OptionsGemeinde.FirstOrDefault(item => item.Id == _stunde.gemeinde) ?? new Gemeinde();
|
||||
SelectedOptionGemeinde = OptionsGemeinde.FirstOrDefault(item => item.Id == Stunde.gemeinde) ?? new Gemeinde();
|
||||
OnPropertyChanged(nameof(SelectedOptionGemeinde));
|
||||
|
||||
SelectedOptionProjekt = OptionsProjekt.FirstOrDefault(Projekt => Projekt.Id == _stunde.projekt) ?? new Projekt();
|
||||
SelectedOptionProjekt = OptionsProjekt.FirstOrDefault(Projekt => Projekt.Id == Stunde.projekt) ?? new Projekt();
|
||||
OnPropertyChanged(nameof(SelectedOptionProjekt));
|
||||
|
||||
SelectedOptionFreistellung = OptionsFreistellung.FirstOrDefault(Freistellung => Freistellung.Id == _stunde.free) ?? new Freistellung();
|
||||
SelectedOptionFreistellung = OptionsFreistellung.FirstOrDefault(Freistellung => Freistellung.Id == Stunde.free) ?? new Freistellung();
|
||||
OnPropertyChanged(nameof(SelectedOptionFreistellung));
|
||||
|
||||
OnPropertyChanged(nameof(Stunde));
|
||||
|
||||
OnPropertyChanged(nameof(SubTitle));
|
||||
|
||||
}
|
||||
if (query.ContainsKey("date")) {
|
||||
if (query.ContainsKey("date"))
|
||||
{
|
||||
Title = "Neuer Eintrag";
|
||||
|
||||
DateTime _date = DateTime.ParseExact((string)query["date"], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
//Bei neuem Eintrag die vorhandenen des gleichen Tages anzeigen
|
||||
try {
|
||||
try
|
||||
{
|
||||
DayTimes = await Models.Stunde.LoadDay(_date);
|
||||
} catch (Exception) {
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Ein Tag ohne Einträge gibt eine Fehlermeldung,
|
||||
//die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ using Newtonsoft.Json.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged {
|
||||
internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged
|
||||
{
|
||||
public string Name => AppInfo.Name;
|
||||
public string Surname => AppInfo.VersionString;
|
||||
public string MoreInfoUrl => "https://aka.ms/maui";
|
||||
@@ -28,11 +30,16 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
public event EventHandler<string> AlertEvent;
|
||||
public event EventHandler<string> InfoEvent;
|
||||
|
||||
private Settings Settings { get; set; }
|
||||
|
||||
private bool isRefreshing;
|
||||
public bool IsRefreshing {
|
||||
public bool IsRefreshing
|
||||
{
|
||||
get => isRefreshing;
|
||||
set {
|
||||
if (isRefreshing != value) {
|
||||
set
|
||||
{
|
||||
if (isRefreshing != value)
|
||||
{
|
||||
isRefreshing = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
@@ -40,13 +47,15 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
}
|
||||
|
||||
private string _title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
||||
public string Title {
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
private Hours _hour;
|
||||
public Hours Hours {
|
||||
public Hours Hours
|
||||
{
|
||||
get => _hour;
|
||||
}
|
||||
|
||||
@@ -59,7 +68,8 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// Liste der Tageszeiten
|
||||
/// </summary>
|
||||
private ObservableCollection<DayTime> _dayTimes = new ObservableCollection<DayTime>();
|
||||
public ObservableCollection<DayTime> DayTimes {
|
||||
public ObservableCollection<DayTime> DayTimes
|
||||
{
|
||||
get => _dayTimes;
|
||||
set => SetProperty(ref _dayTimes, value);
|
||||
}
|
||||
@@ -67,14 +77,16 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <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);
|
||||
}
|
||||
|
||||
@@ -82,10 +94,13 @@ 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();
|
||||
@@ -98,35 +113,40 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Geleistete Stunden
|
||||
/// </summary>
|
||||
public string? ZeitCalculated {
|
||||
public string? ZeitCalculated
|
||||
{
|
||||
get => _hour.zeit_total;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Sollstunden
|
||||
/// </summary>
|
||||
public string? Nominal {
|
||||
public string? Nominal
|
||||
{
|
||||
get => _hour.nominal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Differenz zwischen Soll und geleisteten Stunden
|
||||
/// </summary>
|
||||
public string? Overtime {
|
||||
public string? Overtime
|
||||
{
|
||||
get => _hour.overtime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Restüberstunden insgesamt
|
||||
/// </summary>
|
||||
public string OvertimeMonth {
|
||||
public string OvertimeMonth
|
||||
{
|
||||
get => _hour.overtime_month;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monatsübersicht: Resturlaub
|
||||
/// </summary>
|
||||
public string Holiday {
|
||||
public string Holiday
|
||||
{
|
||||
get => _hour.holiday;
|
||||
}
|
||||
|
||||
@@ -139,19 +159,20 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// <summary>
|
||||
/// CTOR
|
||||
/// </summary>
|
||||
public StundenViewModel() {
|
||||
public StundenViewModel()
|
||||
{
|
||||
|
||||
_hour = new Types.Hours();
|
||||
LoadDataCommand = new AsyncRelayCommand(LoadData);
|
||||
|
||||
LoadDataCommand = new AsyncRelayCommand(LoadData);
|
||||
NewEntryCommand = new AsyncRelayCommand(NewEntryAsync);
|
||||
SelectEntryCommand = new AsyncRelayCommand<DayTime>(SelectEntryAsync);
|
||||
|
||||
RefreshListCommand = new AsyncRelayCommand(RefreshList);
|
||||
RefreshCommand = new Command(async () => await RefreshItemsAsync());
|
||||
|
||||
Task task = LoadDay(DateTime.Today);
|
||||
|
||||
RefreshCommand = new Command(async () => await RefreshItemsAsync());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -160,7 +181,8 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// Ö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}");
|
||||
@@ -171,15 +193,19 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// </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");
|
||||
}
|
||||
else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
|
||||
}
|
||||
|
||||
private async Task RefreshList() {
|
||||
private async Task RefreshList()
|
||||
{
|
||||
OnPropertyChanged(nameof(DayTimes));
|
||||
}
|
||||
|
||||
@@ -187,11 +213,16 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// Lädt die Monatssummen für die Übersicht
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task LoadData() {
|
||||
try {
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
_hour = await Models.Stunde.LoadData();
|
||||
RefreshProperties();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
}
|
||||
}
|
||||
@@ -201,42 +232,58 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
public async Task LoadDay(DateTime date) {
|
||||
public async Task LoadDay(DateTime date)
|
||||
{
|
||||
DayTotal = new TimeOnly(0);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
await LoadSettings();
|
||||
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 ...)
|
||||
//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) {
|
||||
foreach (DayTime dt in DayTimes)
|
||||
{
|
||||
span += dt.end - dt.begin;
|
||||
}
|
||||
DayTotal = TimeOnly.FromTimeSpan(span);
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
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 {
|
||||
}
|
||||
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
|
||||
@@ -249,7 +296,8 @@ 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));
|
||||
@@ -261,10 +309,14 @@ 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}");
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
<Frame Padding="5,2,5,10">
|
||||
<Grid ColumnDefinitions="*,*,*">
|
||||
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}" SelectedItem="{Binding SelectedOptionGemeinde, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="0" >
|
||||
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}" SelectedItem="{Binding SelectedOptionGemeinde, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="0" IsVisible="{Binding Settings.GemeindeAktivSet}">
|
||||
</Picker>
|
||||
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding SelectedOptionProjekt, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="1" >
|
||||
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding SelectedOptionProjekt, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="1" IsVisible="{Binding Settings.ProjektAktivSet}">
|
||||
</Picker>
|
||||
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding SelectedOptionFreistellung, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="2" >
|
||||
</Picker>
|
||||
|
||||
@@ -77,8 +77,8 @@
|
||||
<Label Grid.Column="0" Text="{Binding begin}" />
|
||||
<Label Text="bis" Padding="5,0,5,0" />
|
||||
<Label Text="{Binding end}" />
|
||||
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" />
|
||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" />
|
||||
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding GemeindeAktivSet}" />
|
||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding ProjektAktivSet}" />
|
||||
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user