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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user