Modifying points works
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Models;
|
||||
@@ -24,13 +23,23 @@ public partial class ImageViewModel : ViewModelBase
|
||||
Bytes = image.Bytes;
|
||||
Equipment = image.Equipment;
|
||||
Points = image.Points;
|
||||
FileName = image.Bytes is { Length: > 0 } ? new Bitmap(new MemoryStream(image.Bytes)) : null;
|
||||
}
|
||||
|
||||
public ImageViewModel()
|
||||
{
|
||||
Bytes = null;
|
||||
Equipment = null;
|
||||
Points = null;
|
||||
}
|
||||
|
||||
public Image GetImage()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
FileName?.Save(ms);
|
||||
return new Image()
|
||||
{
|
||||
Bytes = Bytes ?? [],
|
||||
Bytes = ms.ToArray(),
|
||||
Equipment = Equipment ?? [],
|
||||
Points = Points ?? [],
|
||||
};
|
||||
|
||||
@@ -1,6 +1,120 @@
|
||||
namespace GazpromApp.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class EditPointDialogViewModel : ViewModelBase
|
||||
{
|
||||
public ObservableCollection<ImageViewModel> Images { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(CompleteEditCommand))]
|
||||
private string? _name;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(CompleteEditCommand))]
|
||||
private string? _description;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isNameEditing;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isDescriptionEditing;
|
||||
|
||||
[RelayCommand]
|
||||
private void EditName()
|
||||
{
|
||||
IsNameEditing = !IsNameEditing;
|
||||
IsDescriptionEditing = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void EditDescription()
|
||||
{
|
||||
IsDescriptionEditing = !IsDescriptionEditing;
|
||||
IsNameEditing = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
{
|
||||
AllowMultiple = true,
|
||||
Title = "Выберите одну или несколько картинок",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll],
|
||||
});
|
||||
foreach (var file in files)
|
||||
Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(file.Path.AbsolutePath) });
|
||||
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteImage(ImageViewModel image)
|
||||
{
|
||||
Images.Remove(image);
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ViewImage(ImageViewModel image)
|
||||
{
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(image));
|
||||
}
|
||||
|
||||
private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanCompleteEdit))]
|
||||
private void CompleteEdit()
|
||||
{
|
||||
Point point = new Point()
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Images = Images.Select(e => e.GetImage()).ToList()
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditPointDone(new PointViewModel(point)));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private static void CancelEdit(Window w)
|
||||
{
|
||||
w.Close();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isImagesEmpty;
|
||||
|
||||
public EditPointDialogViewModel()
|
||||
{
|
||||
Name = "";
|
||||
Description = "";
|
||||
Images = [];
|
||||
IsImagesEmpty = true;
|
||||
}
|
||||
|
||||
public EditPointDialogViewModel(PointViewModel point)
|
||||
{
|
||||
Name = point.Name;
|
||||
Description = point.Description;
|
||||
Images = new ObservableCollection<ImageViewModel>((point.Images ?? []).Select(e => new ImageViewModel(e)));
|
||||
foreach (ImageViewModel imageViewModel in Images)
|
||||
{
|
||||
Debug.WriteLine(imageViewModel.FileName);
|
||||
}
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,45 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
using GazpromApp.Messages;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
public ObservableCollection<PointViewModel> Points { get; } = new ObservableCollection<PointViewModel>();
|
||||
public ObservableCollection<PointViewModel> Points { get; } = [];
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AddPoint()
|
||||
{
|
||||
var point = await WeakReferenceMessenger.Default.Send(new NewPointMessage());
|
||||
|
||||
if (point != null)
|
||||
Points.Add(point);
|
||||
IsLineVisible = true;
|
||||
|
||||
IsLineVisible = Points.Count > 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task EditPoint(PointViewModel point)
|
||||
{
|
||||
PointViewModel p = await WeakReferenceMessenger.Default.Send(new EditPointMessage(point)) ?? point;
|
||||
Points[Points.IndexOf(point)] = p;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemovePoint(PointViewModel point)
|
||||
{
|
||||
Points.Remove(point);
|
||||
if (Points.Count == 0)
|
||||
IsLineVisible = false;
|
||||
|
||||
IsLineVisible = Points.Count > 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void EditPoint(PointViewModel point)
|
||||
{
|
||||
Debug.WriteLine(point.Name);
|
||||
}
|
||||
|
||||
|
||||
// Visual properties
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLineVisible;
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
@@ -20,20 +17,14 @@ namespace GazpromApp.ViewModels;
|
||||
public partial class NewPointDialogViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(EnterPointCommand))]
|
||||
private string? _name;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(EnterPointCommand))]
|
||||
private string? _description;
|
||||
|
||||
public ObservableCollection<ImageViewModel> Images { get; } = new ObservableCollection<ImageViewModel>();
|
||||
|
||||
[RelayCommand]
|
||||
public void DeleteImage(ImageViewModel image)
|
||||
{
|
||||
Images.Remove(image);
|
||||
if (Images.Count == 0)
|
||||
IsImagesEmpty = true;
|
||||
}
|
||||
public ObservableCollection<ImageViewModel> Images { get; } = [];
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
@@ -46,16 +37,21 @@ public partial class NewPointDialogViewModel : ViewModelBase
|
||||
});
|
||||
foreach (var file in files)
|
||||
Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(file.Path.AbsolutePath) });
|
||||
IsImagesEmpty = false;
|
||||
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isImagesEmpty = true;
|
||||
[RelayCommand]
|
||||
private void DeleteImage(ImageViewModel image)
|
||||
{
|
||||
Images.Remove(image);
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
}
|
||||
|
||||
private bool CanExecuteEnterPoint() => !string.IsNullOrEmpty(Name) || !string.IsNullOrEmpty(Description);
|
||||
private bool CanEnterPoint() => !string.IsNullOrEmpty(Name);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanExecuteEnterPoint))]
|
||||
public void EnterPoint()
|
||||
[RelayCommand (CanExecute = nameof(CanEnterPoint))]
|
||||
private void EnterPoint()
|
||||
{
|
||||
Point point = new Point()
|
||||
{
|
||||
@@ -65,4 +61,15 @@ public partial class NewPointDialogViewModel : ViewModelBase
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new NewPointDone(new PointViewModel(point)));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private static void CancelEnterPoint(Window w)
|
||||
{
|
||||
w.Close();
|
||||
}
|
||||
|
||||
// Visual properties
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isImagesEmpty = true;
|
||||
}
|
||||
Reference in New Issue
Block a user