|
@@ -0,0 +1,130 @@
|
|
|
+using Avalonia.Media;
|
|
|
+using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
+using CommunityToolkit.Mvvm.Input;
|
|
|
+using InABox.Avalonia;
|
|
|
+using InABox.Avalonia.Components;
|
|
|
+using InABox.Core;
|
|
|
+using PRS.Avalonia.Modules;
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows.Input;
|
|
|
+
|
|
|
+namespace PRS.Avalonia.Components;
|
|
|
+
|
|
|
+public partial class SelectionViewButton : ObservableObject
|
|
|
+{
|
|
|
+ [ObservableProperty]
|
|
|
+ private string _text = "";
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private ICommand? _command;
|
|
|
+}
|
|
|
+
|
|
|
+public enum SelectionPageMode
|
|
|
+{
|
|
|
+ MultiSelect,
|
|
|
+ Confirm,
|
|
|
+ Immediate
|
|
|
+}
|
|
|
+
|
|
|
+public partial class SelectionViewModel : PopupViewModel<object?[]?>, IModuleViewModel, IDualFunctionViewModel
|
|
|
+{
|
|
|
+ public string Title => SelectionTitle;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private string _selectionTitle = "";
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private SelectionPageMode _selectionPageMode = SelectionPageMode.Immediate;
|
|
|
+
|
|
|
+ public ObservableCollection<ButtonStripItem> FilterButtons { get; } = new();
|
|
|
+
|
|
|
+ public ObservableCollection<SelectionViewButton> Buttons { get; } = new();
|
|
|
+
|
|
|
+ public AvaloniaDataGridColumns Columns { get; } = new();
|
|
|
+ public bool IsPopup { get; set; }
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private IEnumerable? _itemsSource;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _canSearch = true;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _canRefresh = true;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private DateTime _lastUpdated;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private Func<SelectionViewRefreshArgs, IEnumerable>? _refresh;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private Action<object?[]>? _selected;
|
|
|
+
|
|
|
+ private object?[] _selectedItems = [];
|
|
|
+
|
|
|
+ public SelectionViewModel()
|
|
|
+ {
|
|
|
+ PrimaryMenu.Add(new(Images.tick, Tick_Click));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Task<bool> Tick_Click()
|
|
|
+ {
|
|
|
+ Selected?.Invoke(_selectedItems);
|
|
|
+ Navigation.Back();
|
|
|
+ return Task.FromResult(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override Task OnActivated()
|
|
|
+ {
|
|
|
+ return Task.Run(() =>
|
|
|
+ {
|
|
|
+ var result = Refresh?.Invoke(new(false, FilterButtons.FirstOrDefault(x => x.Selected)?.Text ?? ""));
|
|
|
+ if (result is not null)
|
|
|
+ {
|
|
|
+ if (result is ICoreRepository repository)
|
|
|
+ {
|
|
|
+ LastUpdated = repository.LastUpdated;
|
|
|
+ }
|
|
|
+ ItemsSource = result;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private void OnRefresh(SelectionViewRefreshArgs args)
|
|
|
+ {
|
|
|
+ var result = Refresh?.Invoke(args);
|
|
|
+ if (result is null) return;
|
|
|
+
|
|
|
+ if(result is ICoreRepository repository)
|
|
|
+ {
|
|
|
+ LastUpdated = repository.LastUpdated;
|
|
|
+ }
|
|
|
+ ItemsSource = result;
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private void Select(object?[] items)
|
|
|
+ {
|
|
|
+ _selectedItems = items;
|
|
|
+ if(IsPopup)
|
|
|
+ {
|
|
|
+ Close(items);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(SelectionPageMode == SelectionPageMode.Immediate)
|
|
|
+ {
|
|
|
+ Selected?.Invoke(items);
|
|
|
+ Navigation.Back();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|