mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Move IEntrySource to workshop
This commit is contained in:
parent
c1e0dadce8
commit
59fe1df40f
@ -1,6 +0,0 @@
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
|
||||
public interface IEntrySource
|
||||
{
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Layout;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens.Workshop.Layout;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Extensions;
|
||||
@ -26,7 +26,7 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
|
||||
public LayoutInfoStepViewModel(Func<ArtemisLayout, LayoutInfoViewModel> getLayoutInfoViewModel)
|
||||
{
|
||||
_getLayoutInfoViewModel = getLayoutInfoViewModel;
|
||||
|
||||
|
||||
GoBack = ReactiveCommand.Create(() => State.ChangeScreen<LayoutSelectionStepViewModel>());
|
||||
Continue = ReactiveCommand.Create(ExecuteContinue, ValidationContext.Valid);
|
||||
Secondary = ReactiveCommand.Create(ExecuteAddLayoutInfo);
|
||||
@ -40,11 +40,11 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
|
||||
_layout = layoutEntrySource.Layout;
|
||||
IsKeyboardLayout = _layout.RgbLayout.Type == RGBDeviceType.Keyboard;
|
||||
PhysicalLayout = layoutEntrySource.PhysicalLayout;
|
||||
LayoutInfo = layoutEntrySource.LayoutInfo;
|
||||
LayoutInfo = new ObservableCollection<LayoutInfoViewModel>(layoutEntrySource.LayoutInfo.Select(CreateLayoutInfoViewModel));
|
||||
|
||||
if (!LayoutInfo.Any())
|
||||
ExecuteAddLayoutInfo();
|
||||
|
||||
|
||||
this.ValidationRule(
|
||||
vm => vm.PhysicalLayout,
|
||||
this.WhenAnyValue(vm => vm.IsKeyboardLayout, vm => vm.PhysicalLayout, (isKeyboard, layout) => !isKeyboard || layout != KeyboardLayoutType.Unknown),
|
||||
@ -58,6 +58,17 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
|
||||
});
|
||||
}
|
||||
|
||||
private LayoutInfoViewModel CreateLayoutInfoViewModel(LayoutInfo layoutInfo)
|
||||
{
|
||||
LayoutInfoViewModel vm = _getLayoutInfoViewModel(_layout ?? throw new InvalidOperationException());
|
||||
vm.Model = layoutInfo.Model;
|
||||
vm.Vendor = layoutInfo.Vendor;
|
||||
vm.DeviceProviderId = layoutInfo.DeviceProviderId;
|
||||
vm.Remove = ReactiveCommand.Create(() => LayoutInfo.Remove(vm));
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
private void ExecuteAddLayoutInfo()
|
||||
{
|
||||
if (_layout == null)
|
||||
@ -74,8 +85,9 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
|
||||
return;
|
||||
|
||||
layoutEntrySource.PhysicalLayout = PhysicalLayout;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(State.Name))
|
||||
// layoutEntrySource.LayoutInfo = new List<LayoutInfo>(LayoutInfo.Select(i => i.ToLayoutInfo()));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(State.Name))
|
||||
State.Name = layoutEntrySource.Layout.RgbLayout.Name ?? "";
|
||||
if (string.IsNullOrWhiteSpace(State.Summary))
|
||||
{
|
||||
@ -108,7 +120,6 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
|
||||
}
|
||||
|
||||
State.Categories = new List<long> {8}; // Device category, yes this could change but why would it
|
||||
|
||||
if (State.EntryId == null)
|
||||
State.ChangeScreen<SpecificationsStepViewModel>();
|
||||
else
|
||||
|
||||
@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
using Artemis.UI.Shared.Extensions;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using SkiaSharp;
|
||||
|
||||
@ -9,6 +9,7 @@ using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using DynamicData;
|
||||
using DynamicData.Aggregation;
|
||||
using ReactiveUI;
|
||||
|
||||
@ -8,6 +8,7 @@ using Artemis.Core.Services;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Workshop.Profile;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using Material.Icons;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using ReactiveUI;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
using DryIoc;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public interface IEntrySource
|
||||
{
|
||||
|
||||
}
|
||||
@ -4,5 +4,5 @@ namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public interface IEntryUploadHandler
|
||||
{
|
||||
Task<EntryUploadResult> CreateReleaseAsync(long entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken);
|
||||
Task<EntryUploadResult> CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress<StreamProgress> progress, CancellationToken cancellationToken);
|
||||
}
|
||||
@ -1,10 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens.Workshop.Layout;
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class LayoutEntrySource : IEntrySource
|
||||
{
|
||||
@ -14,8 +10,8 @@ public class LayoutEntrySource : IEntrySource
|
||||
}
|
||||
|
||||
public ArtemisLayout Layout { get; set; }
|
||||
public ObservableCollection<LayoutInfoViewModel> LayoutInfo { get; } = new();
|
||||
public KeyboardLayoutType PhysicalLayout { get; set; }
|
||||
public List<LayoutInfo> LayoutInfo { get; set; } = new();
|
||||
public Core.KeyboardLayoutType PhysicalLayout { get; set; }
|
||||
|
||||
private List<LayoutCustomLedDataLogicalLayout> GetLogicalLayouts()
|
||||
{
|
||||
@ -26,4 +22,11 @@ public class LayoutEntrySource : IEntrySource
|
||||
.DistinctBy(l => l.Name)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class LayoutInfo
|
||||
{
|
||||
public string Vendor { get; set; } = string.Empty;
|
||||
public string Model { get; set; } = string.Empty;
|
||||
public Guid DeviceProviderId { get; set; }
|
||||
}
|
||||
@ -1,12 +1,25 @@
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using System.Xml.Serialization;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using RGB.NET.Layout;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class LayoutEntryUploadHandler : IEntryUploadHandler
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (entrySource is not LayoutEntrySource source)
|
||||
throw new InvalidOperationException("Can only create releases for layouts");
|
||||
|
||||
// Create a copy of the layout, image paths are about to be rewritten
|
||||
XmlSerializer serializer = new(typeof(DeviceLayout));
|
||||
using MemoryStream ms = new();
|
||||
await using StreamWriter writer = new(ms);
|
||||
serializer.Serialize(writer, source.Layout.RgbLayout);
|
||||
await writer.FlushAsync();
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return new EntryUploadResult();
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class ProfileEntrySource : IEntrySource
|
||||
{
|
||||
@ -1,11 +1,10 @@
|
||||
using System.Net.Http.Headers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.Entities;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class ProfileEntryUploadHandler : IEntryUploadHandler
|
||||
{
|
||||
@ -19,12 +18,12 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
if (file is not ProfileConfiguration profileConfiguration)
|
||||
if (entrySource is not ProfileEntrySource source)
|
||||
throw new InvalidOperationException("Can only create releases for profile configurations");
|
||||
|
||||
await using Stream archiveStream = await _profileService.ExportProfile(profileConfiguration);
|
||||
await using Stream archiveStream = await _profileService.ExportProfile(source.ProfileConfiguration);
|
||||
|
||||
// Submit the archive
|
||||
HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user