Started working on main page

This commit is contained in:
2025-11-12 20:12:03 +01:00
parent e0bf95060a
commit 969219137a
148 changed files with 1053 additions and 93 deletions

View File

@@ -0,0 +1,106 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using WorkTime.Models;
using WorkTime.Models.Repositories;
namespace WorkTime.Mobile.Pages;
public partial class CapturePage : ContentPage {
private readonly CapturePageModel _model;
public CapturePage(CapturePageModel model) {
InitializeComponent();
BindingContext = model;
_model = model;
}
protected override void OnAppearing() {
base.OnAppearing();
if (_model.AppearingCommand.CanExecute(null))
_model.AppearingCommand.Execute(null);
}
}
public partial class CapturePageModel(ITimeEntryRepository entryRepository) : ObservableObject {
private DateOnly _currentDate = DateOnly.FromDateTime(DateTime.Now);
[ObservableProperty]
public partial ObservableCollection<TimeEntry> Entries { get; set; } = new();
[ObservableProperty]
public partial EntryType CurrentType { get; set; } = EntryType.Login;
public string CurrentTypeName => CurrentType switch {
EntryType.Login => "Einstempeln",
EntryType.LoginHome => "Einstempeln (mobA)",
EntryType.LoginTrip => "Dienstreise starten",
EntryType.Logout => "Ausstempeln",
EntryType.LogoutHome => "Ausstempeln (mobA)",
EntryType.LogoutTrip => "Dienstreise beenden",
_ => "UNKNOWN"
};
partial void OnCurrentTypeChanged(EntryType value) {
OnPropertyChanged(nameof(CurrentTypeName));
}
[RelayCommand]
public async Task LoadDate(DateOnly date) {
_currentDate = date;
Entries.Clear();
var result = await entryRepository.GetTimeEntries(date);
foreach (var entry in result) {
Entries.Add(entry);
}
UpdateCurrentType();
}
private void UpdateCurrentType() {
var last = Entries.LastOrDefault();
if (last is null) {
CurrentType = EntryType.Login;
return;
}
CurrentType = last.Type switch {
EntryType.Login => EntryType.Logout,
EntryType.LoginHome => EntryType.LogoutHome,
EntryType.LoginTrip => EntryType.LogoutTrip,
EntryType.Logout => EntryType.Login,
EntryType.LogoutHome => EntryType.LoginHome,
EntryType.LogoutTrip => EntryType.LoginTrip,
_ => EntryType.Login
};
}
[RelayCommand]
public async Task OnAppearing() {
await LoadDate(_currentDate);
}
[RelayCommand]
public async Task RegisterEntry(TimeEntry? entry = null) {
entry ??= new TimeEntry {
Timestamp = DateTime.Now,
Type = CurrentType
};
await entryRepository.AddTimeEntry(entry);
await LoadDate(_currentDate);
}
[RelayCommand]
public async Task DeleteEntry(Guid entryId) {
await entryRepository.DeleteTimeEntry(entryId);
await LoadDate(_currentDate);
}
}