Settings so halb und a bissi aufgeräumt ...
This commit is contained in:
@@ -17,17 +17,17 @@ public static class MauiProgram {
|
||||
})
|
||||
.UseBarcodeReader();
|
||||
|
||||
//Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cHM6Ly9zdHVuZGVuLmpkLWxhbmEtdGlzZW5zLml0L2FwcGFwaQ==");
|
||||
//Preferences.Default.Set("name", "Default: Lea");
|
||||
#if DEBUG
|
||||
//Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
||||
//Preferences.Default.Set("name", "Testserver: Lea");
|
||||
//Preferences.Default.Set("surname", "Mair");
|
||||
//Preferences.Default.Set("EmployeeId", 3);
|
||||
//Preferences.Default.Set("apiUrl", "https://stunden.jd-lana-tisens.it/appapi");
|
||||
//Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
||||
|
||||
#if DEBUG
|
||||
Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
||||
Preferences.Default.Set("name", "Testserver: Lea");
|
||||
Preferences.Default.Set("surname", "Mair");
|
||||
Preferences.Default.Set("EmployeeId", 3);
|
||||
Preferences.Default.Set("apiKey", "MTQxfHNkdFptQkNZTXlPT3ZyMHNBZDl0UnVxNExMRXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
Preferences.Default.Set("name", "Testserver: Isabell");
|
||||
Preferences.Default.Set("surname", "Biasi");
|
||||
Preferences.Default.Set("EmployeeId", 141);
|
||||
Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
||||
|
||||
builder.Logging.AddDebug();
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
class Auth {
|
||||
public static async Task<string?> GetApiDataWithAuthAsync(string url, string token) {
|
||||
// Erstellen eines HttpClient-Objekts
|
||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
// Hinzufügen des Bearer-Tokens zum Authorization-Header
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
|
||||
// Senden der Anfrage und Abrufen der Antwort
|
||||
using (HttpResponseMessage HttpResponseMessage = await client.GetAsync(url).ConfigureAwait(false)) {
|
||||
// Überprüfen, ob die Anfrage erfolgreich war
|
||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
||||
// Lesen und Rückgabe der Antwort als String
|
||||
string responseData = await HttpContent.ReadAsStringAsync();
|
||||
return responseData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stundeneintrag speichern
|
||||
/// </summary>
|
||||
public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
|
||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
//Uhrzeiten sollten sinnvolle Werte haben
|
||||
if (item.TimeSpanVon == item.TimeSpanBis) {
|
||||
throw new Exception("Beginn und Ende sind gleich");
|
||||
}
|
||||
|
||||
if (item.TimeSpanBis < item.TimeSpanVon) {
|
||||
throw new Exception("Ende ist vor Beginn");
|
||||
}
|
||||
|
||||
TimeSpan span = TimeSpan.Zero;
|
||||
span += item.TimeSpanBis - item.TimeSpanVon;
|
||||
if (span.Hours > 10) {
|
||||
//Hier vielleicht eine Abfrage, ob mehr als 10 Stunden gesund sind?
|
||||
}
|
||||
|
||||
//Gemeinde ist ein Pflichtfeld
|
||||
if (item.GemeindeAktiv == null) {
|
||||
throw new Exception("Gemeinde nicht gewählt");
|
||||
}
|
||||
//Projekt ist ein Pflichtfeld
|
||||
if (item.ProjektAktiv == null) {
|
||||
throw new Exception("Projekt nicht gewählt");
|
||||
}
|
||||
//Keine Beschreibung
|
||||
if (string.IsNullOrEmpty(item.description)) {
|
||||
throw new Exception("Keine Beschreibung");
|
||||
}
|
||||
//try {
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
string json = JsonSerializer.Serialize<DayTime>(item);
|
||||
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage? response = null;
|
||||
if (isNewItem)
|
||||
response = await client.PostAsync(url, content);
|
||||
else
|
||||
response = await client.PutAsync(url, content);
|
||||
|
||||
//if (response.IsSuccessStatusCode)
|
||||
// Debug.WriteLine(@"\tTodoItem successfully saved.");
|
||||
if (!response.IsSuccessStatusCode) {
|
||||
throw new Exception("Fehler beim Speichern " + response.Content);
|
||||
}
|
||||
//} catch (Exception ex) {
|
||||
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
public static async Task DeleteItemAsync(string url, string token) {
|
||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
//try {
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
HttpResponseMessage response = await client.DeleteAsync(url);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception("Fehler beim Löschen " + response.Content);
|
||||
//if (response.IsSuccessStatusCode)
|
||||
// Debug.WriteLine(@"\tTodoItem successfully deleted.");
|
||||
//} catch (Exception ex) {
|
||||
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
public static async Task<User> AuthUserPass(string user, string pass, string url) {
|
||||
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "user", user },
|
||||
{ "pass", pass }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(values);
|
||||
|
||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
// Senden der Anfrage und Abrufen der Antwort
|
||||
using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) {
|
||||
// Überprüfen, ob die Anfrage erfolgreich war
|
||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
||||
// Lesen und Rückgabe der Antwort als String
|
||||
|
||||
string responseData = await HttpContent.ReadAsStringAsync();
|
||||
User userData = System.Text.Json.JsonSerializer.Deserialize<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return userData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
180
Jugenddienst Stunden/Models/BaseFunc.cs
Normal file
180
Jugenddienst Stunden/Models/BaseFunc.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
internal static class BaseFunc {
|
||||
|
||||
|
||||
internal static async Task<string> GetApiDataWithAuthAsync(string url, string token) {
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None)
|
||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
||||
|
||||
if (string.IsNullOrEmpty(token))
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
|
||||
// Erstellen eines HttpClient-Objekts
|
||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
// Hinzufügen des Bearer-Tokens zum Authorization-Header
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
// Senden der Anfrage und Abrufen der Antwort
|
||||
using (HttpResponseMessage HttpResponseMessage = await client.GetAsync(url).ConfigureAwait(false)) {
|
||||
var byteArray = await HttpResponseMessage.Content.ReadAsByteArrayAsync();
|
||||
string responseData = Encoding.UTF8.GetString(byteArray);
|
||||
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
||||
//responseData = await HttpContent.ReadAsStringAsync();
|
||||
}
|
||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||
return responseData;
|
||||
} else {
|
||||
var options = new JsonDocumentOptions {
|
||||
AllowTrailingCommas = true
|
||||
};
|
||||
using (JsonDocument doc = JsonDocument.Parse(responseData, options)) {
|
||||
JsonElement root = doc.RootElement;
|
||||
string message = root.GetProperty("message").GetString() ?? throw new Exception("Fehler: 'message' ist null.");
|
||||
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal static async Task<User> AuthUserPass(string user, string pass, string url) {
|
||||
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "user", user },
|
||||
{ "pass", pass }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(values);
|
||||
|
||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
// Senden der Anfrage und Abrufen der Antwort
|
||||
using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) {
|
||||
if (!HttpResponseMessage.IsSuccessStatusCode)
|
||||
throw new Exception("Fehler beim Einloggen " + HttpResponseMessage.Content);
|
||||
|
||||
// Überprüfen, ob die Anfrage erfolgreich war
|
||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
||||
// Lesen und Rückgabe der Antwort als String
|
||||
|
||||
string responseData = await HttpContent.ReadAsStringAsync();
|
||||
User userData = System.Text.Json.JsonSerializer.Deserialize<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return userData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
internal static HoursBase Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||
|
||||
return
|
||||
new() {
|
||||
//Filename = Path.GetFileName(filename),
|
||||
//Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stundeneintrag speichern
|
||||
/// </summary>
|
||||
internal static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
|
||||
|
||||
|
||||
//Uhrzeiten sollten sinnvolle Werte haben
|
||||
if (item.TimeSpanVon == item.TimeSpanBis) {
|
||||
throw new Exception("Beginn und Ende sind gleich");
|
||||
}
|
||||
|
||||
if (item.TimeSpanBis < item.TimeSpanVon) {
|
||||
throw new Exception("Ende ist vor Beginn");
|
||||
}
|
||||
|
||||
TimeSpan span = TimeSpan.Zero;
|
||||
span += item.TimeSpanBis - item.TimeSpanVon;
|
||||
if (span.Hours > 10) {
|
||||
//Hier vielleicht eine Abfrage, ob mehr als 10 Stunden gesund sind?
|
||||
//Das müsste aber das ViewModel machen
|
||||
}
|
||||
|
||||
//Gemeinde ist ein Pflichtfeld
|
||||
if (item.GemeindeAktiv == null) {
|
||||
throw new Exception("Gemeinde nicht gewählt");
|
||||
}
|
||||
//Projekt ist ein Pflichtfeld
|
||||
if (item.ProjektAktiv == null) {
|
||||
throw new Exception("Projekt nicht gewählt");
|
||||
}
|
||||
//Keine Beschreibung
|
||||
if (string.IsNullOrEmpty(item.Description)) {
|
||||
throw new Exception("Keine Beschreibung");
|
||||
}
|
||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
//HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
//string json = JsonSerializer.Serialize<DayTime>(item);
|
||||
string json = JsonConvert.SerializeObject(item);
|
||||
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage? response = null;
|
||||
if (isNewItem)
|
||||
response = await client.PostAsync(url, content);
|
||||
else
|
||||
response = await client.PutAsync(url, content);
|
||||
|
||||
if (!response.IsSuccessStatusCode) {
|
||||
throw new Exception("Fehler beim Speichern " + response.Content);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static async Task DeleteItemAsync(string url, string token) {
|
||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
//HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
HttpResponseMessage response = await client.DeleteAsync(url);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception("Fehler beim Löschen " + response.Content);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
125
Jugenddienst Stunden/Models/HoursBase.cs
Normal file
125
Jugenddienst Stunden/Models/HoursBase.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
internal class HoursBase {
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
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", "");
|
||||
public static string surname = Preferences.Default.Get("surname", "");
|
||||
public static string apiUrl = Preferences.Default.Get("apiUrl", "");
|
||||
|
||||
internal static TokenData tokendata = new TokenData(apiKey);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Einstellungen
|
||||
/// </summary>
|
||||
internal async Task<Settings> LoadSettings() {
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?settings", tokendata.ApiKey);
|
||||
|
||||
Settings _settings = JsonConvert.DeserializeObject<Settings>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
return _settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Daten laden
|
||||
/// </summary>
|
||||
internal async Task<Hours> LoadData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?hours", tokendata.ApiKey);
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basisdaten: Mitarbeiterdaten, Projekte, Gemeinden, Freistellungen.
|
||||
/// </summary>
|
||||
internal static async Task<Hours> LoadBasicData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?basic", tokendata.ApiKey);
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
public static async Task<Operator> LoadOperator(string apiKey) {
|
||||
|
||||
Operator OperatorVar = new Operator();
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url, tokendata.ApiKey);
|
||||
|
||||
OperatorVar = JsonConvert.DeserializeObject<Operator>(data);
|
||||
Preferences.Default.Set("name", OperatorVar.name);
|
||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||
Preferences.Default.Set("apiUrl", tokendata.Url);
|
||||
|
||||
return OperatorVar;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Zeiten eines Tages holen
|
||||
/// </summary>
|
||||
internal async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.ApiKey);
|
||||
|
||||
//List<DayTime> daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
List<DayTime> 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>
|
||||
/// Einzelnen Stundeneintrag holen
|
||||
/// </summary>
|
||||
internal static async Task<DayTime> LoadEntry(int id) {
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?id=" + id, tokendata.ApiKey);
|
||||
|
||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
hours.TimeSpanVon = hours.Begin.ToTimeSpan();
|
||||
hours.TimeSpanBis = hours.End.ToTimeSpan();
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eintrag speichern
|
||||
/// </summary>
|
||||
internal static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
bool isNew = false;
|
||||
if (stunde.Id == null)
|
||||
isNew = true;
|
||||
await BaseFunc.SaveItemAsync(tokendata.Url, tokendata.ApiKey, stunde, isNew);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eintrag löschen
|
||||
/// </summary>
|
||||
internal static async Task DeleteEntry(DayTime stunde) {
|
||||
await BaseFunc.DeleteItemAsync(tokendata.Url + "/entry/" + stunde.Id, tokendata.ApiKey);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
internal class Note {
|
||||
public string Filename { get; set; }
|
||||
public string Text { get; set; }
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Jugenddienst_Stunden.ViewModels;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
public class Operator : ObservableObject {
|
||||
internal class Operator : HoursBase {
|
||||
public string? id;
|
||||
public string? name;
|
||||
public string? surname;
|
||||
@@ -22,31 +19,5 @@ public class Operator : ObservableObject {
|
||||
|
||||
public event EventHandler<string>? AlertEvent;
|
||||
|
||||
public static async Task<Operator> LoadData(string apiKey) {
|
||||
|
||||
Operator OperatorVar = new Operator();
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
//throw new Exception("Keine Internetverbindung");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
//try {
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
if (data != "null") {
|
||||
OperatorVar = JsonConvert.DeserializeObject<Operator>(data);
|
||||
Preferences.Default.Set("name", OperatorVar.name);
|
||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||
Preferences.Default.Set("apiUrl", tokendata.url);
|
||||
}
|
||||
|
||||
}
|
||||
return OperatorVar;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System.Collections.ObjectModel;
|
||||
using Jugenddienst_Stunden.Exceptions;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
internal class Stunde : ObservableObject {
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
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", "");
|
||||
public static string surname = Preferences.Default.Get("surname", "");
|
||||
public static string apiUrl = Preferences.Default.Get("apiUrl", "");
|
||||
|
||||
|
||||
|
||||
public static async Task<Hours> LoadData() {
|
||||
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
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(requestUrl, apiKey);
|
||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", 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");
|
||||
}
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
}
|
||||
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>
|
||||
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.");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?basic", 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");
|
||||
}
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Zeiten eines Tages holen
|
||||
/// </summary>
|
||||
public static async Task<ObservableCollection<DayTime>> LoadDay(DateTime date) {
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
||||
}
|
||||
|
||||
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 NoDataException("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
if (data == null) {
|
||||
throw new NoDataException("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>
|
||||
/// Einzelnen Stundeneintrag holen
|
||||
/// </summary>
|
||||
public static async Task<DayTime> LoadEntry(int id) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
|
||||
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
|
||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
hours.TimeSpanVon = hours.begin.ToTimeSpan();
|
||||
hours.TimeSpanBis = hours.end.ToTimeSpan();
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
|
||||
public static Stunde Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||
|
||||
return
|
||||
new() {
|
||||
//Filename = Path.GetFileName(filename),
|
||||
//Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eintrag speichern
|
||||
/// </summary>
|
||||
public static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
bool isNew = false;
|
||||
if (stunde.id == null)
|
||||
isNew = true;
|
||||
await Auth.SaveItemAsync(tokendata.url, tokendata.apiKey, stunde, isNew);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eintrag löschen
|
||||
/// </summary>
|
||||
public static async Task DeleteEntry(DayTime stunde) {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
await Auth.DeleteItemAsync(tokendata.url + "/entry/" + stunde.id, tokendata.apiKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
class TokenData {
|
||||
public string token { get; set; }
|
||||
public string apiKey { get; set; }
|
||||
public string url { get; set; }
|
||||
public string operator_id { get; set; }
|
||||
internal class TokenData {
|
||||
public string Token { get; set; }
|
||||
public string ApiKey { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string Operator_id { get; set; }
|
||||
|
||||
public TokenData(string ak) {
|
||||
string dat = Encoding.UTF8.GetString(Convert.FromBase64String(ak));
|
||||
token = dat.Split('|')[1]; ;
|
||||
url = dat.Split('|')[2]; ;
|
||||
operator_id = dat.Split('|')[0]; ;
|
||||
apiKey = ak;
|
||||
Token = dat.Split('|')[1]; ;
|
||||
Url = dat.Split('|')[2]; ;
|
||||
Operator_id = dat.Split('|')[0]; ;
|
||||
ApiKey = ak;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
public struct Base {
|
||||
public Collection<Projekt>? Projekte { get; set; }
|
||||
public Collection<Gemeinde>? Gemeinden { get; set; }
|
||||
public Collection<Freistellung>? Freistellungen { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
public Hours Hours { get; set; }
|
||||
public List<DayTime> daytime { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
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>
|
||||
public int? id { get; set; }
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Mitarbeiter-ID
|
||||
@@ -19,92 +19,76 @@ public class DayTime
|
||||
/// <summary>
|
||||
/// Der betreffende Tag
|
||||
/// </summary>
|
||||
public DateTime day { get; set; }
|
||||
public DateTime Day { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Der Wochentag
|
||||
/// </summary>
|
||||
public int wday { get; set; }
|
||||
public int Wday { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Arbeitsbeginn
|
||||
/// </summary>
|
||||
public TimeOnly begin { get; set; }
|
||||
public TimeOnly Begin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Arbeitsende
|
||||
/// </summary>
|
||||
public TimeOnly end { get; set; }
|
||||
public TimeOnly End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Beschreibung der Arbeit
|
||||
/// Beschreibung der Tätigkeit
|
||||
/// </summary>
|
||||
public string description { get; set; }
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Freistellung
|
||||
/// </summary>
|
||||
public string? free { get; set; }
|
||||
public string? Free { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Freisetellung genehmigt?
|
||||
/// Freistellung genehmigt?
|
||||
/// </summary>
|
||||
public bool? approved { get; set; }
|
||||
public bool? Approved { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sollte nix sein
|
||||
/// </summary>
|
||||
public int? type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Das gewählte Projekt
|
||||
/// </summary>
|
||||
public int? projekt { get; set; }
|
||||
public int? Projekt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die gewählte Gemeinde
|
||||
/// </summary>
|
||||
public int? gemeinde { get; set; }
|
||||
public int? Gemeinde { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nachtstunden
|
||||
/// </summary>
|
||||
public TimeOnly night { get; set; }
|
||||
public TimeOnly Night { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Summe Arbeitszeit (inklusive Nachstunden mit Faktor)
|
||||
/// </summary>
|
||||
public Dictionary<string, TimeOnly> total { get; set; }
|
||||
public TimeOnly end_print { 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; }
|
||||
|
||||
/// <summary>
|
||||
/// Projekte für die Auswahlliste
|
||||
/// </summary>
|
||||
public Collection<Projekt> Projekte { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gemeinden für die Auswahlliste
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
public bool ProjektAktivSet { get; set; } = false;
|
||||
public bool GemeindeAktivSet { get; set; } = false;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class Gemeinde {
|
||||
/// <summary>
|
||||
/// Eindeutige Id der Gemeinde.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name der Gemeinde.
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
public class Hours : ObservableObject {
|
||||
public string? zeit;
|
||||
public string? nominal;
|
||||
internal class Hours : ObservableObject {
|
||||
public string? Zeit;
|
||||
public string? Nominal;
|
||||
//public Dictionary<DateOnly,NominalDay> nominal_day_api;
|
||||
public List<NominalDay>? nominal_day_api;
|
||||
public List<NominalDay>? Nominal_day_api;
|
||||
//public Dictionary<int,NominalWeek> nominal_week_api;
|
||||
public List<NominalWeek>? nominal_week_api;
|
||||
public List<NominalWeek>? Nominal_week_api;
|
||||
//public List<string> time_line;
|
||||
public string? zeit_total;
|
||||
public string? Zeit_total;
|
||||
|
||||
//https://stackoverflow.com/questions/29449641/deserialize-json-when-a-value-can-be-an-object-or-an-empty-array/29450279#29450279
|
||||
//[JsonConverter(typeof(JsonSingleOrEmptyArrayConverter<Hours>))]
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
public class NominalDay {
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
internal class NominalDay {
|
||||
public int day_number;
|
||||
public int month_number;
|
||||
public decimal hours;
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
public class NominalWeek
|
||||
{
|
||||
public int week_number;
|
||||
public decimal hours;
|
||||
internal class NominalWeek {
|
||||
public int Week_number;
|
||||
public decimal Hours;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class Projekt {
|
||||
/// <summary>
|
||||
/// Holt oder setzt die eindeutige ID des Projekts.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holt oder setzt den Namen des Projekts.
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Einstellungen
|
||||
/// </summary>
|
||||
public class Settings
|
||||
{
|
||||
public class Settings {
|
||||
/// <summary>
|
||||
/// Sind Projekte aktiv?
|
||||
/// </summary>
|
||||
public bool ProjektAktivSet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sind Gemeinden aktiv?
|
||||
/// </summary>
|
||||
public bool GemeindeAktivSet { get; set; }
|
||||
public Collection<Projekt> Projekte { get; set; }
|
||||
public Collection<Gemeinde> Gemeinden { get; set; }
|
||||
public Collection<Freistellung> Freistellungen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Liste der Projekte
|
||||
/// </summary>
|
||||
public List<Projekt>? Projekte { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Liste der Gemeinden
|
||||
/// </summary>
|
||||
public List<Gemeinde>? Gemeinden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Liste der Freistellungen
|
||||
/// </summary>
|
||||
public List<Freistellung>? Freistellungen { get; set; }
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Summe der geleisteten Stunden.
|
||||
/// </summary>
|
||||
public struct TimeDay {
|
||||
internal struct TimeDay {
|
||||
public int Day { get; set; }
|
||||
public decimal Hours { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
internal class Timetable
|
||||
{
|
||||
internal class Timetable {
|
||||
public List<TimetableEntry> timetable;
|
||||
public decimal wochensumme;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
|
||||
internal class TimetableEntry
|
||||
{
|
||||
public List<TimeOnly>? von;
|
||||
public List<TimeOnly>? bis;
|
||||
public decimal summe { get; set; }
|
||||
internal class TimetableEntry {
|
||||
public List<TimeOnly>? Von;
|
||||
public List<TimeOnly>? Bis;
|
||||
public decimal Summe { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
public class User {
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string surname { get; set; }
|
||||
public string token { get; set; }
|
||||
namespace Jugenddienst_Stunden.Types;
|
||||
internal class User {
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Surname { get; set; }
|
||||
public string Token { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,100 +1,68 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Jugenddienst_Stunden.Models;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
internal class StundeViewModel : ObservableObject, IQueryAttributable
|
||||
{
|
||||
|
||||
public int id { get; set; }
|
||||
public class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; } = "Eintrag bearbeiten";
|
||||
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;
|
||||
set
|
||||
{
|
||||
if (_stunde != value)
|
||||
{
|
||||
_stunde = value;
|
||||
OnPropertyChanged(nameof(Stunde));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Title { get; set; } = "Eintrag bearbeiten";
|
||||
private HoursBase HoursBase = new HoursBase();
|
||||
internal Settings Settings = new Settings();
|
||||
|
||||
public event EventHandler<string> AlertEvent;
|
||||
public event EventHandler<string> InfoEvent;
|
||||
public event Func<string, string, Task<bool>> ConfirmEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Gemeinden für die Auswahlliste
|
||||
/// </summary>
|
||||
public List<Gemeinde> OptionsGemeinde { get; private set; }
|
||||
|
||||
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; }
|
||||
/// <summary>
|
||||
/// Projekte für die Auswahlliste
|
||||
/// </summary>
|
||||
public List<Projekt> OptionsProjekt { get; private set; }
|
||||
|
||||
//private Gemeinde _selectedGemeinde;
|
||||
public Gemeinde SelectedOptionGemeinde
|
||||
{
|
||||
get => _stunde.GemeindeAktiv;
|
||||
set
|
||||
{
|
||||
if (_stunde.GemeindeAktiv != value)
|
||||
{
|
||||
//_selectedGemeinde = value;
|
||||
_stunde.GemeindeAktiv = value;
|
||||
OnPropertyChanged(nameof(SelectedOptionGemeinde));
|
||||
}
|
||||
/// <summary>
|
||||
/// Freistellungen für die Auswahlliste
|
||||
/// </summary>
|
||||
public List<Freistellung> OptionsFreistellung { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Vorhandene Zeiten anzeigen, wenn neuer Eintrag erstellt wird
|
||||
/// </summary>
|
||||
public List<DayTime> DayTimes { get; set; }
|
||||
|
||||
private DayTime _dayTime;
|
||||
/// <summary>
|
||||
/// Aktueller Stundeneintrag
|
||||
/// </summary>
|
||||
public DayTime DayTime {
|
||||
get => _dayTime;
|
||||
set {
|
||||
if (_dayTime != value) {
|
||||
_dayTime = value;
|
||||
|
||||
}OnPropertyChanged(nameof(DayTime));
|
||||
}
|
||||
}
|
||||
|
||||
//private Projekt _selectedProjekt;
|
||||
public Projekt SelectedOptionProjekt
|
||||
{
|
||||
get => _stunde.ProjektAktiv;
|
||||
set
|
||||
{
|
||||
if (_stunde.ProjektAktiv != value)
|
||||
{
|
||||
//_selectedProjekt = value;
|
||||
_stunde.ProjektAktiv = value;
|
||||
OnPropertyChanged(nameof(SelectedOptionProjekt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//private Freistellung _selectedFreistellung;
|
||||
public Freistellung SelectedOptionFreistellung
|
||||
{
|
||||
get => _stunde.FreistellungAktiv;
|
||||
set
|
||||
{
|
||||
if (_stunde.FreistellungAktiv != value)
|
||||
{
|
||||
_stunde.FreistellungAktiv = value;
|
||||
OnPropertyChanged(nameof(SelectedOptionFreistellung));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dürfen Gemeinden verwendet werden?
|
||||
/// </summary>
|
||||
public bool GemeindeAktivSet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dürfen Projekte verwendet werden?
|
||||
/// </summary>
|
||||
public bool ProjektAktivSet { get; set; }
|
||||
|
||||
|
||||
|
||||
@@ -104,156 +72,131 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable
|
||||
//public ICommand LoadDataCommand { get; private set; }
|
||||
|
||||
|
||||
public StundeViewModel()
|
||||
{
|
||||
_stunde = new DayTime();
|
||||
public StundeViewModel() {
|
||||
DayTime = new DayTime();
|
||||
|
||||
SaveCommand = new AsyncRelayCommand(Save);
|
||||
//DeleteCommand = new AsyncRelayCommand(Delete);
|
||||
DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
|
||||
|
||||
LoadSettingsAsync();
|
||||
}
|
||||
|
||||
public StundeViewModel(DayTime stunde)
|
||||
{
|
||||
_stunde = stunde;
|
||||
public StundeViewModel(DayTime stunde) {
|
||||
DayTime = new DayTime();
|
||||
|
||||
SaveCommand = new AsyncRelayCommand(Save);
|
||||
DeleteConfirmCommand = new AsyncRelayCommand(DeleteConfirm);
|
||||
LoadSettingsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
Hours _hours = await Models.Stunde.LoadBasicData();
|
||||
OptionsProjekt = new ObservableCollection<Projekt>(_hours.Projekte);
|
||||
OptionsGemeinde = new ObservableCollection<Gemeinde>(_hours.Gemeinden);
|
||||
OptionsFreistellung = new ObservableCollection<Freistellung>(_hours.Freistellungen);
|
||||
private async void LoadSettingsAsync() {
|
||||
Settings = await HoursBase.LoadSettings();
|
||||
|
||||
OptionsGemeinde = Settings.Gemeinden;
|
||||
OptionsProjekt = Settings.Projekte;
|
||||
OptionsFreistellung = Settings.Freistellungen;
|
||||
|
||||
GemeindeAktivSet = Settings.GemeindeAktivSet;
|
||||
ProjektAktivSet = Settings.ProjektAktivSet;
|
||||
|
||||
OnPropertyChanged(nameof(OptionsGemeinde));
|
||||
OnPropertyChanged(nameof(OptionsProjekt));
|
||||
OnPropertyChanged(nameof(OptionsFreistellung));
|
||||
_stunde.EmployeeId = _hours.EmployeeId;
|
||||
OnPropertyChanged(nameof(OptionsProjekt));
|
||||
|
||||
OnPropertyChanged(nameof(GemeindeAktivSet));
|
||||
OnPropertyChanged(nameof(ProjektAktivSet));
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
private async Task LoadData() {
|
||||
try {
|
||||
Hours _hours = await Models.HoursBase.LoadBasicData();
|
||||
DayTime.EmployeeId = _hours.EmployeeId;
|
||||
} catch (Exception e) {
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
async Task Save()
|
||||
{
|
||||
async Task Save() {
|
||||
bool exceptionOccurred = false;
|
||||
try
|
||||
{
|
||||
await Models.Stunde.SaveEntry(_stunde);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try {
|
||||
await Models.HoursBase.SaveEntry(DayTime);
|
||||
} catch (Exception e) {
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
exceptionOccurred = true;
|
||||
}
|
||||
if (!exceptionOccurred)
|
||||
{
|
||||
if (_stunde.id != null)
|
||||
{
|
||||
await Shell.Current.GoToAsync($"..?saved={_stunde.id}");
|
||||
}
|
||||
else
|
||||
{
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
if (!exceptionOccurred) {
|
||||
if (DayTime.Id != null) {
|
||||
await Shell.Current.GoToAsync($"..?saved={DayTime.Id}");
|
||||
} else {
|
||||
await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Delete()
|
||||
{
|
||||
await Models.Stunde.DeleteEntry(_stunde);
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
private async Task Delete() {
|
||||
await Models.HoursBase.DeleteEntry(DayTime);
|
||||
await Shell.Current.GoToAsync($"..?date={DayTime.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
|
||||
await Models.HoursBase.DeleteEntry(DayTime);
|
||||
await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}");
|
||||
} else { //nicht Löschen
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private async Task LoadSettings()
|
||||
{
|
||||
Settings = await Models.Stunde.LoadSettings();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Anwenden der Query-Parameter
|
||||
/// </summary>
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
|
||||
{
|
||||
await LoadSettings();
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||
|
||||
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))
|
||||
{
|
||||
_dayTime = await Models.HoursBase.LoadEntry(Convert.ToInt32(query["load"]));
|
||||
if (System.String.IsNullOrEmpty(DayTime.Description)) {
|
||||
AlertEvent?.Invoke(this, "Eintrag hat keine Daten zurückgegeben");
|
||||
}
|
||||
SubTitle = Stunde.day.ToString("dddd, d. MMMM yyyy");
|
||||
SubTitle = DayTime.Day.ToString("dddd, d. MMMM yyyy");
|
||||
|
||||
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);
|
||||
_dayTime.GemeindeAktiv = OptionsGemeinde.FirstOrDefault(Gemeinde => Gemeinde.Id == DayTime.Gemeinde) ?? new Gemeinde();
|
||||
|
||||
SelectedOptionGemeinde = OptionsGemeinde.FirstOrDefault(item => item.Id == Stunde.gemeinde) ?? new Gemeinde();
|
||||
OnPropertyChanged(nameof(SelectedOptionGemeinde));
|
||||
_dayTime.ProjektAktiv = OptionsProjekt.FirstOrDefault(Projekt => Projekt.Id == DayTime.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();
|
||||
OnPropertyChanged(nameof(SelectedOptionFreistellung));
|
||||
_dayTime.FreistellungAktiv = OptionsFreistellung.FirstOrDefault(Freistellung => Freistellung.Id == DayTime.Free) ?? new Freistellung();
|
||||
|
||||
OnPropertyChanged(nameof(DayTime));
|
||||
|
||||
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
|
||||
{
|
||||
DayTimes = await Models.Stunde.LoadDay(_date);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
try {
|
||||
DayTimes = await HoursBase.LoadDay(_date);
|
||||
} catch (Exception) {
|
||||
//Ein Tag ohne Einträge gibt eine Fehlermeldung,
|
||||
//die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht
|
||||
}
|
||||
|
||||
_stunde.day = _date;
|
||||
DayTime.Day = _date;
|
||||
SubTitle = _date.ToString("dddd, d. MMMM yyyy");
|
||||
|
||||
_ = LoadData();
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -49,19 +49,19 @@ public partial class LoginPage : ContentPage {
|
||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||
_lastDetectionTime = currentTime;
|
||||
foreach (var barcode in e.Results) {
|
||||
if (Stunde.apiKey != barcode.Value) {
|
||||
if (HoursBase.apiKey != barcode.Value) {
|
||||
_ = MainThread.InvokeOnMainThreadAsync(async () => {
|
||||
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||
|
||||
try {
|
||||
var tokendata = new TokenData(barcode.Value);
|
||||
var op = await Models.Operator.LoadData(barcode.Value);
|
||||
Models.Stunde.apiKey = barcode.Value;
|
||||
Models.Stunde.name = op.name;
|
||||
Models.Stunde.surname = op.surname;
|
||||
Models.Stunde.EmployeeId = int.Parse(op.id);
|
||||
var op = await Models.HoursBase.LoadOperator(barcode.Value);
|
||||
Models.HoursBase.apiKey = barcode.Value;
|
||||
Models.HoursBase.name = op.name;
|
||||
Models.HoursBase.surname = op.surname;
|
||||
Models.HoursBase.EmployeeId = int.Parse(op.id);
|
||||
Title = op.name + " " + op.surname;
|
||||
ServerLabel.Text = "Server: " + tokendata.url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||
|
||||
Preferences.Default.Set("apiKey", barcode.Value);
|
||||
Preferences.Default.Set("name", op.name);
|
||||
@@ -122,18 +122,18 @@ public partial class LoginPage : ContentPage {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Types.User response = await Auth.AuthUserPass(username, password, server);
|
||||
Types.User response = await BaseFunc.AuthUserPass(username, password, server);
|
||||
|
||||
var tokendata = new TokenData(response.token);
|
||||
var op = await Models.Operator.LoadData(response.token);
|
||||
Models.Stunde.apiKey = response.token;
|
||||
Models.Stunde.name = op.name;
|
||||
Models.Stunde.surname = op.surname;
|
||||
Models.Stunde.EmployeeId = int.Parse(op.id);
|
||||
var tokendata = new TokenData(response.Token);
|
||||
var op = await Models.HoursBase.LoadOperator(response.Token);
|
||||
Models.HoursBase.apiKey = response.Token;
|
||||
Models.HoursBase.name = op.name;
|
||||
Models.HoursBase.surname = op.surname;
|
||||
Models.HoursBase.EmployeeId = int.Parse(op.id);
|
||||
Title = op.name + " " + op.surname;
|
||||
ServerLabel.Text = "Server: " + tokendata.url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||
|
||||
Preferences.Default.Set("apiKey", response.token);
|
||||
Preferences.Default.Set("apiKey", response.Token);
|
||||
Preferences.Default.Set("name", op.name);
|
||||
Preferences.Default.Set("surname", op.surname);
|
||||
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="Beginn" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,0" MinimumWidthRequest="60"></Label>
|
||||
<TimePicker x:Name="TimeBegin" HorizontalOptions="Center" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding Stunde.TimeSpanVon}" Margin="0,0,0,-5" />
|
||||
<TimePicker x:Name="TimeBegin" HorizontalOptions="Center" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding DayTime.TimeSpanVon}" Margin="0,0,0,-5" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="Ende" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,0" MinimumWidthRequest="60"></Label>
|
||||
<TimePicker x:Name="TimeEnd" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding Stunde.TimeSpanBis}" Margin="0,0,0,-5" />
|
||||
<TimePicker x:Name="TimeEnd" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding DayTime.TimeSpanBis}" Margin="0,0,0,-5" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
</FlexLayout>
|
||||
@@ -38,21 +38,21 @@
|
||||
|
||||
<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" IsVisible="{Binding Settings.GemeindeAktivSet}">
|
||||
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}" SelectedItem="{Binding DayTime.GemeindeAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="0" IsVisible="{Binding GemeindeAktivSet}">
|
||||
</Picker>
|
||||
<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 x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding DayTime.ProjektAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="1" IsVisible="{Binding ProjektAktivSet}">
|
||||
</Picker>
|
||||
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding SelectedOptionFreistellung, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="2" >
|
||||
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding DayTime.FreistellungAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="2" >
|
||||
</Picker>
|
||||
</Grid>
|
||||
</Frame>
|
||||
|
||||
<Editor Placeholder="Beschreibung" Text="{Binding Stunde.description}" MinimumHeightRequest="40" AutoSize="TextChanges" FontSize="18" />
|
||||
<Editor Placeholder="Beschreibung" Text="{Binding DayTime.Description}" MinimumHeightRequest="40" AutoSize="TextChanges" FontSize="18" />
|
||||
|
||||
|
||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
||||
<Button Text="Speichern" Command="{Binding SaveCommand}" />
|
||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" IsEnabled="{Binding Stunde.id, Converter={StaticResource IntBoolConverter}}" />
|
||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" IsEnabled="{Binding DayTime.Id, Converter={StaticResource IntBoolConverter}}" />
|
||||
</Grid>
|
||||
|
||||
<BoxView HeightRequest="1" Margin="5,10"/>
|
||||
@@ -81,15 +81,15 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<HorizontalStackLayout Grid.Row="0" Grid.Column="0">
|
||||
<Label Grid.Column="0" Text="{Binding begin}"/>
|
||||
<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 End}"/>
|
||||
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}"/>
|
||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}"/>
|
||||
<Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0"/>
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
|
||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Description}" Padding="0,0,0,15"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
|
||||
@@ -74,15 +74,15 @@
|
||||
|
||||
</Grid.ColumnDefinitions>
|
||||
<HorizontalStackLayout Grid.Row="0" HorizontalOptions="FillAndExpand">
|
||||
<Label Grid.Column="0" Text="{Binding begin}" />
|
||||
<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" IsVisible="{Binding GemeindeAktivSet}" />
|
||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding ProjektAktivSet}" />
|
||||
<Label Text="{Binding End}" />
|
||||
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}" />
|
||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}" />
|
||||
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
|
||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Description}" Padding="0,0,0,15"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
|
||||
Reference in New Issue
Block a user