Removed dialogs for editing equipment and points, and their related resources
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Utils;
|
||||
|
||||
@@ -9,6 +13,7 @@ namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class EquipmentViewModel : ViewModelBase
|
||||
{
|
||||
public ViewModelBase? Parent { get; set; }
|
||||
private Equipment Equipment { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -17,31 +22,72 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string? _description;
|
||||
|
||||
public ObservableCollection<ImageViewModel> Images { get; init; } = [];
|
||||
|
||||
public ObservableCollection<PropertyViewModel> Properties { get; }
|
||||
[ObservableProperty]
|
||||
private DateTime _creationDate;
|
||||
|
||||
public ObservableCollection<InspectionViewModel> Inspections { get; }
|
||||
public ObservableCollection<ImageViewModel> Images { get; set; } = [];
|
||||
|
||||
public ObservableCollection<PropertyViewModel> Properties { get; set; }
|
||||
|
||||
public ObservableCollection<InspectionViewModel> Inspections { get; set; }
|
||||
|
||||
public ObservableCollection<EquipmentViewModel> Equipments { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
private string _nearestInspection;
|
||||
|
||||
[RelayCommand]
|
||||
private void AddEquipment()
|
||||
{
|
||||
Equipments.Add(new EquipmentViewModel{ Name = "Новое оборудование", Description = "Описание оборудования", Parent = this});
|
||||
CallSavePoint(this);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveEquipment()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new RemoveEquipmentMessage(this));
|
||||
}
|
||||
|
||||
private void RemoveEquipment(object sender, RemoveEquipmentMessage msg)
|
||||
{
|
||||
if (Equipments.Contains(msg.Equipment))
|
||||
Equipments.Remove(msg.Equipment);
|
||||
CallSavePoint(this);
|
||||
}
|
||||
|
||||
private void CallSavePoint(EquipmentViewModel equipment)
|
||||
{
|
||||
var current = equipment;
|
||||
while (current.Parent is EquipmentViewModel model)
|
||||
current = model ?? throw new InvalidOperationException("Parent equipment not found in hierarchy");
|
||||
|
||||
if (current.Parent is PointViewModel pointViewModel)
|
||||
WeakReferenceMessenger.Default.Send(new EditPointMessage(pointViewModel));
|
||||
}
|
||||
|
||||
public EquipmentViewModel()
|
||||
{
|
||||
Name = string.Empty;
|
||||
Description = string.Empty;
|
||||
CreationDate = DateTime.Now;
|
||||
Properties = [];
|
||||
Inspections = [];
|
||||
Equipments = [];
|
||||
NearestInspection = "Нету инспекций";
|
||||
Equipment = new Equipment();
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemoveEquipmentMessage>(this, RemoveEquipment);
|
||||
}
|
||||
|
||||
public EquipmentViewModel(Equipment equipment)
|
||||
{
|
||||
Name = equipment.Name;
|
||||
Description = equipment.Description;
|
||||
CreationDate = equipment.CreationDate;
|
||||
Images = new ObservableCollection<ImageViewModel>(equipment.Images.Select(i => new ImageViewModel(i)));
|
||||
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => new PropertyViewModel(e)));
|
||||
Equipments = new ObservableCollection<EquipmentViewModel>(equipment.Equipments.Select(e => new EquipmentViewModel(e){Parent = this}));
|
||||
|
||||
var times = equipment.Inspections.Select(e => new InspectionViewModel(e))
|
||||
.Select(e => e.GetNearestDates())
|
||||
@@ -59,14 +105,20 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
|
||||
if (Inspections.Count == 0) NearestInspection = "Нету инспекций";
|
||||
Equipment = equipment;
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemoveEquipmentMessage>(this, RemoveEquipment);
|
||||
}
|
||||
|
||||
public Equipment GetEquipment()
|
||||
{
|
||||
Equipment.Name = Name;
|
||||
Equipment.Description = Description;
|
||||
Equipment.CreationDate = CreationDate;
|
||||
Equipment.Images = Images.Select(e => e.GetImage()).ToList();
|
||||
Equipment.Inspections = Inspections.Select(e => e.GetInspection()).ToList();
|
||||
Equipment.Properties = Properties.Select(e => e.GetProperty()).ToList();
|
||||
Equipment.Equipments = Equipments.Select(e => e.GetEquipment()).ToList();
|
||||
|
||||
return Equipment;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user