|
@@ -1,19 +1,112 @@
|
|
|
-using CommunityToolkit.Mvvm.Input;
|
|
|
+using Avalonia.Threading;
|
|
|
+using Comal.Classes;
|
|
|
+using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
+using CommunityToolkit.Mvvm.Input;
|
|
|
using DialogHostAvalonia;
|
|
|
+using DynamicData;
|
|
|
using InABox.Avalonia;
|
|
|
+using InABox.Core;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace PRS.Avalonia.Modules;
|
|
|
|
|
|
+public partial class EquipmentMapsMenuItem(Guid id, string description, bool selected) : ObservableObject
|
|
|
+{
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _selected = selected;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private string _description = description;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private Guid _ID = id;
|
|
|
+}
|
|
|
+
|
|
|
public partial class EquipmentMapsMenuViewModel : PopupViewModel
|
|
|
{
|
|
|
+ public event EventHandler? OnChanged;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ public HashSet<Guid> _selectedItems = [];
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private ObservableCollection<EquipmentMapsMenuItem> _items = [];
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private EquipmentGroupModel _equipmentGroups;
|
|
|
+
|
|
|
+ public EquipmentMapsMenuViewModel()
|
|
|
+ {
|
|
|
+ EquipmentGroups = new EquipmentGroupModel(
|
|
|
+ DataAccess,
|
|
|
+ () => LookupFactory.DefineFilter<EquipmentGroup>());
|
|
|
+ }
|
|
|
+
|
|
|
+ protected async override Task<TimeSpan> OnRefresh()
|
|
|
+ {
|
|
|
+ await EquipmentGroups.RefreshAsync(false);
|
|
|
+
|
|
|
+ Dispatcher.UIThread.Invoke(() =>
|
|
|
+ {
|
|
|
+ Items.Clear();
|
|
|
+ Items.AddRange(EquipmentGroups.Items
|
|
|
+ .Select(x => new EquipmentMapsMenuItem(x.ID, x.Description, SelectedItems.Contains(x.ID)))
|
|
|
+ .Prepend(new EquipmentMapsMenuItem(CoreUtils.FullGuid, "Job Locations", SelectedItems.Contains(CoreUtils.FullGuid))));
|
|
|
+ foreach (var item in Items)
|
|
|
+ {
|
|
|
+ item.PropertyChanged += Item_PropertyChanged;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return TimeSpan.Zero;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Item_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not EquipmentMapsMenuItem item) return;
|
|
|
+
|
|
|
+ if(e.PropertyName == nameof(EquipmentMapsMenuItem.Selected))
|
|
|
+ {
|
|
|
+ if (item.Selected)
|
|
|
+ {
|
|
|
+ SelectedItems.Add(item.ID);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SelectedItems.Remove(item.ID);
|
|
|
+ }
|
|
|
+ DoChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[RelayCommand]
|
|
|
private void ClearAll()
|
|
|
{
|
|
|
- Close();
|
|
|
+ SelectedItems.Clear();
|
|
|
+ foreach (var item in Items)
|
|
|
+ {
|
|
|
+ item.Selected = false;
|
|
|
+ }
|
|
|
+ DoChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private void SelectAll()
|
|
|
+ {
|
|
|
+ foreach (var item in Items)
|
|
|
+ {
|
|
|
+ item.Selected = true;
|
|
|
+ SelectedItems.Add(item.ID);
|
|
|
+ }
|
|
|
+ DoChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoChanged()
|
|
|
+ {
|
|
|
+ OnChanged?.Invoke(this, EventArgs.Empty);
|
|
|
}
|
|
|
}
|