Adding new local history page

This commit is contained in:
Selim Mustafaev 2024-05-07 01:04:44 +03:00
parent 59441b386a
commit 7592c39529
7 changed files with 107 additions and 44 deletions

View File

@ -22,10 +22,11 @@ public class App : Application
services.AddSingleton<IApiService, ApiService>(); services.AddSingleton<IApiService, ApiService>();
// ViewModels // ViewModels
services.AddTransient<HistoryViewModel>(); services.AddTransient<SearchViewModel>();
services.AddTransient<AuthWindowViewModel>(); services.AddTransient<AuthWindowViewModel>();
services.AddTransient<MainWindowViewModel>(); services.AddTransient<MainWindowViewModel>();
services.AddTransient<CheckNumberViewModel>(); services.AddTransient<CheckNumberViewModel>();
services.AddTransient<HistoryViewModel>();
// Windows // Windows
services.AddWindowFactory<AuthWindow>(); services.AddWindowFactory<AuthWindow>();

View File

@ -19,6 +19,7 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<!--
<Grid ColumnDefinitions="300, Auto, *"> <Grid ColumnDefinitions="300, Auto, *">
<ListBox ItemsSource="{Binding Vehicles}" <ListBox ItemsSource="{Binding Vehicles}"
ItemTemplate="{StaticResource VehicleCell}" ItemTemplate="{StaticResource VehicleCell}"
@ -26,4 +27,5 @@
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/> <GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/> <pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
</Grid> </Grid>
-->
</UserControl> </UserControl>

View 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>

View 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();
}
}

View File

@ -1,43 +1,12 @@
using System; using System.Threading.Tasks;
using System.Collections.ObjectModel;
using AutoCatCore.Model; using AutoCatCore.Model;
using AutoCatCore.Services.Api;
using DynamicData;
namespace AutoCat.ViewModels; namespace AutoCat.ViewModels;
public class HistoryViewModel: ViewModelBase public class HistoryViewModel: ViewModelBase
{ {
#region Dependencies public async Task AddVehicle(Vehicle vehicle)
private readonly IApiService _apiService;
#endregion
#region Properties
public ObservableCollection<Vehicle> Vehicles { get; set; }
#endregion
public HistoryViewModel(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}");
}
} }
} }

View 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}");
}
}
}

View File

@ -1,7 +1,9 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using AutoCat.Pages; using AutoCat.Pages;
using AutoCat.ViewModels; using AutoCat.ViewModels;
using AutoCatCore.Model;
using Avalonia.Controls; using Avalonia.Controls;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
@ -11,6 +13,7 @@ public partial class MainWindow : Window
{ {
private readonly SettingsPage _settingsPage = new SettingsPage(); private readonly SettingsPage _settingsPage = new SettingsPage();
private readonly HistoryPage _historyPage = new HistoryPage(); private readonly HistoryPage _historyPage = new HistoryPage();
private readonly SearchPage _searchPage = new SearchPage();
public MainWindow() public MainWindow()
{ {
@ -39,14 +42,12 @@ public partial class MainWindow : Window
} }
else if (args.SelectedItem is NavigationViewItem item) else if (args.SelectedItem is NavigationViewItem item)
{ {
switch (item.Tag) NavView.Content = item.Tag switch
{ {
case "History": "History" => _historyPage,
break; "Search" => _searchPage,
case "Search": _ => NavView.Content
NavView.Content = _historyPage; };
break;
}
} }
} }
@ -65,10 +66,14 @@ public partial class MainWindow : Window
if (dialogContent.DataContext is CheckNumberViewModel vm) if (dialogContent.DataContext is CheckNumberViewModel vm)
{ {
vm.AutoCloseEvent += (_, _) => vm.AutoCloseEvent += async (_, _) =>
{ {
dialog.Hide(); 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;
}
}; };
} }