mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +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="Minimum" Value="{x:Static system:Double.MinValue}"></Setter>
|
||||
</Style>
|
||||
<Style Selector="controls|NumberBox /template/ TextBox.NumberBoxTextBoxStyle /template/ TextBlock#PART_Prefix">
|
||||
<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">
|
||||
<Style Selector="controls|NumberBox /template/ TextBox#InputBox">
|
||||
<Setter Property="attachedProperties:TextBoxAssist.PrefixText" Value="{TemplateBinding attachedProperties:NumberBoxAssist.PrefixText}"></Setter>
|
||||
<Setter Property="attachedProperties:TextBoxAssist.SuffixText" Value="{TemplateBinding attachedProperties:NumberBoxAssist.SuffixText}"></Setter>
|
||||
</Style>
|
||||
|
||||
@ -5,7 +5,21 @@
|
||||
<Design.PreviewWith>
|
||||
<Border Padding="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 -->
|
||||
<TextBox Text="99999999"
|
||||
@ -46,12 +60,10 @@
|
||||
|
||||
<Border Margin="{TemplateBinding BorderThickness}">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||
<ContentPresenter Grid.Column="0"
|
||||
Grid.ColumnSpan="1"
|
||||
Content="{TemplateBinding InnerLeftContent}" />
|
||||
<ContentPresenter Grid.Column="0" Content="{TemplateBinding InnerLeftContent}" />
|
||||
<Grid x:Name="PART_InnerGrid"
|
||||
Grid.Column="1"
|
||||
RowDefinitions="Auto,Auto"
|
||||
RowDefinitions="Auto,*"
|
||||
ColumnDefinitions="Auto,*,Auto"
|
||||
Cursor="IBeam"
|
||||
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>
|
||||
</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();
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi
|
||||
return;
|
||||
|
||||
// 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();
|
||||
listener.Prefixes.Add(redirectUri + "/");
|
||||
listener.Start();
|
||||
|
||||
@ -69,7 +69,10 @@ public class WorkshopService : IWorkshopService
|
||||
ProgressableStreamContent streamContent = new(request.File, progress);
|
||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue("image/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
|
||||
HttpResponseMessage response = await client.PostAsync($"entries/{entryId}/image", content, cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user