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 7f670f5..eb94c82 100644 Binary files a/obj/Debug/net8.0/Avalonia/resources and b/obj/Debug/net8.0/Avalonia/resources differ 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