Comments etc.
This commit is contained in:
@@ -1,19 +1,45 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Maui.Dispatching;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
//using BarcodeScanning;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Die Loginseite
|
||||
/// </summary>
|
||||
public class LoginViewModel {
|
||||
/// <summary>
|
||||
/// Name der Anwendung
|
||||
/// </summary>
|
||||
public string AppTitle => AppInfo.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Programmversion
|
||||
/// </summary>
|
||||
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 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 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;
|
||||
|
||||
internal class NotesViewModel : IQueryAttributable {
|
||||
public ObservableCollection<ViewModels.NoteViewModel> AllNotes { get; }
|
||||
public ObservableCollection<NoteViewModel> AllNotes { get; }
|
||||
public ICommand NewCommand { get; }
|
||||
public ICommand SelectNoteCommand { get; }
|
||||
|
||||
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);
|
||||
SelectNoteCommand = new AsyncRelayCommand<ViewModels.NoteViewModel>(SelectNoteAsync);
|
||||
SelectNoteCommand = new AsyncRelayCommand<NoteViewModel?>(SelectNoteAsync);
|
||||
}
|
||||
|
||||
private async Task NewNoteAsync() {
|
||||
await Shell.Current.GoToAsync(nameof(Views.NotePage));
|
||||
}
|
||||
|
||||
private async Task SelectNoteAsync(ViewModels.NoteViewModel note) {
|
||||
private async Task SelectNoteAsync(NoteViewModel? note) {
|
||||
if (note != null)
|
||||
await Shell.Current.GoToAsync($"{nameof(Views.NotePage)}?load={note.Identifier}");
|
||||
}
|
||||
|
||||
void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||
if (query.ContainsKey("deleted")) {
|
||||
string noteId = query["deleted"].ToString();
|
||||
NoteViewModel matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
|
||||
string? noteId = query["deleted"]?.ToString();
|
||||
if (noteId != null) {
|
||||
NoteViewModel? matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
|
||||
|
||||
// If note exists, delete it
|
||||
if (matchedNote != null)
|
||||
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);
|
||||
// If note exists, delete it
|
||||
if (matchedNote != null)
|
||||
AllNotes.Remove(matchedNote);
|
||||
}
|
||||
} 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.
|
||||
else
|
||||
AllNotes.Insert(0, new NoteViewModel(Note.Load(noteId)));
|
||||
// If note is found, update it
|
||||
if (matchedNote != null) {
|
||||
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))); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user