mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Workshop - Added image uploading
This commit is contained in:
1 parent
0667d58ed8
commit
e33ae8a066
9 files changed
+120
-35
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:image="clr-namespace:Artemis.UI.Screens.Workshop.Image"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Image.ImagePropertiesDialogView"
|
||||
x:DataType="image:ImagePropertiesDialogViewModel">
|
||||
<StackPanel Width="400">
|
||||
<Label>Name</Label>
|
||||
<TextBox Text="{CompiledBinding Name}" Watermark="Name" MaxLength="50"/>
|
||||
<Label>Description</Label>
|
||||
<TextBox AcceptsReturn="True" Height="150" Text="{CompiledBinding Description}" Watermark="Description" MaxLength="150" MaxLines="7"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Image;
|
||||
|
||||
public partial class ImagePropertiesDialogView : UserControl
|
||||
{
|
||||
public ImagePropertiesDialogView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Reactive;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Extensions;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Image;
|
||||
|
||||
public partial class ImagePropertiesDialogViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
private readonly ImageUploadRequest _image;
|
||||
[Notify] private string? _name;
|
||||
[Notify] private string? _description;
|
||||
|
||||
public ImagePropertiesDialogViewModel(ImageUploadRequest image)
|
||||
{
|
||||
_image = image;
|
||||
_name = image.Name;
|
||||
_description = image.Description;
|
||||
|
||||
Confirm = ReactiveCommand.Create(ExecuteConfirm, ValidationContext.Valid);
|
||||
|
||||
this.ValidationRule(vm => vm.Name, input => !string.IsNullOrWhiteSpace(input), "Name is required");
|
||||
this.ValidationRule(vm => vm.Name, input => input?.Length <= 50, "Name can be a maximum of 50 characters");
|
||||
this.ValidationRule(vm => vm.Description, input => input?.Length <= 150, "Description can be a maximum of 150 characters");
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Confirm { get; }
|
||||
|
||||
private void ExecuteConfirm()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
return;
|
||||
|
||||
_image.Name = Name;
|
||||
_image.Description = string.IsNullOrWhiteSpace(Description) ? null : Description;
|
||||
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,9 @@
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" Spacing="5" Margin="6" VerticalAlignment="Bottom" HorizontalAlignment="Right">
|
||||
<StackPanel Grid.Row="1" Spacing="5" Margin="6" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right">
|
||||
<Button Classes="icon-button"
|
||||
Command="{CompiledBinding Remove}"
|
||||
Command="{CompiledBinding Edit}"
|
||||
ToolTip.Tip="Edit">
|
||||
<avalonia:MaterialIcon Kind="Edit" />
|
||||
</Button>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.IO;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
@@ -13,6 +16,8 @@ namespace Artemis.UI.Screens.Workshop.Image;
|
||||
|
||||
public partial class ImageSubmissionViewModel : ValidatableViewModelBase
|
||||
{
|
||||
private readonly ImageUploadRequest _image;
|
||||
private readonly IWindowService _windowService;
|
||||
[Notify(Setter.Private)] private Bitmap? _bitmap;
|
||||
[Notify(Setter.Private)] private string? _imageDimensions;
|
||||
[Notify(Setter.Private)] private long _fileSize;
|
||||
@@ -20,25 +25,35 @@ public partial class ImageSubmissionViewModel : ValidatableViewModelBase
|
||||
[Notify] private string? _description;
|
||||
[Notify] private ICommand? _remove;
|
||||
|
||||
public ImageSubmissionViewModel(ImageUploadRequest image)
|
||||
public ImageSubmissionViewModel(ImageUploadRequest image, IWindowService windowService)
|
||||
{
|
||||
_image = image;
|
||||
_windowService = windowService;
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
image.File.Seek(0, SeekOrigin.Begin);
|
||||
Bitmap = new Bitmap(image.File);
|
||||
FileSize = image.File.Length;
|
||||
_image.File.Seek(0, SeekOrigin.Begin);
|
||||
Bitmap = new Bitmap(_image.File);
|
||||
FileSize = _image.File.Length;
|
||||
ImageDimensions = Bitmap.Size.Width + "x" + Bitmap.Size.Height;
|
||||
Name = image.Name;
|
||||
Description = image.Description;
|
||||
Name = _image.Name;
|
||||
Description = _image.Description;
|
||||
|
||||
Bitmap.DisposeWith(d);
|
||||
}, DispatcherPriority.Background);
|
||||
});
|
||||
|
||||
this.ValidationRule(vm => vm.Name, input => !string.IsNullOrWhiteSpace(input), "Name is required");
|
||||
this.ValidationRule(vm => vm.Name, input => input?.Length <= 50, "Name can be a maximum of 50 characters");
|
||||
this.ValidationRule(vm => vm.Description, input => input?.Length <= 150, "Description can be a maximum of 150 characters");
|
||||
}
|
||||
|
||||
public async Task Edit()
|
||||
{
|
||||
await _windowService.CreateContentDialog()
|
||||
.WithTitle("Edit image properties")
|
||||
.WithViewModel(out ImagePropertiesDialogViewModel vm, _image)
|
||||
.HavingPrimaryButton(b => b.WithText("Confirm").WithCommand(vm.Confirm))
|
||||
.WithCloseButtonText("Cancel")
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user