Adding point works
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class ImageViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private byte[]? _bytes;
|
||||
// EF stuff
|
||||
[ObservableProperty]
|
||||
private List<Point>? _points;
|
||||
[ObservableProperty]
|
||||
private List<Equipment>? _equipment;
|
||||
[ObservableProperty]
|
||||
private Bitmap? _fileName;
|
||||
|
||||
public ImageViewModel(Image image)
|
||||
{
|
||||
Bytes = image.Bytes;
|
||||
Equipment = image.Equipment;
|
||||
Points = image.Points;
|
||||
}
|
||||
|
||||
public Image GetImage()
|
||||
{
|
||||
return new Image()
|
||||
{
|
||||
Bytes = Bytes ?? [],
|
||||
Equipment = Equipment ?? [],
|
||||
Points = Points ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class PointViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? _name;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _description;
|
||||
|
||||
[ObservableProperty]
|
||||
private double? _latitude;
|
||||
|
||||
[ObservableProperty]
|
||||
private double? _longitude;
|
||||
// EF stuff
|
||||
[ObservableProperty]
|
||||
private List<Image>? _images;
|
||||
[ObservableProperty]
|
||||
private List<Equipment>? _equipment;
|
||||
[ObservableProperty]
|
||||
private List<Property>? _properties;
|
||||
|
||||
public PointViewModel(Models.Point point)
|
||||
{
|
||||
Name = point.Name;
|
||||
Description = point.Description;
|
||||
Latitude = point.Latitude;
|
||||
Longitude = point.Longitude;
|
||||
Images = point.Images;
|
||||
Equipment = point.Equipment;
|
||||
Properties = point.Properties;
|
||||
}
|
||||
|
||||
public Models.Point GetPoint()
|
||||
{
|
||||
return new Models.Point()
|
||||
{
|
||||
Name = this.Name,
|
||||
Description = this.Description
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class EditPointDialogViewModel : ViewModelBase
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,6 +1,40 @@
|
||||
namespace GazpromApp.ViewModels;
|
||||
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;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
public string Greeting { get; } = "Welcome to Avalonia!";
|
||||
public ObservableCollection<PointViewModel> Points { get; } = new ObservableCollection<PointViewModel>();
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AddPoint()
|
||||
{
|
||||
var point = await WeakReferenceMessenger.Default.Send(new NewPointMessage());
|
||||
if (point != null)
|
||||
Points.Add(point);
|
||||
IsLineVisible = true;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemovePoint(PointViewModel point)
|
||||
{
|
||||
Points.Remove(point);
|
||||
if (Points.Count == 0)
|
||||
IsLineVisible = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void EditPoint(PointViewModel point)
|
||||
{
|
||||
Debug.WriteLine(point.Name);
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLineVisible;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
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;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
using Point = GazpromApp.Models.Point;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class NewPointDialogViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? _name;
|
||||
|
||||
[ObservableProperty]
|
||||
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;
|
||||
}
|
||||
|
||||
[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 = false;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isImagesEmpty = true;
|
||||
|
||||
private bool CanExecuteEnterPoint() => !string.IsNullOrEmpty(Name) || !string.IsNullOrEmpty(Description);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanExecuteEnterPoint))]
|
||||
public void EnterPoint()
|
||||
{
|
||||
Point point = new Point()
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Images = Images.Select(e => e.GetImage()).ToList()
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new NewPointDone(new PointViewModel(point)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user