DB integration added, multiple images for equipment
This commit is contained in:
@@ -32,8 +32,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private bool _isDescriptionEditing;
|
||||
|
||||
[ObservableProperty]
|
||||
private ImageViewModel? _image;
|
||||
public ObservableCollection<ImageViewModel> Images { get; set; }
|
||||
|
||||
public ObservableCollection<InspectionViewModel> Inspections { get; set; }
|
||||
|
||||
@@ -56,43 +55,39 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
{
|
||||
var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = "Выберите картинку",
|
||||
AllowMultiple = true,
|
||||
Title = "Выберите одну или несколько картинок",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll]
|
||||
});
|
||||
|
||||
IsImageSelected = files.Count > 0;
|
||||
|
||||
try
|
||||
foreach (var file in files)
|
||||
{
|
||||
Image = IsImageSelected ? new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
var error = new Error
|
||||
try
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = "Картинка не была добавлена",
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
|
||||
IsImageSelected = false;
|
||||
Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(file.Path.AbsolutePath) ) });
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
var error = new Error
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = $"Картинка не была добавлена: \"{HttpUtility.UrlDecode(file.Name)}\"",
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
}
|
||||
}
|
||||
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ViewImage()
|
||||
{
|
||||
if (Image is null) return;
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(Image));
|
||||
}
|
||||
private static async Task ViewImage(ImageViewModel image) => _ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(image));
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteImage()
|
||||
private void DeleteImage(ImageViewModel image)
|
||||
{
|
||||
Image = null;
|
||||
IsImageSelected = false;
|
||||
Images.Remove(image);
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -146,7 +141,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Images = Images.Select(e => e.GetImage()).ToList(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList()
|
||||
};
|
||||
@@ -163,13 +158,14 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
// Visual and other properties
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isImageSelected;
|
||||
private bool _isImagesEmpty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isClosed;
|
||||
|
||||
private readonly EquipmentViewModel _equipment;
|
||||
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Global
|
||||
public PeriodType[] AllPeriods => Enum.GetValues<PeriodType>()
|
||||
.Where(p => p != PeriodType.Unknown)
|
||||
.ToArray();
|
||||
@@ -178,11 +174,11 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
{
|
||||
Name = "Testing";
|
||||
Description = "Testing";
|
||||
Image = null;
|
||||
Images = [];
|
||||
Inspections = [];
|
||||
Properties = [];
|
||||
|
||||
IsImageSelected = false;
|
||||
IsImagesEmpty = true;
|
||||
|
||||
_equipment = new EquipmentViewModel();
|
||||
}
|
||||
@@ -191,11 +187,11 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
{
|
||||
Name = equipment.Name;
|
||||
Description = equipment.Description;
|
||||
Image = equipment.Image;
|
||||
Images = equipment.Images;
|
||||
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 };
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
|
||||
_equipment = equipment;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user