Modifying equipment works

This commit is contained in:
retr0volkov
2025-07-05 12:13:30 +03:00 Unverified
parent c0178625cd
commit 8806d28787
9 changed files with 269 additions and 15 deletions
+2 -2
View File
@@ -21,6 +21,6 @@ public class Equipment
// EF stuff // EF stuff
public Image? Image { get; set; } public Image? Image { get; set; }
public Models.Point? Point { get; set; } public Models.Point? Point { get; set; }
public List<Property> Properties { get; } = []; public List<Property> Properties { get; set; } = [];
public List<Inspection> Inspections { get; } = []; public List<Inspection> Inspections { get; set; } = [];
} }
+127 -2
View File
@@ -1,6 +1,131 @@
namespace GazpromApp.ViewModels; using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web;
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;
public class EditEquipmentDialogViewModel namespace GazpromApp.ViewModels;
public partial class EditEquipmentDialogViewModel : ViewModelBase
{ {
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CompleteEditCommand))]
private string? _name;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CompleteEditCommand))]
private string? _description;
[ObservableProperty]
private bool _isNameEditing;
[ObservableProperty]
private bool _isDescriptionEditing;
[ObservableProperty]
private ImageViewModel? _image;
[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 = false,
Title = "Выберите картинку",
FileTypeFilter = [FilePickerFileTypes.ImageAll],
});
IsImageSelected = files.Count > 0;
Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
}
[RelayCommand]
private async Task ViewImage()
{
if (Image is null) return;
_ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(Image));
}
[RelayCommand]
private void DeleteImage()
{
Image = null;
IsImageSelected = false;
}
private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name);
[RelayCommand(CanExecute = nameof(CanCompleteEdit))]
private void CompleteEdit()
{
IsClosed = true;
Equipment equipment = new Equipment()
{
Name = Name,
Description = Description,
Image = Image?.GetImage(),
Properties = [],
};
WeakReferenceMessenger.Default.Send(new EditEquipmentDone(new EquipmentViewModel(equipment)));
}
[RelayCommand]
private void CancelEdit(Window w)
{
IsClosed = true;
WeakReferenceMessenger.Default.Send(new EditEquipmentDone(_equipment));
}
// Visual and other properties
[ObservableProperty]
private bool _isImageSelected;
[ObservableProperty]
private bool _isClosed;
private readonly EquipmentViewModel _equipment;
public EditEquipmentDialogViewModel()
{
Name = "";
Description = "";
Image = null;
IsImageSelected = false;
_equipment = new EquipmentViewModel(new Equipment());
}
public EditEquipmentDialogViewModel(EquipmentViewModel equipment)
{
Name = equipment.Name;
Description = equipment.Description;
Image = equipment.Image;
IsImageSelected = equipment.Image is { Bytes.Length: > 0 };
_equipment = equipment;
}
} }
+73 -3
View File
@@ -2,8 +2,78 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:vm="using:GazpromApp.ViewModels"
x:Name="Window"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="600"
Width="1000" Height="600"
x:Class="GazpromApp.Views.EditEquipmentDialog" x:Class="GazpromApp.Views.EditEquipmentDialog"
Title="EditEquipmentDialog"> x:DataType="vm:EditEquipmentDialogViewModel"
Welcome to Avalonia! Title="EditEquipmentDialog"
WindowStartupLocation="CenterOwner"
Closing="Window_OnClosing"
Closed="Window_OnClosed">
<Design.DataContext>
<vm:EditEquipmentDialogViewModel/>
</Design.DataContext>
<Grid RowDefinitions="70,150,*,Auto" ColumnDefinitions="*,100,220" x:Name="Root">
<TextBlock Grid.Column="0" Grid.Row="0" FontSize="28" Margin="20,4,0,4"
Text="{Binding Name}"
IsVisible="{Binding !IsNameEditing}"/>
<TextBox Grid.Column="0" Grid.Row="0" Margin="12,12,0,4"
Text="{Binding Name}"
IsVisible="{Binding IsNameEditing}"/>
<Button Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" Margin="10"
Command="{Binding EditNameCommand}">
<Image Width="24" Height="24" Source="avares://GazpromApp/Assets/ic_fluent_edit_24_filled (Custom).png"/>
</Button>
<TextBlock Grid.Column="0" Grid.Row="1" Margin="20,4,0,4"
Text="{Binding Description}"
IsVisible="{Binding !IsDescriptionEditing}"/>
<TextBox Grid.Column="0" Grid.Row="1" Margin="12,4,0,4"
Text="{Binding Description}"
IsVisible="{Binding IsDescriptionEditing}"/>
<Button Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" Margin="10"
Command="{Binding EditDescriptionCommand}">
<Image Width="24" Height="24" Source="avares://GazpromApp/Assets/ic_fluent_edit_24_filled (Custom).png"/>
</Button>
<Grid Grid.Row="0" Grid.RowSpan="2" Grid.Column="2"
ColumnDefinitions="*,20,4,20,8" RowDefinitions="8,20,*"
IsVisible="{Binding IsImageSelected}">
<Image Grid.ColumnSpan="5" Grid.RowSpan="3"
Source="{Binding Image.FileName, FallbackValue=null}"/>
<Button Grid.Row="1" Grid.Column="1" Width="20" Height="20"
Command="{Binding ViewImageCommand}">
<Image Width="16" Height="16" Source="avares://GazpromApp/Assets/ic_fluent_eye_show_24_filled (Custom) 16.png"/>
</Button>
<Button Grid.Row="1" Grid.Column="3" Width="20" Height="20"
Command="{Binding DeleteImageCommand}">
<Image Width="16" Height="16" Source="avares://GazpromApp/Assets/ic_fluent_delete_24_filled (Custom) 16.png"/>
</Button>
</Grid>
<Button Grid.Row="0" Grid.RowSpan="2" Grid.Column="2" HorizontalAlignment="Center"
IsVisible="{Binding !IsImageSelected}"
Command="{Binding AddImageCommand}"
CommandParameter="{Binding #Window}">
<Image Width="24" Height="24"
Source="avares://GazpromApp/Assets/ic_fluent_camera_add_24_filled (Custom).png"/>
</Button>
<TabControl Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2">
<TabItem Header="Тех. осмотры">
</TabItem>
<TabItem Header="Свойства">
</TabItem>
</TabControl>
<Button Grid.Column="0" Grid.Row="3" Margin="8" Content="Отменить"
Command="{Binding CancelEditCommand}"
CommandParameter="{Binding #Window}"/>
<Button Grid.Column="2" Grid.Row="3" Margin="8" Content="Сохранить" HorizontalAlignment="Right"
Command="{Binding CompleteEditCommand}"/>
</Grid>
</Window> </Window>
+45 -1
View File
@@ -1,13 +1,57 @@
using Avalonia; using System;
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using CommunityToolkit.Mvvm.Messaging;
using GazpromApp.Messages;
using GazpromApp.Models;
using GazpromApp.ViewModels;
namespace GazpromApp.Views; namespace GazpromApp.Views;
public partial class EditEquipmentDialog : Window public partial class EditEquipmentDialog : Window
{ {
public Equipment? Equipment;
public EditEquipmentDialog() public EditEquipmentDialog()
{ {
InitializeComponent(); InitializeComponent();
if (Design.IsDesignMode)
return;
// view image
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, ViewImageMessage>(this, static (w, m) =>
{
ImageView dialog = new ImageView()
{
DataContext = m.Image
};
m.Reply(dialog.ShowDialog<ImageViewModel?>(w));
});
// new property dialog
// edit property dialog
// complete editing equipment
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, EditEquipmentDone>(this, static (w, m) =>
{
w.Close(m.Equipment);
});
}
private void Window_OnClosing(object? sender, WindowClosingEventArgs e)
{
if (DataContext is EditEquipmentDialogViewModel { IsClosed: false} vm)
vm.CancelEditCommand.Execute(this);
}
private void Window_OnClosed(object? sender, EventArgs e)
{
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
//
//
WeakReferenceMessenger.Default.Unregister<EditEquipmentDone>(this);
} }
} }
+3 -2
View File
@@ -76,7 +76,8 @@
</Button> </Button>
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
<Button HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="{Binding IsImagesEmpty}" <Button HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsImagesEmpty}"
Command="{Binding AddImageCommand}" Command="{Binding AddImageCommand}"
CommandParameter="{Binding #Window}"> CommandParameter="{Binding #Window}">
<Image Width="24" Source="avares://GazpromApp/Assets/ic_fluent_camera_add_24_filled (Custom).png"/> <Image Width="24" Source="avares://GazpromApp/Assets/ic_fluent_camera_add_24_filled (Custom).png"/>
@@ -91,7 +92,7 @@
IsVisible="{Binding !IsEquipmentEmpty}" IsVisible="{Binding !IsEquipmentEmpty}"
ItemsSource="{Binding Equipment}"> ItemsSource="{Binding Equipment}">
<ItemsRepeater.Layout> <ItemsRepeater.Layout>
<NonVirtualizingStackLayout Orientation="Vertical"/> <StackLayout Orientation="Vertical"/>
</ItemsRepeater.Layout> </ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate> <ItemsRepeater.ItemTemplate>
<DataTemplate DataType="vm:EquipmentViewModel"> <DataTemplate DataType="vm:EquipmentViewModel">
+16 -2
View File
@@ -39,15 +39,29 @@ public partial class EditPointDialog : Window
}); });
// edit equipment // edit equipment
WeakReferenceMessenger.Default.Register<EditPointDialog, EditEquipmentMessage>(this, static (w, m) => WeakReferenceMessenger.Default.Register<EditPointDialog, EditEquipmentMessage>(this, (w, m) =>
{ {
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
EditEquipmentDialog dialog = new EditEquipmentDialog() EditEquipmentDialog dialog = new EditEquipmentDialog()
{ {
DataContext = m.Equipment DataContext = new EditEquipmentDialogViewModel(m.Equipment)
}; };
m.Reply(dialog.ShowDialog<EquipmentViewModel?>(w)); m.Reply(dialog.ShowDialog<EquipmentViewModel?>(w));
}); });
// re registering view image
WeakReferenceMessenger.Default.Register<EditPointDialog, EditEquipmentDone>(this, (w, m) =>
{
WeakReferenceMessenger.Default.Register<EditPointDialog, ViewImageMessage>(this, static (w, m) =>
{
ImageView dialog = new ImageView()
{
DataContext = m.Image
};
m.Reply(dialog.ShowDialog<ImageViewModel?>(w));
});
});
// new property // new property
// edit property // edit property
Binary file not shown.
+1 -1
View File
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+812a13e5bb0a09295ee40845a12a0c855bb7376f")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c0178625cd3b6493e3edb6c1847a526192a67b27")]
[assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")]
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
9e16bd1a0b8f6b51c35ae0e4fe20412558f0d499fbae32e7c62ee506cbe91b95 bd707ac6740d23b45223f7c5e6320a05563f812a5bd2e1dc1b2ba3f2023ec0f2