Inspections added
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Utils;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
@@ -33,7 +33,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Image = null;
|
||||
Properties = [];
|
||||
Inspections = [];
|
||||
NearestInspection = DateTime.Now.ToLongDateString();
|
||||
NearestInspection = "Нету инспекций";
|
||||
}
|
||||
|
||||
public EquipmentViewModel(Equipment equipment)
|
||||
@@ -42,8 +42,22 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Description = equipment.Description;
|
||||
Image = new ImageViewModel(equipment.Image ?? new Image());
|
||||
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => new PropertyViewModel(e)));
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections.Select(e => new InspectionViewModel(e)));
|
||||
NearestInspection = DateTime.Now.ToLongDateString();
|
||||
|
||||
List<DateTime[]> times = (equipment.Inspections.Select(e => new InspectionViewModel(e)))
|
||||
.Select(e => e.GetNearestDates())
|
||||
.ToList();
|
||||
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections
|
||||
.Select((e, i) => new InspectionViewModel(e) { InspectionDate = times[i][0] }));
|
||||
|
||||
NearestInspection = times
|
||||
.Where(e => e[1] > DateTime.Now)
|
||||
.Select(e => e[1])
|
||||
.OrderBy(e => e)
|
||||
.FirstOrDefault()
|
||||
.ToLongDateString();
|
||||
|
||||
if (Inspections.Count == 0) NearestInspection = "Нету инспекций";
|
||||
}
|
||||
|
||||
public Equipment GetEquipment()
|
||||
@@ -53,6 +67,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,50 @@
|
||||
using GazpromApp.Models;
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class InspectionViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string _name;
|
||||
[ObservableProperty]
|
||||
private DateTimeOffset _inspectionDate;
|
||||
[ObservableProperty]
|
||||
private PeriodType _periodType;
|
||||
[ObservableProperty]
|
||||
private float _periodValue;
|
||||
|
||||
// Visual properties
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isEditing = false;
|
||||
|
||||
public InspectionViewModel()
|
||||
{
|
||||
|
||||
Name = string.Empty;
|
||||
InspectionDate = DateTimeOffset.Now;
|
||||
PeriodType = 0;
|
||||
PeriodValue = 1;
|
||||
}
|
||||
|
||||
public InspectionViewModel(Inspection inspection)
|
||||
{
|
||||
|
||||
Name = inspection.Name;
|
||||
InspectionDate = inspection.InspectionDate;
|
||||
PeriodType = inspection.PeriodType.ToPeriodType();
|
||||
PeriodValue = inspection.PeriodValue;
|
||||
}
|
||||
|
||||
public Inspection GetInspection()
|
||||
{
|
||||
return new Inspection()
|
||||
{
|
||||
Name = Name,
|
||||
InspectionDate = InspectionDate,
|
||||
PeriodType = PeriodType.ToDescription(),
|
||||
PeriodValue = PeriodValue
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Avalonia.Controls;
|
||||
@@ -33,6 +35,8 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private ImageViewModel? _image;
|
||||
|
||||
public ObservableCollection<InspectionViewModel> Inspections { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
private void EditName()
|
||||
{
|
||||
@@ -90,6 +94,27 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
Image = null;
|
||||
IsImageSelected = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AddInspection()
|
||||
{
|
||||
Inspections.Add(new InspectionViewModel { Name = "Название инспекции", InspectionDate = DateTimeOffset.Now, PeriodValue = 1, PeriodType = PeriodType.Day });
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void EditInspection(InspectionViewModel inspection)
|
||||
{
|
||||
foreach (var item in Inspections)
|
||||
if (item != inspection)
|
||||
item.IsEditing = false;
|
||||
inspection.IsEditing = !inspection.IsEditing;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteInspection(InspectionViewModel inspection)
|
||||
{
|
||||
Inspections.Remove(inspection);
|
||||
}
|
||||
|
||||
private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name);
|
||||
|
||||
@@ -102,6 +127,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
Properties = [],
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditEquipmentDone(new EquipmentViewModel(equipment)));
|
||||
@@ -124,15 +150,20 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
|
||||
private readonly EquipmentViewModel _equipment;
|
||||
|
||||
public PeriodType[] AllPeriods => Enum.GetValues<PeriodType>()
|
||||
.Where(p => p != PeriodType.Unknown)
|
||||
.ToArray();
|
||||
|
||||
public EditEquipmentDialogViewModel()
|
||||
{
|
||||
Name = "";
|
||||
Description = "";
|
||||
Name = "Testing";
|
||||
Description = "Testing";
|
||||
Image = null;
|
||||
Inspections = [];
|
||||
|
||||
IsImageSelected = false;
|
||||
|
||||
_equipment = new EquipmentViewModel(new Equipment());
|
||||
_equipment = new EquipmentViewModel();
|
||||
}
|
||||
|
||||
public EditEquipmentDialogViewModel(EquipmentViewModel equipment)
|
||||
@@ -140,6 +171,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
Name = equipment.Name;
|
||||
Description = equipment.Description;
|
||||
Image = equipment.Image;
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections.Select(e => e));
|
||||
|
||||
IsImageSelected = equipment.Image is { Bytes.Length: > 0 };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user