Comments etc.
This commit is contained in:
@@ -1,22 +1,19 @@
|
|||||||
using System;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
namespace Jugenddienst_Stunden.Models;
|
||||||
|
|
||||||
class TokenData {
|
class TokenData {
|
||||||
public string token { get; set; }
|
public string token { get; set; }
|
||||||
public string apiKey { get; set; }
|
public string apiKey { get; set; }
|
||||||
public string url { get; set; }
|
public string url { get; set; }
|
||||||
public string operator_id { get; set; }
|
public string operator_id { get; set; }
|
||||||
|
|
||||||
public TokenData(string apiKey) {
|
public TokenData(string ak) {
|
||||||
string dat = Encoding.UTF8.GetString(System.Convert.FromBase64String(apiKey));
|
string dat = Encoding.UTF8.GetString(Convert.FromBase64String(ak));
|
||||||
this.token = dat.Split('|')[1]; ;
|
token = dat.Split('|')[1]; ;
|
||||||
this.url = dat.Split('|')[2]; ;
|
url = dat.Split('|')[2]; ;
|
||||||
this.operator_id = dat.Split('|')[0]; ;
|
operator_id = dat.Split('|')[0]; ;
|
||||||
this.apiKey = apiKey;
|
apiKey = ak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,45 @@
|
|||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using System.Windows.Input;
|
|
||||||
using Microsoft.Maui.Dispatching;
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
|
||||||
//using BarcodeScanning;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.ViewModels;
|
namespace Jugenddienst_Stunden.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Die Loginseite
|
||||||
|
/// </summary>
|
||||||
public class LoginViewModel {
|
public class LoginViewModel {
|
||||||
|
/// <summary>
|
||||||
|
/// Name der Anwendung
|
||||||
|
/// </summary>
|
||||||
public string AppTitle => AppInfo.Name;
|
public string AppTitle => AppInfo.Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Programmversion
|
||||||
|
/// </summary>
|
||||||
public string Version => AppInfo.VersionString;
|
public string Version => AppInfo.VersionString;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Kurze Mitteilung für den Anwender
|
||||||
|
/// </summary>
|
||||||
public string Message => "Scanne den QR-Code von deinem Benutzerprofil auf der Stundenseite.";
|
public string Message => "Scanne den QR-Code von deinem Benutzerprofil auf der Stundenseite.";
|
||||||
|
|
||||||
public string Server { get; set; } = "Server: " + Preferences.Default.Get("apiUrl","").Replace("/appapi","").Replace("https://","").Replace("http://","");
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Genutzer Server für die API
|
||||||
|
/// </summary>
|
||||||
|
public string Server { get; set; } = "Server: " + Preferences.Default.Get("apiUrl", "").Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Titel der Seite - im Moment der aktuelle Anwender
|
||||||
|
/// </summary>
|
||||||
public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//public event EventHandler<string> AlertEvent;
|
||||||
|
//public event EventHandler<string> InfoEvent;
|
||||||
|
//public event Func<string,string, Task> MsgEvent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,46 +6,49 @@ using System.Windows.Input;
|
|||||||
namespace Jugenddienst_Stunden.ViewModels;
|
namespace Jugenddienst_Stunden.ViewModels;
|
||||||
|
|
||||||
internal class NotesViewModel : IQueryAttributable {
|
internal class NotesViewModel : IQueryAttributable {
|
||||||
public ObservableCollection<ViewModels.NoteViewModel> AllNotes { get; }
|
public ObservableCollection<NoteViewModel> AllNotes { get; }
|
||||||
public ICommand NewCommand { get; }
|
public ICommand NewCommand { get; }
|
||||||
public ICommand SelectNoteCommand { get; }
|
public ICommand SelectNoteCommand { get; }
|
||||||
|
|
||||||
public NotesViewModel() {
|
public NotesViewModel() {
|
||||||
AllNotes = new ObservableCollection<ViewModels.NoteViewModel>(Models.Note.LoadAll().Select(n => new NoteViewModel(n)));
|
AllNotes = new ObservableCollection<NoteViewModel>(Models.Note.LoadAll().Select(n => new NoteViewModel(n)));
|
||||||
NewCommand = new AsyncRelayCommand(NewNoteAsync);
|
NewCommand = new AsyncRelayCommand(NewNoteAsync);
|
||||||
SelectNoteCommand = new AsyncRelayCommand<ViewModels.NoteViewModel>(SelectNoteAsync);
|
SelectNoteCommand = new AsyncRelayCommand<NoteViewModel?>(SelectNoteAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task NewNoteAsync() {
|
private async Task NewNoteAsync() {
|
||||||
await Shell.Current.GoToAsync(nameof(Views.NotePage));
|
await Shell.Current.GoToAsync(nameof(Views.NotePage));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SelectNoteAsync(ViewModels.NoteViewModel note) {
|
private async Task SelectNoteAsync(NoteViewModel? note) {
|
||||||
if (note != null)
|
if (note != null)
|
||||||
await Shell.Current.GoToAsync($"{nameof(Views.NotePage)}?load={note.Identifier}");
|
await Shell.Current.GoToAsync($"{nameof(Views.NotePage)}?load={note.Identifier}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||||
if (query.ContainsKey("deleted")) {
|
if (query.ContainsKey("deleted")) {
|
||||||
string noteId = query["deleted"].ToString();
|
string? noteId = query["deleted"]?.ToString();
|
||||||
NoteViewModel matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
|
if (noteId != null) {
|
||||||
|
NoteViewModel? matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
|
||||||
|
|
||||||
// If note exists, delete it
|
// If note exists, delete it
|
||||||
if (matchedNote != null)
|
if (matchedNote != null)
|
||||||
AllNotes.Remove(matchedNote);
|
AllNotes.Remove(matchedNote);
|
||||||
} else if (query.ContainsKey("saved")) {
|
|
||||||
string noteId = query["saved"].ToString();
|
|
||||||
NoteViewModel matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
|
|
||||||
|
|
||||||
// If note is found, update it
|
|
||||||
if (matchedNote != null) {
|
|
||||||
matchedNote.Reload();
|
|
||||||
AllNotes.Move(AllNotes.IndexOf(matchedNote), 0);
|
|
||||||
}
|
}
|
||||||
|
} else if (query.ContainsKey("saved")) {
|
||||||
|
string? noteId = query["saved"]?.ToString();
|
||||||
|
if (noteId != null) {
|
||||||
|
NoteViewModel? matchedNote = AllNotes.FirstOrDefault((n) => n.Identifier == noteId);
|
||||||
|
|
||||||
// If note isn't found, it's new; add it.
|
// If note is found, update it
|
||||||
else
|
if (matchedNote != null) {
|
||||||
AllNotes.Insert(0, new NoteViewModel(Note.Load(noteId)));
|
matchedNote.Reload();
|
||||||
|
AllNotes.Move(AllNotes.IndexOf(matchedNote), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If note isn't found, it's new; add it.
|
||||||
|
else { AllNotes.Insert(0, new NoteViewModel(Note.Load(noteId))); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using Jugenddienst_Stunden.Models;
|
using Jugenddienst_Stunden.Models;
|
||||||
using Jugenddienst_Stunden.ViewModels;
|
using Jugenddienst_Stunden.ViewModels;
|
||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
@@ -6,15 +7,26 @@ using ZXing.Net.Maui;
|
|||||||
|
|
||||||
namespace Jugenddienst_Stunden.Views;
|
namespace Jugenddienst_Stunden.Views;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Die Loginseite mit dem Barcodescanner
|
||||||
|
/// </summary>
|
||||||
public partial class LoginPage : ContentPage {
|
public partial class LoginPage : ContentPage {
|
||||||
|
|
||||||
private DateTime _lastDetectionTime;
|
private DateTime _lastDetectionTime;
|
||||||
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
|
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
|
||||||
private readonly LoginViewModel _loginViewModel = new LoginViewModel();
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CTOR
|
||||||
|
/// </summary>
|
||||||
public LoginPage() {
|
public LoginPage() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
//if (BindingContext is LoginViewModel vm) {
|
||||||
|
// vm.AlertEvent += Vm_AlertEvent;
|
||||||
|
// vm.InfoEvent += Vm_InfoEvent;
|
||||||
|
// vm.MsgEvent += Vm_MsgEvent;
|
||||||
|
//}
|
||||||
|
|
||||||
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
|
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
|
||||||
Formats = ZXing.Net.Maui.BarcodeFormat.QrCode,
|
Formats = ZXing.Net.Maui.BarcodeFormat.QrCode,
|
||||||
AutoRotate = true,
|
AutoRotate = true,
|
||||||
@@ -22,40 +34,34 @@ public partial class LoginPage : ContentPage {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//public event EventHandler<string> AlertEvent;
|
|
||||||
|
|
||||||
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
||||||
//var first = e.Results?.FirstOrDefault();
|
|
||||||
var currentTime = DateTime.Now;
|
var currentTime = DateTime.Now;
|
||||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||||
_lastDetectionTime = currentTime;
|
_lastDetectionTime = currentTime;
|
||||||
foreach (var barcode in e.Results) {
|
foreach (var barcode in e.Results) {
|
||||||
if (Stunde.apiKey != barcode.Value) {
|
if (Stunde.apiKey != barcode.Value) {
|
||||||
MainThread.InvokeOnMainThreadAsync(async () => {
|
_ = MainThread.InvokeOnMainThreadAsync(async () => {
|
||||||
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
var tokendata = new TokenData(barcode.Value);
|
||||||
var op = await Models.Operator.LoadData(barcode.Value);
|
var op = await Models.Operator.LoadData(barcode.Value);
|
||||||
Models.Stunde.apiKey = barcode.Value;
|
Models.Stunde.apiKey = barcode.Value;
|
||||||
Models.Stunde.name = op.name;
|
Models.Stunde.name = op.name;
|
||||||
Models.Stunde.surname = op.surname;
|
Models.Stunde.surname = op.surname;
|
||||||
Models.Stunde.EmployeeId = int.Parse(op.id);
|
Models.Stunde.EmployeeId = int.Parse(op.id);
|
||||||
Title = op.name + " " + op.surname;
|
Title = op.name + " " + op.surname;
|
||||||
|
ServerLabel.Text = "Server: " + tokendata.url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||||
|
|
||||||
Preferences.Default.Set("apiKey", barcode.Value);
|
Preferences.Default.Set("apiKey", barcode.Value);
|
||||||
Preferences.Default.Set("name", op.name);
|
Preferences.Default.Set("name", op.name);
|
||||||
Preferences.Default.Set("surname", op.surname);
|
Preferences.Default.Set("surname", op.surname);
|
||||||
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
|
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
|
||||||
//Preferences.Default.Set("apiUrl", Pre);
|
|
||||||
_loginViewModel.Server = Preferences.Default.Get("apiUrl", "");
|
|
||||||
|
|
||||||
|
|
||||||
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
|
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//AlertEvent?.Invoke(this, e.Message);
|
await DisplayAlert("Fehler", e.Message, "OK");
|
||||||
await DisplayAlert("Fehler",
|
|
||||||
e.Message,
|
|
||||||
"OK");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -84,4 +90,14 @@ public partial class LoginPage : ContentPage {
|
|||||||
barcodeScannerView.IsDetecting = true;
|
barcodeScannerView.IsDetecting = true;
|
||||||
barcodeScannerView.CameraLocation = CameraLocation.Rear;
|
barcodeScannerView.CameraLocation = CameraLocation.Rear;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private void Vm_AlertEvent(object? sender, string e) {
|
||||||
|
// DisplayAlert("Fehler:", e, "OK");
|
||||||
|
//}
|
||||||
|
//private void Vm_InfoEvent(object? sender, string e) {
|
||||||
|
// DisplayAlert("Information:", e, "OK");
|
||||||
|
//}
|
||||||
|
//private async Task Vm_MsgEvent(string title, string message) {
|
||||||
|
// await DisplayAlert(title, message, "OK");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ namespace Jugenddienst_Stunden.Views;
|
|||||||
|
|
||||||
public partial class StundePage : ContentPage {
|
public partial class StundePage : ContentPage {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CTOR
|
||||||
|
/// </summary>
|
||||||
public StundePage() {
|
public StundePage() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,23 @@ using Jugenddienst_Stunden.ViewModels;
|
|||||||
namespace Jugenddienst_Stunden.Views;
|
namespace Jugenddienst_Stunden.Views;
|
||||||
|
|
||||||
public partial class StundenPage : ContentPage {
|
public partial class StundenPage : ContentPage {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CTOR
|
||||||
|
/// </summary>
|
||||||
public StundenPage() {
|
public StundenPage() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
if(BindingContext is StundenViewModel vm) {
|
if (BindingContext is StundenViewModel vm) {
|
||||||
vm.AlertEvent += Vm_AlertEvent;
|
vm.AlertEvent += Vm_AlertEvent;
|
||||||
vm.InfoEvent += Vm_InfoEvent;
|
vm.InfoEvent += Vm_InfoEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// Bildschirmh<6D>he abrufen
|
||||||
|
//var screenHeight = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
|
||||||
|
|
||||||
|
//// Berechnen der gew<65>nschten H<>he
|
||||||
|
//var desiredHeight = screenHeight - 450; // Abz<62>glich der Stunden<65>bersicht
|
||||||
|
//stundeItems.HeightRequest = desiredHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Vm_AlertEvent(object? sender, string e) {
|
private void Vm_AlertEvent(object? sender, string e) {
|
||||||
@@ -18,16 +29,22 @@ public partial class StundenPage : ContentPage {
|
|||||||
DisplayAlert("Information:", e, "OK");
|
DisplayAlert("Information:", e, "OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Beim Laden der Seite den Titel setzen
|
||||||
|
/// </summary>
|
||||||
protected override void OnAppearing() {
|
protected override void OnAppearing() {
|
||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
Title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
Title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Das ausgew<65>hlte Datum merken
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
protected void OnDateSelected(object sender, DateChangedEventArgs e) {
|
protected void OnDateSelected(object sender, DateChangedEventArgs e) {
|
||||||
DateTime selectedDate = e.NewDate;
|
DateTime selectedDate = e.NewDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) {
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user