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;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,49 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class ImageViewModel : ViewModelBase
|
||||
{
|
||||
public ViewModelBase? Parent;
|
||||
private Image Image { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private byte[]? _bytes;
|
||||
|
||||
|
||||
[ObservableProperty] private byte[]? _bytes;
|
||||
|
||||
[ObservableProperty] private DateTime _creationDate;
|
||||
|
||||
// EF stuff
|
||||
|
||||
[ObservableProperty]
|
||||
private Point? _point;
|
||||
|
||||
[ObservableProperty]
|
||||
private Equipment? _equipment;
|
||||
|
||||
[ObservableProperty]
|
||||
private Bitmap? _fileName;
|
||||
|
||||
[ObservableProperty] private Point? _point;
|
||||
|
||||
[ObservableProperty] private Equipment? _equipment;
|
||||
|
||||
[ObservableProperty] private Bitmap? _fileName;
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ViewImage() => _ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(this));
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteImage() => _ = Parent switch
|
||||
{
|
||||
PointViewModel pmv => pmv.Images.Remove(this),
|
||||
EquipmentViewModel emv => emv.Images.Remove(this),
|
||||
EditPointViewModel editPointViewModel => editPointViewModel.Images.Remove(this),
|
||||
EditEquipmentViewModel editEquipmentViewModel => editEquipmentViewModel.Images.Remove(this),
|
||||
_ => false
|
||||
};
|
||||
|
||||
public ImageViewModel(Image image)
|
||||
{
|
||||
Bytes = image.Bytes;
|
||||
CreationDate = image.CreationDate;
|
||||
Equipment = image.Equipment;
|
||||
Point = image.Point;
|
||||
FileName = image.Bytes is { Length: > 0 } ? new Bitmap(new MemoryStream(image.Bytes)) : null;
|
||||
@@ -35,6 +53,7 @@ public partial class ImageViewModel : ViewModelBase
|
||||
public ImageViewModel()
|
||||
{
|
||||
Bytes = null;
|
||||
CreationDate = DateTime.Now;
|
||||
Equipment = null;
|
||||
Point = null;
|
||||
Image = new Image();
|
||||
@@ -45,6 +64,7 @@ public partial class ImageViewModel : ViewModelBase
|
||||
var ms = new MemoryStream();
|
||||
FileName?.Save(ms);
|
||||
Image.Bytes = ms.ToArray();
|
||||
Image.CreationDate = CreationDate;
|
||||
Image.Equipment = Equipment;
|
||||
Image.Point = Point;
|
||||
return Image;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -11,6 +15,8 @@ public partial class InspectionViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _name;
|
||||
[ObservableProperty]
|
||||
private DateTime _creationDate;
|
||||
[ObservableProperty]
|
||||
private DateTimeOffset _inspectionDate;
|
||||
[ObservableProperty]
|
||||
private PeriodType _periodType;
|
||||
@@ -21,10 +27,25 @@ public partial class InspectionViewModel : ViewModelBase
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isEditing;
|
||||
|
||||
[RelayCommand]
|
||||
private void EditInspection()
|
||||
{
|
||||
IsEditing = !IsEditing;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveInspection() => WeakReferenceMessenger.Default.Send(new RemoveInspectionMessage(this));
|
||||
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Global
|
||||
public PeriodType[] AllPeriods => Enum.GetValues<PeriodType>()
|
||||
.Where(p => p != PeriodType.Unknown)
|
||||
.ToArray();
|
||||
|
||||
public InspectionViewModel()
|
||||
{
|
||||
Name = string.Empty;
|
||||
CreationDate = DateTime.Now;
|
||||
InspectionDate = DateTimeOffset.Now;
|
||||
PeriodType = 0;
|
||||
PeriodValue = 1;
|
||||
@@ -34,6 +55,7 @@ public partial class InspectionViewModel : ViewModelBase
|
||||
public InspectionViewModel(Inspection inspection)
|
||||
{
|
||||
Name = inspection.Name;
|
||||
CreationDate = inspection.CreationDate;
|
||||
InspectionDate = inspection.InspectionDate;
|
||||
PeriodType = inspection.PeriodType.ToPeriodType();
|
||||
PeriodValue = inspection.PeriodValue;
|
||||
@@ -43,6 +65,7 @@ public partial class InspectionViewModel : ViewModelBase
|
||||
public Inspection GetInspection()
|
||||
{
|
||||
Inspection.Name = Name;
|
||||
Inspection.CreationDate = CreationDate;
|
||||
Inspection.InspectionDate = InspectionDate;
|
||||
Inspection.PeriodType = PeriodType.ToDescription();
|
||||
Inspection.PeriodValue = PeriodValue;
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -14,39 +21,64 @@ public partial class PointViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string? _description;
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTime _creationDate;
|
||||
|
||||
[ObservableProperty]
|
||||
private double? _latitude;
|
||||
|
||||
[ObservableProperty]
|
||||
private double? _longitude;
|
||||
|
||||
[RelayCommand]
|
||||
private void AddEquipment()
|
||||
{
|
||||
Equipment.Add(new EquipmentViewModel(new Equipment()) {Name = "Новое оборудование", Description = "Описание оборудования", Parent = this});
|
||||
WeakReferenceMessenger.Default.Send(new EditPointMessage(this));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemovePoint()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new RemovePointMessage(this));
|
||||
}
|
||||
|
||||
private void RemoveEquipment(object sender, RemoveEquipmentMessage msg)
|
||||
{
|
||||
if (msg.Equipment.GetEquipment().Point == GetPoint())
|
||||
Equipment.Remove(msg.Equipment);
|
||||
}
|
||||
|
||||
// EF stuff
|
||||
[ObservableProperty]
|
||||
private List<Image> _images;
|
||||
private ObservableCollection<ImageViewModel> _images;
|
||||
[ObservableProperty]
|
||||
private List<Equipment> _equipment;
|
||||
private ObservableCollection<EquipmentViewModel> _equipment;
|
||||
[ObservableProperty]
|
||||
private List<Property> _properties;
|
||||
private ObservableCollection<PropertyViewModel> _properties;
|
||||
|
||||
public PointViewModel(Point point)
|
||||
{
|
||||
Point = point;
|
||||
Name = point.Name;
|
||||
CreationDate = point.CreationDate;
|
||||
Description = point.Description;
|
||||
Latitude = point.Latitude;
|
||||
Longitude = point.Longitude;
|
||||
Images = point.Images;
|
||||
Equipment = point.Equipment;
|
||||
Properties = point.Properties;
|
||||
Images = new ObservableCollection<ImageViewModel>(point.Images.Select(i => new ImageViewModel(i)));
|
||||
Equipment = new ObservableCollection<EquipmentViewModel>(point.Equipment.Select(i => new EquipmentViewModel(i){Parent = this}));
|
||||
Properties = new ObservableCollection<PropertyViewModel>(point.Properties.Select(i => new PropertyViewModel(i)));
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemoveEquipmentMessage>(this, RemoveEquipment);
|
||||
}
|
||||
|
||||
public Point GetPoint()
|
||||
{
|
||||
Point.Name = Name;
|
||||
Point.Description = Description;
|
||||
Point.Equipment = Equipment;
|
||||
Point.Images = Images;
|
||||
Point.Properties = Properties;
|
||||
Point.CreationDate = CreationDate;
|
||||
Point.Equipment = Equipment.Select(e => e.GetEquipment()).ToList();
|
||||
Point.Images = Images.Select(i => i.GetImage()).ToList();
|
||||
Point.Properties = Properties.Select(p => p.GetProperty()).ToList();
|
||||
return Point;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -8,6 +12,8 @@ namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class PropertyViewModel : ViewModelBase
|
||||
{
|
||||
public ViewModelBase? Parent { get; init; }
|
||||
|
||||
private Property Property { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -16,19 +22,36 @@ public partial class PropertyViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _value;
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTime _creationDate;
|
||||
|
||||
public ObservableCollection<PropertyViewModel> Properties { get; set; }
|
||||
|
||||
// Visual and other properties
|
||||
|
||||
public PropertyViewModel? Parent { get; init; }
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isEditing;
|
||||
|
||||
[RelayCommand]
|
||||
private void AddProperty() => Properties.Add(new PropertyViewModel() {Parent = this});
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveProperty() => WeakReferenceMessenger.Default.Send(new RemovePropertyMessage(this));
|
||||
|
||||
[RelayCommand]
|
||||
private void EditProperty() => IsEditing = !IsEditing;
|
||||
|
||||
private void RemoveProperty(object sender, RemovePropertyMessage msg)
|
||||
{
|
||||
if (Properties.Contains(msg.Property))
|
||||
Properties.Remove(msg.Property);
|
||||
}
|
||||
|
||||
public Property GetProperty(Property? parent = null)
|
||||
{
|
||||
Property.Name = Name;
|
||||
Property.Value = Value;
|
||||
Property.CreationDate = CreationDate;
|
||||
Property.Parent = parent;
|
||||
Property.Properties = Properties.Select(e => e.GetProperty(Property)).ToList();
|
||||
return Property;
|
||||
@@ -38,19 +61,25 @@ public partial class PropertyViewModel : ViewModelBase
|
||||
{
|
||||
Name = "Имя свойства";
|
||||
Value = "Значение свойства";
|
||||
CreationDate = DateTime.Now;
|
||||
Properties = [];
|
||||
Parent = null;
|
||||
Property = new Property();
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemovePropertyMessage>(this, RemoveProperty);
|
||||
}
|
||||
|
||||
public PropertyViewModel(Property property, PropertyViewModel? parent = null)
|
||||
{
|
||||
Name = property.Name;
|
||||
Value = property.Value;
|
||||
CreationDate = property.CreationDate;
|
||||
Properties = new ObservableCollection<PropertyViewModel>(
|
||||
property.Properties.Select(e => new PropertyViewModel(e, this)));
|
||||
Parent = property.Parent is null ? null : parent;
|
||||
Property = property;
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemovePropertyMessage>(this, RemoveProperty);
|
||||
}
|
||||
|
||||
public PropertyViewModel(PropertyViewModel property)
|
||||
@@ -60,5 +89,7 @@ public partial class PropertyViewModel : ViewModelBase
|
||||
Properties = [];
|
||||
Parent = property;
|
||||
Property = new Property();
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemovePropertyMessage>(this, RemoveProperty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Views;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class SaveChangesViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool _isSave;
|
||||
[ObservableProperty]
|
||||
private bool _isCancel;
|
||||
|
||||
[RelayCommand]
|
||||
private void Cancel(Window w)
|
||||
{
|
||||
((SaveChangesView)w).CanClose = true;
|
||||
WeakReferenceMessenger.Default.Send(new SaveChangesResult(false, true));
|
||||
w.Close(this);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Save(Window w)
|
||||
{
|
||||
((SaveChangesView)w).CanClose = true;
|
||||
WeakReferenceMessenger.Default.Send(new SaveChangesResult(true, false));
|
||||
w.Close(this);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DontSave(Window w)
|
||||
{
|
||||
((SaveChangesView)w).CanClose = true;
|
||||
WeakReferenceMessenger.Default.Send(new SaveChangesResult(false, false));
|
||||
w.Close(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user