mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Workshop - Added image uploading
This commit is contained in:
parent
0667d58ed8
commit
e33ae8a066
@ -27,22 +27,7 @@
|
|||||||
<Setter Property="Maximum" Value="{x:Static system:Double.MaxValue}"></Setter>
|
<Setter Property="Maximum" Value="{x:Static system:Double.MaxValue}"></Setter>
|
||||||
<Setter Property="Minimum" Value="{x:Static system:Double.MinValue}"></Setter>
|
<Setter Property="Minimum" Value="{x:Static system:Double.MinValue}"></Setter>
|
||||||
</Style>
|
</Style>
|
||||||
<Style Selector="controls|NumberBox /template/ TextBox.NumberBoxTextBoxStyle /template/ TextBlock#PART_Prefix">
|
<Style Selector="controls|NumberBox /template/ TextBox#InputBox">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}"></Setter>
|
|
||||||
<Setter Property="Margin" Value="-4 0 -12 0"></Setter>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="controls|NumberBox /template/ TextBox.NumberBoxTextBoxStyle /template/ TextBlock#PART_Suffix">
|
|
||||||
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}"></Setter>
|
|
||||||
<Setter Property="Margin" Value="-12 0 0 0"></Setter>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style Selector="controls|NumberBox.condensed /template/ TextBox.NumberBoxTextBoxStyle /template/ TextBlock#PART_Prefix">
|
|
||||||
<Setter Property="Margin" Value="0 0 -4 0"></Setter>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="controls|NumberBox.condensed /template/ TextBox.NumberBoxTextBoxStyle /template/ TextBlock#PART_Suffix">
|
|
||||||
<Setter Property="Margin" Value="-4 0 0 0"></Setter>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="controls|NumberBox /template/ TextBox.NumberBoxTextBoxStyle">
|
|
||||||
<Setter Property="attachedProperties:TextBoxAssist.PrefixText" Value="{TemplateBinding attachedProperties:NumberBoxAssist.PrefixText}"></Setter>
|
<Setter Property="attachedProperties:TextBoxAssist.PrefixText" Value="{TemplateBinding attachedProperties:NumberBoxAssist.PrefixText}"></Setter>
|
||||||
<Setter Property="attachedProperties:TextBoxAssist.SuffixText" Value="{TemplateBinding attachedProperties:NumberBoxAssist.SuffixText}"></Setter>
|
<Setter Property="attachedProperties:TextBoxAssist.SuffixText" Value="{TemplateBinding attachedProperties:NumberBoxAssist.SuffixText}"></Setter>
|
||||||
</Style>
|
</Style>
|
||||||
|
|||||||
@ -5,7 +5,21 @@
|
|||||||
<Design.PreviewWith>
|
<Design.PreviewWith>
|
||||||
<Border Padding="20">
|
<Border Padding="20">
|
||||||
<StackPanel Spacing="20">
|
<StackPanel Spacing="20">
|
||||||
|
<TextBox Width="200" Height="150" AcceptsReturn="True" xml:space="preserve">asdasdas asd
|
||||||
|
asdasd
|
||||||
|
asd
|
||||||
|
asd
|
||||||
|
asd
|
||||||
|
as
|
||||||
|
fdsfsdf
|
||||||
|
sdg
|
||||||
|
sdg
|
||||||
|
sdg
|
||||||
|
</TextBox>
|
||||||
|
<TextBox Width="200" Height="150" AcceptsReturn="True" xml:space="preserve">asdasdas asd
|
||||||
|
asdasd
|
||||||
|
asd
|
||||||
|
as</TextBox>
|
||||||
|
|
||||||
<!-- Add Controls for Previewer Here -->
|
<!-- Add Controls for Previewer Here -->
|
||||||
<TextBox Text="99999999"
|
<TextBox Text="99999999"
|
||||||
@ -46,12 +60,10 @@
|
|||||||
|
|
||||||
<Border Margin="{TemplateBinding BorderThickness}">
|
<Border Margin="{TemplateBinding BorderThickness}">
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto">
|
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||||
<ContentPresenter Grid.Column="0"
|
<ContentPresenter Grid.Column="0" Content="{TemplateBinding InnerLeftContent}" />
|
||||||
Grid.ColumnSpan="1"
|
|
||||||
Content="{TemplateBinding InnerLeftContent}" />
|
|
||||||
<Grid x:Name="PART_InnerGrid"
|
<Grid x:Name="PART_InnerGrid"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
RowDefinitions="Auto,Auto"
|
RowDefinitions="Auto,*"
|
||||||
ColumnDefinitions="Auto,*,Auto"
|
ColumnDefinitions="Auto,*,Auto"
|
||||||
Cursor="IBeam"
|
Cursor="IBeam"
|
||||||
Margin="{TemplateBinding Padding}">
|
Margin="{TemplateBinding Padding}">
|
||||||
|
|||||||
@ -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>
|
</TextBlock>
|
||||||
</StackPanel>
|
</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"
|
<Button Classes="icon-button"
|
||||||
Command="{CompiledBinding Remove}"
|
Command="{CompiledBinding Edit}"
|
||||||
ToolTip.Tip="Edit">
|
ToolTip.Tip="Edit">
|
||||||
<avalonia:MaterialIcon Kind="Edit" />
|
<avalonia:MaterialIcon Kind="Edit" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
|
using Artemis.UI.Shared.Services;
|
||||||
|
using Artemis.UI.Shared.Services.Builders;
|
||||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
@ -13,6 +16,8 @@ namespace Artemis.UI.Screens.Workshop.Image;
|
|||||||
|
|
||||||
public partial class ImageSubmissionViewModel : ValidatableViewModelBase
|
public partial class ImageSubmissionViewModel : ValidatableViewModelBase
|
||||||
{
|
{
|
||||||
|
private readonly ImageUploadRequest _image;
|
||||||
|
private readonly IWindowService _windowService;
|
||||||
[Notify(Setter.Private)] private Bitmap? _bitmap;
|
[Notify(Setter.Private)] private Bitmap? _bitmap;
|
||||||
[Notify(Setter.Private)] private string? _imageDimensions;
|
[Notify(Setter.Private)] private string? _imageDimensions;
|
||||||
[Notify(Setter.Private)] private long _fileSize;
|
[Notify(Setter.Private)] private long _fileSize;
|
||||||
@ -20,25 +25,35 @@ public partial class ImageSubmissionViewModel : ValidatableViewModelBase
|
|||||||
[Notify] private string? _description;
|
[Notify] private string? _description;
|
||||||
[Notify] private ICommand? _remove;
|
[Notify] private ICommand? _remove;
|
||||||
|
|
||||||
public ImageSubmissionViewModel(ImageUploadRequest image)
|
public ImageSubmissionViewModel(ImageUploadRequest image, IWindowService windowService)
|
||||||
{
|
{
|
||||||
|
_image = image;
|
||||||
|
_windowService = windowService;
|
||||||
|
|
||||||
this.WhenActivated(d =>
|
this.WhenActivated(d =>
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
image.File.Seek(0, SeekOrigin.Begin);
|
_image.File.Seek(0, SeekOrigin.Begin);
|
||||||
Bitmap = new Bitmap(image.File);
|
Bitmap = new Bitmap(_image.File);
|
||||||
FileSize = image.File.Length;
|
FileSize = _image.File.Length;
|
||||||
ImageDimensions = Bitmap.Size.Width + "x" + Bitmap.Size.Height;
|
ImageDimensions = Bitmap.Size.Width + "x" + Bitmap.Size.Height;
|
||||||
Name = image.Name;
|
Name = _image.Name;
|
||||||
Description = image.Description;
|
Description = _image.Description;
|
||||||
|
|
||||||
Bitmap.DisposeWith(d);
|
Bitmap.DisposeWith(d);
|
||||||
}, DispatcherPriority.Background);
|
}, 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");
|
public async Task Edit()
|
||||||
this.ValidationRule(vm => vm.Description, input => input?.Length <= 150, "Description can be a maximum of 150 characters");
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Start a HTTP listener, this port could be in use but chances are very slim
|
// Start a HTTP listener, this port could be in use but chances are very slim
|
||||||
string redirectUri = "http://localhost:56789";
|
string redirectUri = "http://localhost:57461";
|
||||||
using HttpListener listener = new();
|
using HttpListener listener = new();
|
||||||
listener.Prefixes.Add(redirectUri + "/");
|
listener.Prefixes.Add(redirectUri + "/");
|
||||||
listener.Start();
|
listener.Start();
|
||||||
|
|||||||
@ -69,7 +69,10 @@ public class WorkshopService : IWorkshopService
|
|||||||
ProgressableStreamContent streamContent = new(request.File, progress);
|
ProgressableStreamContent streamContent = new(request.File, progress);
|
||||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
streamContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||||
content.Add(streamContent, "file", "file.png");
|
content.Add(streamContent, "file", "file.png");
|
||||||
|
content.Add(new StringContent(request.Name), "Name");
|
||||||
|
if (request.Description != null)
|
||||||
|
content.Add(new StringContent(request.Description), "Description");
|
||||||
|
|
||||||
// Submit
|
// Submit
|
||||||
HttpResponseMessage response = await client.PostAsync($"entries/{entryId}/image", content, cancellationToken);
|
HttpResponseMessage response = await client.PostAsync($"entries/{entryId}/image", content, cancellationToken);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user