Properties added

This commit is contained in:
retr0volkov
2025-07-09 14:27:45 +03:00 Unverified
parent 72dc9b6874
commit 2a8f8d2714
10 changed files with 272 additions and 22 deletions
+41 -5
View File
@@ -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<PropertyViewModel> Properties { get; set; } = [];
public ObservableCollection<PropertyViewModel> 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<PropertyViewModel>(
property.Properties.Select(e => new PropertyViewModel(e, this)));
Parent = property.Parent is null ? null : parent;
}
public PropertyViewModel(PropertyViewModel property)
{
Name = "Имя свойства";
Value = "Значение свойства";
Properties = [];
Parent = property;
}
}
+24 -2
View File
@@ -115,6 +115,26 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
{
Inspections.Remove(inspection);
}
public ObservableCollection<PropertyViewModel> 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<InspectionViewModel>(equipment.Inspections.Select(e => e));
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => e));
IsImageSelected = equipment.Image is { Bytes.Length: > 0 };
+77 -5
View File
@@ -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<EquipmentViewModel> Equipment { get; set; }
@@ -122,6 +119,26 @@ public partial class EditPointDialogViewModel : ViewModelBase
IsEquipmentEmpty = Equipment.Count == 0;
}
public ObservableCollection<PropertyViewModel> 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<ImageViewModel>((point.Images ?? []).Select(e => new ImageViewModel(e)));
Equipment = new ObservableCollection<EquipmentViewModel>((point.Equipment ?? []).Select(e => new EquipmentViewModel(e)));
Properties = new ObservableCollection<PropertyViewModel>((point.Properties ?? []).Select(e => new PropertyViewModel(e)));
IsImagesEmpty = Images.Count == 0;
IsEquipmentEmpty = Equipment.Count == 0;