From 6d85cf53c953d129f5aac1a4d605db4ebc6e689e Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sun, 29 Oct 2023 22:14:54 +0300 Subject: [PATCH] Adding NavigationView --- AutoCat/App.axaml | 8 ++-- AutoCat/App.axaml.cs | 5 +- AutoCat/AutoCat.csproj | 1 + AutoCat/Mocks/HistoryListViewModelMock.cs | 30 ++++++++++++ AutoCat/Pages/HistoryListPage.axaml | 32 +++++++++++++ AutoCat/Pages/HistoryListPage.axaml.cs | 13 ++++++ AutoCat/Pages/HistoryPage.axaml | 13 ++++++ AutoCat/Pages/HistoryPage.axaml.cs | 13 ++++++ AutoCat/Pages/ReportPage.axaml | 8 ++++ AutoCat/Pages/ReportPage.axaml.cs | 13 ++++++ AutoCat/Pages/SettingsPage.axaml | 8 ++++ AutoCat/Pages/SettingsPage.axaml.cs | 13 ++++++ AutoCat/ViewLocator.cs | 27 ----------- AutoCat/ViewModels/HistoryListViewModel.cs | 46 +++++++++++++++++++ AutoCat/Views/MainWindow.axaml.cs | 11 ----- AutoCat/{Views => Windows}/AuthWindow.axaml | 2 +- .../{Views => Windows}/AuthWindow.axaml.cs | 2 +- AutoCat/{Views => Windows}/MainWindow.axaml | 19 ++++++-- AutoCat/Windows/MainWindow.axaml.cs | 33 +++++++++++++ AutoCatCore/Services/Api/ApiService.cs | 4 +- .../Services/Storage/IStorageService.cs | 2 + .../Services/Storage/StorageService.cs | 2 + 22 files changed, 255 insertions(+), 50 deletions(-) create mode 100644 AutoCat/Mocks/HistoryListViewModelMock.cs create mode 100644 AutoCat/Pages/HistoryListPage.axaml create mode 100644 AutoCat/Pages/HistoryListPage.axaml.cs create mode 100644 AutoCat/Pages/HistoryPage.axaml create mode 100644 AutoCat/Pages/HistoryPage.axaml.cs create mode 100644 AutoCat/Pages/ReportPage.axaml create mode 100644 AutoCat/Pages/ReportPage.axaml.cs create mode 100644 AutoCat/Pages/SettingsPage.axaml create mode 100644 AutoCat/Pages/SettingsPage.axaml.cs delete mode 100644 AutoCat/ViewLocator.cs create mode 100644 AutoCat/ViewModels/HistoryListViewModel.cs delete mode 100644 AutoCat/Views/MainWindow.axaml.cs rename AutoCat/{Views => Windows}/AuthWindow.axaml (97%) rename AutoCat/{Views => Windows}/AuthWindow.axaml.cs (96%) rename AutoCat/{Views => Windows}/MainWindow.axaml (51%) create mode 100644 AutoCat/Windows/MainWindow.axaml.cs diff --git a/AutoCat/App.axaml b/AutoCat/App.axaml index 4527556..1c01ea2 100644 --- a/AutoCat/App.axaml +++ b/AutoCat/App.axaml @@ -1,14 +1,14 @@ - - - - + + \ No newline at end of file diff --git a/AutoCat/App.axaml.cs b/AutoCat/App.axaml.cs index 7b79f40..f2aaf53 100644 --- a/AutoCat/App.axaml.cs +++ b/AutoCat/App.axaml.cs @@ -3,7 +3,7 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using AutoCat.ViewModels; -using AutoCat.Views; +using AutoCat.Windows; using AutoCatCore.Services.Api; using AutoCatCore.Services.Storage; using Microsoft.Extensions.DependencyInjection; @@ -18,10 +18,11 @@ public partial class App : Application private static void RegisterDependencies(HostBuilderContext context, IServiceCollection services) { // Services - services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); // ViewModels + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AutoCat/AutoCat.csproj b/AutoCat/AutoCat.csproj index edb0bb6..162b6dc 100644 --- a/AutoCat/AutoCat.csproj +++ b/AutoCat/AutoCat.csproj @@ -23,6 +23,7 @@ + diff --git a/AutoCat/Mocks/HistoryListViewModelMock.cs b/AutoCat/Mocks/HistoryListViewModelMock.cs new file mode 100644 index 0000000..26e1715 --- /dev/null +++ b/AutoCat/Mocks/HistoryListViewModelMock.cs @@ -0,0 +1,30 @@ +using System.Collections.ObjectModel; +using AutoCat.ViewModels; +using AutoCatCore.Model; + +namespace AutoCat.Mocks; + +public class HistoryListViewModelMock: ViewModelBase +{ + public ObservableCollection Vehicles { get; set; } + + public HistoryListViewModelMock() + { + var vehicle1 = new Vehicle + { + Number = "А007АА761" + }; + + var vehicle2 = new Vehicle + { + Number = "А008АА761" + }; + + var vehicle3 = new Vehicle + { + Number = "А009АА761" + }; + + Vehicles = new ObservableCollection { vehicle1, vehicle2, vehicle3 }; + } +} \ No newline at end of file diff --git a/AutoCat/Pages/HistoryListPage.axaml b/AutoCat/Pages/HistoryListPage.axaml new file mode 100644 index 0000000..f161a09 --- /dev/null +++ b/AutoCat/Pages/HistoryListPage.axaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/AutoCat/Pages/HistoryListPage.axaml.cs b/AutoCat/Pages/HistoryListPage.axaml.cs new file mode 100644 index 0000000..a7f8472 --- /dev/null +++ b/AutoCat/Pages/HistoryListPage.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace AutoCat.Pages; + +public partial class HistoryListPage : UserControl +{ + public HistoryListPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/AutoCat/Pages/HistoryPage.axaml b/AutoCat/Pages/HistoryPage.axaml new file mode 100644 index 0000000..0ff9a7f --- /dev/null +++ b/AutoCat/Pages/HistoryPage.axaml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/AutoCat/Pages/HistoryPage.axaml.cs b/AutoCat/Pages/HistoryPage.axaml.cs new file mode 100644 index 0000000..4a53307 --- /dev/null +++ b/AutoCat/Pages/HistoryPage.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace AutoCat.Pages; + +public partial class HistoryPage : UserControl +{ + public HistoryPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/AutoCat/Pages/ReportPage.axaml b/AutoCat/Pages/ReportPage.axaml new file mode 100644 index 0000000..60139d8 --- /dev/null +++ b/AutoCat/Pages/ReportPage.axaml @@ -0,0 +1,8 @@ + + Welcome to Avalonia! + diff --git a/AutoCat/Pages/ReportPage.axaml.cs b/AutoCat/Pages/ReportPage.axaml.cs new file mode 100644 index 0000000..27b93cd --- /dev/null +++ b/AutoCat/Pages/ReportPage.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace AutoCat.Pages; + +public partial class ReportPage : UserControl +{ + public ReportPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/AutoCat/Pages/SettingsPage.axaml b/AutoCat/Pages/SettingsPage.axaml new file mode 100644 index 0000000..1ee4137 --- /dev/null +++ b/AutoCat/Pages/SettingsPage.axaml @@ -0,0 +1,8 @@ + + Settings Page + diff --git a/AutoCat/Pages/SettingsPage.axaml.cs b/AutoCat/Pages/SettingsPage.axaml.cs new file mode 100644 index 0000000..3ed72a8 --- /dev/null +++ b/AutoCat/Pages/SettingsPage.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace AutoCat.Pages; + +public partial class SettingsPage : UserControl +{ + public SettingsPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/AutoCat/ViewLocator.cs b/AutoCat/ViewLocator.cs deleted file mode 100644 index 0ffcdd0..0000000 --- a/AutoCat/ViewLocator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Avalonia.Controls; -using Avalonia.Controls.Templates; -using AutoCat.ViewModels; - -namespace AutoCat; - -public class ViewLocator : IDataTemplate -{ - public Control Build(object data) - { - var name = data.GetType().FullName!.Replace("ViewModel", "View"); - var type = Type.GetType(name); - - if (type != null) - { - return (Control)Activator.CreateInstance(type)!; - } - - return new TextBlock { Text = "Not Found: " + name }; - } - - public bool Match(object data) - { - return data is ViewModelBase; - } -} \ No newline at end of file diff --git a/AutoCat/ViewModels/HistoryListViewModel.cs b/AutoCat/ViewModels/HistoryListViewModel.cs new file mode 100644 index 0000000..e94aa95 --- /dev/null +++ b/AutoCat/ViewModels/HistoryListViewModel.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using AutoCatCore.Model; +using AutoCatCore.Services.Api; +using DynamicData; + +namespace AutoCat.ViewModels; + +public class HistoryListViewModel: ViewModelBase +{ + #region Dependencies + + private readonly IApiService _apiService; + + #endregion + + #region Properties + + public ObservableCollection Vehicles { get; set; } + + #endregion + + public HistoryListViewModel(IApiService apiService) + { + _apiService = apiService; + Vehicles = new ObservableCollection(); + LoadVehicles(); + } + + private async Task LoadVehicles() + { + try + { + var pagedResponse = await _apiService.GetVehicles(); + Vehicles.Clear(); + Vehicles.AddRange(pagedResponse.Items); + + Console.WriteLine($"Loaded vehicles: {Vehicles.Count}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/AutoCat/Views/MainWindow.axaml.cs b/AutoCat/Views/MainWindow.axaml.cs deleted file mode 100644 index bd3355f..0000000 --- a/AutoCat/Views/MainWindow.axaml.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Avalonia.Controls; - -namespace AutoCat.Views; - -public partial class MainWindow : Window -{ - public MainWindow() - { - InitializeComponent(); - } -} \ No newline at end of file diff --git a/AutoCat/Views/AuthWindow.axaml b/AutoCat/Windows/AuthWindow.axaml similarity index 97% rename from AutoCat/Views/AuthWindow.axaml rename to AutoCat/Windows/AuthWindow.axaml index 0670b33..4e6ad7d 100644 --- a/AutoCat/Views/AuthWindow.axaml +++ b/AutoCat/Windows/AuthWindow.axaml @@ -7,7 +7,7 @@ xmlns:mocks="using:AutoCat.Mocks" xmlns:ext="using:AutoCat.Extensions" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="AutoCat.Views.AuthWindow" + x:Class="AutoCat.Windows.AuthWindow" x:DataType="vm:AuthWindowViewModel" Title="AuthWindow" Width="800" Height="600" diff --git a/AutoCat/Views/AuthWindow.axaml.cs b/AutoCat/Windows/AuthWindow.axaml.cs similarity index 96% rename from AutoCat/Views/AuthWindow.axaml.cs rename to AutoCat/Windows/AuthWindow.axaml.cs index 6dfeb1a..1e3444b 100644 --- a/AutoCat/Views/AuthWindow.axaml.cs +++ b/AutoCat/Windows/AuthWindow.axaml.cs @@ -5,7 +5,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting.Internal; -namespace AutoCat.Views; +namespace AutoCat.Windows; public partial class AuthWindow : Window { diff --git a/AutoCat/Views/MainWindow.axaml b/AutoCat/Windows/MainWindow.axaml similarity index 51% rename from AutoCat/Views/MainWindow.axaml rename to AutoCat/Windows/MainWindow.axaml index 6550d18..6f07e6a 100644 --- a/AutoCat/Views/MainWindow.axaml +++ b/AutoCat/Windows/MainWindow.axaml @@ -3,13 +3,17 @@ xmlns:vm="using:AutoCat.ViewModels" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:utils="using:AutoCat.Utils" + xmlns:ui="using:FluentAvalonia.UI.Controls" + xmlns:uip="using:FluentAvalonia.UI.Controls.Primitives" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" Width="800" Height="600" - x:Class="AutoCat.Views.MainWindow" + x:Class="AutoCat.Windows.MainWindow" x:DataType="vm:MainWindowViewModel" Icon="/Assets/avalonia-logo.ico" - Title="AutoCat"> + Title="AutoCat" + DataContext="{utils:ViewModelProvider vm:MainWindowViewModel}">