Added the NewControl as a content replacement for the MainWindow.

This commit is contained in:
alphafetus committed 2023-10-09 14:56:06 -04:00
1 parent 8c7e1b917f
commit 0e5be04b02
31 files changed
+262 -153

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
using System;
using System.Reactive;
using PcgsInvUi.Models;
using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class EditViewModel : ViewModelBase
{
public Coin CurrentCoin { get; set; }
public ReactiveCommand<Unit, Unit> OkCommand { get; }
public EditViewModel(Coin coin)
{
CurrentCoin = coin;
var okEnabled = this.WhenAnyValue(
x => x.CurrentCoin.PcgsNumber,
x => x.CurrentCoin.Grade,
x => x.CurrentCoin.Quantity,
(id, grade, quantity) => (id != 0) &&
!string.IsNullOrWhiteSpace(grade) &&
(quantity != 0)
);
// Setup OkCommand - all Coin-related properties must be non-whitespace.
OkCommand = ReactiveCommand.Create(() => { });
}
}
+29 -8
View File
@@ -9,23 +9,29 @@ namespace PcgsInvUi.ViewModels;
public class MainWindowViewModel : ViewModelBase
{
public CoinListViewModel List { get; }
private ViewModelBase _content;
private ViewModelBase _mainContent;
private ViewModelBase _sideContent;
public MainWindowViewModel(CoinCollection coins)
{
List = new CoinListViewModel(coins.GetItems());
Content = List;
MainContent = List;
}
public ViewModelBase Content
public ViewModelBase MainContent
{
get => _content;
private set => this.RaiseAndSetIfChanged(ref _content, value);
get => _mainContent;
private set => this.RaiseAndSetIfChanged(ref _mainContent, value);
}
public ViewModelBase SidebarContent
{
get => _sideContent;
private set => this.RaiseAndSetIfChanged(ref _sideContent, value);
}
public void AddItem()
{
Console.WriteLine("You hit the button!");
var newViewModel = new NewViewModel();
Observable.Merge(
@@ -37,9 +43,24 @@ public class MainWindowViewModel : ViewModelBase
if (model != null)
List.CoinCollection.Add(model);
Content = List;
MainContent = List;
});
Content = newViewModel;
MainContent = newViewModel;
}
public void EditItem()
{
var editViewModel = new EditViewModel(List.SelectedCoin);
}
public void DeleteItem()
{
}
public void FindItem()
{
}
}
+49 -3
View File
@@ -1,5 +1,6 @@
using System;
using System.Reactive;
using System.Collections.Generic;
using PcgsInvUi.Models;
using ReactiveUI;
@@ -26,17 +27,62 @@ public class NewViewModel : ViewModelBase
get => _quantity;
set => this.RaiseAndSetIfChanged(ref _quantity, value);
}
public List<string> GradesList { get; }
public NewViewModel()
{
var okEnabled = this.WhenAnyValue(
x => x.PcgsNumber,
x => !string.IsNullOrWhiteSpace(x));
x => x.Grade,
x => x.Quantity,
(id, grade, quantity) => !string.IsNullOrWhiteSpace(id) &&
!string.IsNullOrWhiteSpace(grade) &&
!string.IsNullOrWhiteSpace(quantity));
// This will eventually send our request to the public API, then construct our coin.
OkCommand = ReactiveCommand.Create(
() => new Coin { PcgsNumber = Int32.Parse(PcgsNumber) },
() => new Coin { PcgsNumber = Int32.Parse(PcgsNumber),
Grade = Grade,
Quantity = Int32.Parse(Quantity) },
okEnabled);
CancelCommand = ReactiveCommand.Create(() => { });
// Initialize grade values for use in the view.
// This must be typed out manually, as there is no way to get a list of grades from the API.
GradesList = new List<string>()
{
"P-01",
"FR-02",
"AG-03",
"G-04",
"G-06",
"VG-08",
"VG-10",
"F-12",
"F-15",
"VF-20",
"VF-25",
"VF-30",
"VF-35",
"EF-40",
"EF-45",
"AU-50",
"AU-53",
"AU-55",
"AU-58",
"MS-60",
"MS-61",
"MS-62",
"MS-63",
"MS-64",
"MS-65",
"MS-66",
"MS-67",
"MS-68",
"MS-69",
"MS-70"
};
}
public ReactiveCommand<Unit, Coin> OkCommand { get; }