Adding new local history page
This commit is contained in:
parent
59441b386a
commit
7592c39529
@ -22,10 +22,11 @@ public class App : Application
|
||||
services.AddSingleton<IApiService, ApiService>();
|
||||
|
||||
// ViewModels
|
||||
services.AddTransient<HistoryViewModel>();
|
||||
services.AddTransient<SearchViewModel>();
|
||||
services.AddTransient<AuthWindowViewModel>();
|
||||
services.AddTransient<MainWindowViewModel>();
|
||||
services.AddTransient<CheckNumberViewModel>();
|
||||
services.AddTransient<HistoryViewModel>();
|
||||
|
||||
// Windows
|
||||
services.AddWindowFactory<AuthWindow>();
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<!--
|
||||
<Grid ColumnDefinitions="300, Auto, *">
|
||||
<ListBox ItemsSource="{Binding Vehicles}"
|
||||
ItemTemplate="{StaticResource VehicleCell}"
|
||||
@ -26,4 +27,5 @@
|
||||
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
||||
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
|
||||
</Grid>
|
||||
-->
|
||||
</UserControl>
|
||||
|
||||
30
AutoCat/Pages/SearchPage.axaml
Normal file
30
AutoCat/Pages/SearchPage.axaml
Normal file
@ -0,0 +1,30 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:AutoCat.ViewModels"
|
||||
xmlns:utils="using:AutoCat.Utils"
|
||||
xmlns:pages="clr-namespace:AutoCat.Pages"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="AutoCat.Pages.SearchPage"
|
||||
x:DataType="vm:SearchViewModel"
|
||||
x:CompileBindings="True"
|
||||
DataContext="{utils:ViewModelProvider vm:SearchViewModel}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceInclude Source="../Templates/VehicleCell.axaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid ColumnDefinitions="300, Auto, *">
|
||||
<ListBox ItemsSource="{Binding Vehicles}"
|
||||
ItemTemplate="{StaticResource VehicleCell}"
|
||||
Name="VehiclesList"/>
|
||||
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
||||
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
||||
13
AutoCat/Pages/SearchPage.axaml.cs
Normal file
13
AutoCat/Pages/SearchPage.axaml.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace AutoCat.Pages;
|
||||
|
||||
public partial class SearchPage : UserControl
|
||||
{
|
||||
public SearchPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@ -1,43 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCatCore.Model;
|
||||
using AutoCatCore.Services.Api;
|
||||
using DynamicData;
|
||||
|
||||
namespace AutoCat.ViewModels;
|
||||
|
||||
public class HistoryViewModel: ViewModelBase
|
||||
{
|
||||
#region Dependencies
|
||||
|
||||
private readonly IApiService _apiService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public ObservableCollection<Vehicle> Vehicles { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public HistoryViewModel(IApiService apiService)
|
||||
public async Task AddVehicle(Vehicle vehicle)
|
||||
{
|
||||
_apiService = apiService;
|
||||
Vehicles = new ObservableCollection<Vehicle>();
|
||||
LoadVehicles();
|
||||
}
|
||||
|
||||
private async void LoadVehicles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var pagedResponse = await _apiService.GetVehicles();
|
||||
Vehicles.Clear();
|
||||
Vehicles.AddRange(pagedResponse.Items);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
43
AutoCat/ViewModels/SearchViewModel.cs
Normal file
43
AutoCat/ViewModels/SearchViewModel.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using AutoCatCore.Model;
|
||||
using AutoCatCore.Services.Api;
|
||||
using DynamicData;
|
||||
|
||||
namespace AutoCat.ViewModels;
|
||||
|
||||
public class SearchViewModel: ViewModelBase
|
||||
{
|
||||
#region Dependencies
|
||||
|
||||
private readonly IApiService _apiService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public ObservableCollection<Vehicle> Vehicles { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public SearchViewModel(IApiService apiService)
|
||||
{
|
||||
_apiService = apiService;
|
||||
Vehicles = new ObservableCollection<Vehicle>();
|
||||
LoadVehicles();
|
||||
}
|
||||
|
||||
private async void LoadVehicles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var pagedResponse = await _apiService.GetVehicles();
|
||||
Vehicles.Clear();
|
||||
Vehicles.AddRange(pagedResponse.Items);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCat.Pages;
|
||||
using AutoCat.ViewModels;
|
||||
using AutoCatCore.Model;
|
||||
using Avalonia.Controls;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
|
||||
@ -11,6 +13,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
private readonly SettingsPage _settingsPage = new SettingsPage();
|
||||
private readonly HistoryPage _historyPage = new HistoryPage();
|
||||
private readonly SearchPage _searchPage = new SearchPage();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@ -39,14 +42,12 @@ public partial class MainWindow : Window
|
||||
}
|
||||
else if (args.SelectedItem is NavigationViewItem item)
|
||||
{
|
||||
switch (item.Tag)
|
||||
NavView.Content = item.Tag switch
|
||||
{
|
||||
case "History":
|
||||
break;
|
||||
case "Search":
|
||||
NavView.Content = _historyPage;
|
||||
break;
|
||||
}
|
||||
"History" => _historyPage,
|
||||
"Search" => _searchPage,
|
||||
_ => NavView.Content
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,10 +66,14 @@ public partial class MainWindow : Window
|
||||
|
||||
if (dialogContent.DataContext is CheckNumberViewModel vm)
|
||||
{
|
||||
vm.AutoCloseEvent += (_, _) =>
|
||||
vm.AutoCloseEvent += async (_, _) =>
|
||||
{
|
||||
dialog.Hide();
|
||||
Console.WriteLine($"Checked number: {vm.Vehicle?.Number}");
|
||||
if (_historyPage.DataContext is HistoryViewModel hvm && vm.Vehicle != null)
|
||||
{
|
||||
await hvm.AddVehicle(vm.Vehicle);
|
||||
NavView.Content = _historyPage;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user