From 2a8f8d2714fbf16f8b576c0df1cc1439e63924d0 Mon Sep 17 00:00:00 2001 From: retr0volkov <68907954+retr0volkov@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:27:45 +0300 Subject: [PATCH] Properties added --- Models/Property.cs | 3 + Utils/AppDbContext.cs | 5 ++ ViewModels/Basic/PropertyViewModel.cs | 46 ++++++++-- ViewModels/EditEquipmentDialogViewModel.cs | 26 +++++- ViewModels/EditPointDialogViewModel.cs | 82 ++++++++++++++++-- Views/EditEquipmentDialog.axaml | 59 ++++++++++++- Views/EditPointDialog.axaml | 69 ++++++++++++++- obj/Debug/net8.0/Avalonia/resources | Bin 335944 -> 343059 bytes obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs | 2 +- .../GazpromApp.AssemblyInfoInputs.cache | 2 +- 10 files changed, 272 insertions(+), 22 deletions(-) diff --git a/Models/Property.cs b/Models/Property.cs index 250a8fe..75388fc 100644 --- a/Models/Property.cs +++ b/Models/Property.cs @@ -12,6 +12,9 @@ public class Property [Required] public string Name { get; set; } = string.Empty; public string Value { get; set; } = string.Empty; + // EF stuff + public Property? Parent { get; set; } + public List Properties{ get; set; } = []; public List Points { get; set; } = []; public List Equipment { get; } = []; } \ No newline at end of file diff --git a/Utils/AppDbContext.cs b/Utils/AppDbContext.cs index 0431016..2592521 100644 --- a/Utils/AppDbContext.cs +++ b/Utils/AppDbContext.cs @@ -38,6 +38,11 @@ public class AppDbContext : DbContext .HasMany(e => e.Properties) .WithMany(e => e.Equipment); + modelBuilder.Entity() + .HasMany(e => e.Properties) + .WithOne(e => e.Parent) + .HasForeignKey(e => e.ParentId); + // Equipment modelBuilder.Entity() .HasOne(e => e.Point) diff --git a/ViewModels/Basic/PropertyViewModel.cs b/ViewModels/Basic/PropertyViewModel.cs index 8e96156..512658a 100644 --- a/ViewModels/Basic/PropertyViewModel.cs +++ b/ViewModels/Basic/PropertyViewModel.cs @@ -1,9 +1,12 @@ using System.Collections.ObjectModel; +using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using GazpromApp.Models; namespace GazpromApp.ViewModels; + public partial class PropertyViewModel : ViewModelBase { [ObservableProperty] @@ -12,17 +15,50 @@ public partial class PropertyViewModel : ViewModelBase [ObservableProperty] private string _value; - public ObservableCollection Properties { get; set; } = []; + public ObservableCollection Properties { get; set; } + + // Visual and other properties + + public PropertyViewModel? Parent { get; set; } + + [ObservableProperty] + private bool _isEditing; - public PropertyViewModel() + public Property GetProperty(Property? parent = null) { - Name = string.Empty; - Value = string.Empty; + Property p = new Property + { + Name = Name, + Value = Value, + Properties = [], + Parent = parent + }; + p.Properties = Properties.Select(e => e.GetProperty(p)).ToList(); + return p; } - public PropertyViewModel(Property property) + public PropertyViewModel() + { + Name = "Имя свойства"; + Value = "Значение свойства"; + Properties = []; + Parent = null; + } + + public PropertyViewModel(Property property, PropertyViewModel? parent = null) { Name = property.Name; Value = property.Value; + Properties = new ObservableCollection( + property.Properties.Select(e => new PropertyViewModel(e, this))); + Parent = property.Parent is null ? null : parent; + } + + public PropertyViewModel(PropertyViewModel property) + { + Name = "Имя свойства"; + Value = "Значение свойства"; + Properties = []; + Parent = property; } } \ No newline at end of file diff --git a/ViewModels/EditEquipmentDialogViewModel.cs b/ViewModels/EditEquipmentDialogViewModel.cs index 0429709..35f9c94 100644 --- a/ViewModels/EditEquipmentDialogViewModel.cs +++ b/ViewModels/EditEquipmentDialogViewModel.cs @@ -115,6 +115,26 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase { Inspections.Remove(inspection); } + + public ObservableCollection Properties { get; set; } + + [RelayCommand] + private void AddPropertySimple() => Properties.Add(new PropertyViewModel()); + + [RelayCommand] + private static void AddProperty(PropertyViewModel property) => property.Properties.Add(new PropertyViewModel(property)); + + [RelayCommand] + private static void EditProperty(PropertyViewModel property) => property.IsEditing = !property.IsEditing; + + [RelayCommand] + private void DeleteProperty(PropertyViewModel property) + { + if (property.Parent is null) + Properties.Remove(property); + else + property.Parent?.Properties.Remove(property); + } private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name); @@ -122,13 +142,13 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase private void CompleteEdit() { IsClosed = true; - Equipment equipment = new Equipment() + Equipment equipment = new Equipment { Name = Name, Description = Description, Image = Image?.GetImage(), Inspections = Inspections.Select(e => e.GetInspection()).ToList(), - Properties = [], + Properties = Properties.Select(e => e.GetProperty()).ToList(), }; WeakReferenceMessenger.Default.Send(new EditEquipmentDone(new EquipmentViewModel(equipment))); } @@ -160,6 +180,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase Description = "Testing"; Image = null; Inspections = []; + Properties = []; IsImageSelected = false; @@ -172,6 +193,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase Description = equipment.Description; Image = equipment.Image; Inspections = new ObservableCollection(equipment.Inspections.Select(e => e)); + Properties = new ObservableCollection(equipment.Properties.Select(e => e)); IsImageSelected = equipment.Image is { Bytes.Length: > 0 }; diff --git a/ViewModels/EditPointDialogViewModel.cs b/ViewModels/EditPointDialogViewModel.cs index 07c847a..28b8b19 100644 --- a/ViewModels/EditPointDialogViewModel.cs +++ b/ViewModels/EditPointDialogViewModel.cs @@ -89,10 +89,7 @@ public partial class EditPointDialogViewModel : ViewModelBase } [RelayCommand] - private static async Task ViewImage(ImageViewModel image) - { - _ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(image)); - } + private static async Task ViewImage(ImageViewModel image) => _ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(image)); public ObservableCollection Equipment { get; set; } @@ -122,6 +119,26 @@ public partial class EditPointDialogViewModel : ViewModelBase IsEquipmentEmpty = Equipment.Count == 0; } + public ObservableCollection Properties { get; set; } + + [RelayCommand] + private void AddPropertySimple() => Properties.Add(new PropertyViewModel()); + + [RelayCommand] + private static void AddProperty(PropertyViewModel property) => property.Properties.Add(new PropertyViewModel(property)); + + [RelayCommand] + private static void EditProperty(PropertyViewModel property) => property.IsEditing = !property.IsEditing; + + [RelayCommand] + private void DeleteProperty(PropertyViewModel property) + { + if (property.Parent is null) + Properties.Remove(property); + else + property.Parent?.Properties.Remove(property); + } + private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name); [RelayCommand(CanExecute = nameof(CanCompleteEdit))] @@ -133,7 +150,8 @@ public partial class EditPointDialogViewModel : ViewModelBase Name = Name, Description = Description, Images = Images.Select(e => e.GetImage()).ToList(), - Equipment = Equipment.Select(e => e.GetEquipment()).ToList() + Equipment = Equipment.Select(e => e.GetEquipment()).ToList(), + Properties = Properties.Select(e => e.GetProperty()).ToList(), }; WeakReferenceMessenger.Default.Send(new EditPointDone(new PointViewModel(point))); } @@ -175,6 +193,59 @@ public partial class EditPointDialogViewModel : ViewModelBase Description = "Really big description for the equipment to show the long textReally big description for the equipment to show the long textReally big description for the equipment to show the long textReally big description for the equipment to show the long text", Image = null } ]; + Properties = [ + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [ + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [ + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [], + Parent = null + }, + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [], + Parent = null + }, + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [], + Parent = null + } + ], + Parent = null + }, + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [], + Parent = null + }, + ], + Parent = null + }, + new PropertyViewModel + { + Name = "Property Name", + Value = "Property Value", + Properties = [], + Parent = null + } + ]; IsImagesEmpty = true; IsEquipmentEmpty = true; @@ -188,6 +259,7 @@ public partial class EditPointDialogViewModel : ViewModelBase Description = point.Description; Images = new ObservableCollection((point.Images ?? []).Select(e => new ImageViewModel(e))); Equipment = new ObservableCollection((point.Equipment ?? []).Select(e => new EquipmentViewModel(e))); + Properties = new ObservableCollection((point.Properties ?? []).Select(e => new PropertyViewModel(e))); IsImagesEmpty = Images.Count == 0; IsEquipmentEmpty = Equipment.Count == 0; diff --git a/Views/EditEquipmentDialog.axaml b/Views/EditEquipmentDialog.axaml index de4613f..1e3b669 100644 --- a/Views/EditEquipmentDialog.axaml +++ b/Views/EditEquipmentDialog.axaml @@ -18,6 +18,7 @@ + @@ -47,7 +48,7 @@ - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/Views/EditPointDialog.axaml b/Views/EditPointDialog.axaml index 64d406f..95bbe5f 100644 --- a/Views/EditPointDialog.axaml +++ b/Views/EditPointDialog.axaml @@ -16,6 +16,20 @@ + + + + + + + + + + + + + + - + - @@ -142,7 +157,53 @@ - + + + + + + + + + + + + + + + + + + diff --git a/obj/Debug/net8.0/Avalonia/resources b/obj/Debug/net8.0/Avalonia/resources index 7f670f5ebc19104630f35b335983ba5b6aaace57..eb94c829776dc7ad5bb9491568539b02c1b85227 100644 GIT binary patch delta 1944 zcmeHGU2GIp813wy*$%UAyRy4on{K<)nh+@6b~lItETt6)2pCE!KTpuXxuKivPrKc! zX#7buG3pCu)K7yJ3=d7|Vt*o?2V%02W+82WhE$3?5FU*@v?``3CU|e_HlQ}~g+vo? za_`)^`R=*rJKuLMX1(TJ@8FF>xw*EWAVBVNIp7%m8U-T}Q&LK8uS}Z(rQFsxYd)h? z$W`}HkTee{Puf2ymd&@7O51k zQkoI%(htR$mQ1|BwEcQKR@=gi?u4Ny(k-kj*`4CYp-_WM)%d8V>CX|c)_jI>nc7Na zm41_Cr?owccO}|xmsKls5|c~)nzk=$q}$h5tqNCZTUqpQds^&i=oI|amO~*O9Y--` zMzEUdPGT(;SvXDKe~YJ<)VHP>+Z$ys(at^|9GHYkoqh0@1n-{#XDkpnsrg< zDR|_$OEh!`{=lm*uWLQh!L%3S>zY$Zo?-fkKzlxEuoy)$SVr0NC|SVuP~#|nVdqtN z+>zDcn(CUS?sRf~q0XxaP~9w?biW5~ni#-x3iqOjnsfZO`4Y-#Wd$UZY)SP%3UY1nN?HHiwD@%!h;K z@Z*#4mnm@4U4T;br&9hExB9WoMl}5(@(P}r|N*Ck-{!DZwc;9_u!LE>rqC^!uDA8?~LzJfz}kQ}35u45CmP2p() zS5AXIxeTJq=!Yo;>;Asq{xE_tgBbM-VbnB&4T}}wp}sHji%vy66pGcPXHgubHtOtd%HF*wiI_dRc_^i{HuuY%%K}PyOF)kJfBz4$GWPkHBpL w_}}U_!R^1~HjBG${S$W0rIOnt2c6Y5k#M+b&gUPUkSl5YN5rj}pRm8?chBy+!~g&Q delta 320 zcmYj{&nts*9LJyM+52l>%VVb5=o#CyUF1iba$A;zla|DRQoB(Ov=x5=Q9G$`d@dH{ z;2^b=FNc*9)>33He(XmnqC~01VX>SXUiGTiOME%A$IkSfRdbo*!RoC`rlG9+h05DB zZ(ewKyEbw!!n}i>7oq%!7!TB+eL|Vg6~&-bm>F8TDt5W4Jvo+gd^N|_8d?pD%yEnf zIk|~vCi9orQe|NW#b(NEqmjx-;Ix*3l|BwIM5%t(OIPpcrg#P8wEu#j+^e9~BK0h) zs+_;TauW@{!Oatkv+=p<`2|Yc!r0hDJ;ko!lGXx-ReE$WH&u%mMRahKKZQk}d}E-6I_*qQ$zWc3axkN=%O8yBHYz)q`QL4Qq0nFP`6%jP K0eNU=Q$4?Q&v6$3 diff --git a/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs b/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs index d1d9aa8..9cbb48f 100644 --- a/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs +++ b/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+646f60e800da077d6f0e380695010dafc74187f1")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+72dc9b68743bc32f202a106f6161f2a4c5401a0c")] [assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache b/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache index f206f62..6ffceae 100644 --- a/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache @@ -1 +1 @@ -d96ce4087b396be689d2265a12a73a6073c44823fe98e991f0bc173e827a4fb3 +15ad954b97553ac87ab7a0c39a3000dca500a7ad2febeb4c503529c5bb6ac55b