Workshop - Redesigned library

Workshop - Limit screen width to keep main content at 1000px
Workshop - Auto-updating WIP
This commit is contained in:
Robert committed 2024-07-13 20:25:40 +02:00
1 parent 4552b3ba17
commit 99d11e1921
37 files changed
+955 -200

No files matched your search

@@ -73,7 +73,7 @@ public class LayoutEntryInstallationHandler : IEntryInstallationHandler
// Remove the layout from any devices currently using it
foreach (ArtemisDevice device in _deviceService.Devices)
{
if (device.LayoutSelection.Type == WorkshopLayoutProvider.LayoutType && device.LayoutSelection.Parameter == installedEntry.EntryId.ToString())
if (device.LayoutSelection.Type == WorkshopLayoutProvider.LayoutType && device.LayoutSelection.Parameter == installedEntry.Id.ToString())
{
_defaultLayoutProvider.ConfigureDevice(device);
_deviceService.SaveDevice(device);
@@ -6,9 +6,18 @@ using Artemis.Storage.Entities.Workshop;
namespace Artemis.WebClient.Workshop.Models;
public class InstalledEntry
public class InstalledEntry : CorePropertyChanged, IEntrySummary
{
private Dictionary<string, JsonNode> _metadata = new();
private long _id;
private string _author;
private string _name;
private string _summary;
private EntryType _entryType;
private long _downloads;
private DateTimeOffset _createdAt;
private long? _latestReleaseId;
private IReadOnlyList<IGetDependantEntries_Entries_Items_Categories> _categories;
internal InstalledEntry(EntryEntity entity)
{
@@ -20,55 +29,58 @@ public class InstalledEntry
{
Entity = new EntryEntity();
EntryId = entry.Id;
EntryType = entry.EntryType;
Author = entry.Author;
Name = entry.Name;
ApplyEntrySummary(entry);
InstalledAt = DateTimeOffset.Now;
ReleaseId = release.Id;
ReleaseVersion = release.Version;
AutoUpdate = true;
}
public long EntryId { get; set; }
public EntryType EntryType { get; set; }
public string Author { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public long ReleaseId { get; set; }
public string ReleaseVersion { get; set; } = string.Empty;
public DateTimeOffset InstalledAt { get; set; }
public bool AutoUpdate { get; set; }
internal EntryEntity Entity { get; }
internal void Load()
{
EntryId = Entity.EntryId;
EntryType = (EntryType) Entity.EntryType;
Id = Entity.EntryId;
Author = Entity.Author;
Name = Entity.Name;
Summary = Entity.Summary;
EntryType = (EntryType) Entity.EntryType;
Downloads = Entity.Downloads;
CreatedAt = Entity.CreatedAt;
LatestReleaseId = Entity.LatestReleaseId;
Categories = Entity.Categories?.Select(c => new GetDependantEntries_Entries_Items_Categories_Category(c.Name, c.Icon)).ToList() ?? [];
ReleaseId = Entity.ReleaseId;
ReleaseVersion = Entity.ReleaseVersion;
InstalledAt = Entity.InstalledAt;
AutoUpdate = Entity.AutoUpdate;
_metadata = Entity.Metadata != null ? new Dictionary<string, JsonNode>(Entity.Metadata) : new Dictionary<string, JsonNode>();
_metadata = Entity.Metadata != null ? new Dictionary<string, JsonNode>(Entity.Metadata) : [];
}
internal void Save()
{
Entity.EntryId = EntryId;
Entity.EntryId = Id;
Entity.EntryType = (int) EntryType;
Entity.Author = Author;
Entity.Name = Name;
Entity.Summary = Summary;
Entity.Downloads = Downloads;
Entity.CreatedAt = CreatedAt;
Entity.LatestReleaseId = LatestReleaseId;
Entity.Categories = Categories.Select(c => new EntryCategoryEntity(c.Name, c.Icon)).ToList();
Entity.ReleaseId = ReleaseId;
Entity.ReleaseVersion = ReleaseVersion;
Entity.InstalledAt = InstalledAt;
Entity.AutoUpdate = AutoUpdate;
Entity.Metadata = new Dictionary<string, JsonNode>(_metadata);
}
@@ -118,7 +130,7 @@ public class InstalledEntry
/// <returns>The directory info of the directory.</returns>
public DirectoryInfo GetDirectory()
{
return new DirectoryInfo(Path.Combine(Constants.WorkshopFolder, $"{EntryId}-{StringUtilities.UrlFriendly(Name)}"));
return new DirectoryInfo(Path.Combine(Constants.WorkshopFolder, $"{Id}-{StringUtilities.UrlFriendly(Name)}"));
}
/// <summary>
@@ -141,4 +153,84 @@ public class InstalledEntry
ReleaseVersion = release.Version;
InstalledAt = DateTimeOffset.UtcNow;
}
public void ApplyEntrySummary(IEntrySummary entry)
{
Id = entry.Id;
Author = entry.Author;
Name = entry.Name;
Summary = entry.Summary;
EntryType = entry.EntryType;
Downloads = entry.Downloads;
CreatedAt = entry.CreatedAt;
LatestReleaseId = entry.LatestReleaseId;
Categories = entry.Categories;
}
#region Implementation of IEntrySummary
/// <inheritdoc />
public long Id
{
get => _id;
private set => SetAndNotify(ref _id, value);
}
/// <inheritdoc />
public string Author
{
get => _author;
private set => SetAndNotify(ref _author, value);
}
/// <inheritdoc />
public string Name
{
get => _name;
private set => SetAndNotify(ref _name, value);
}
/// <inheritdoc />
public string Summary
{
get => _summary;
private set => SetAndNotify(ref _summary, value);
}
/// <inheritdoc />
public EntryType EntryType
{
get => _entryType;
private set => SetAndNotify(ref _entryType, value);
}
/// <inheritdoc />
public long Downloads
{
get => _downloads;
private set => SetAndNotify(ref _downloads, value);
}
/// <inheritdoc />
public DateTimeOffset CreatedAt
{
get => _createdAt;
private set => SetAndNotify(ref _createdAt, value);
}
/// <inheritdoc />
public long? LatestReleaseId
{
get => _latestReleaseId;
private set => SetAndNotify(ref _latestReleaseId, value);
}
/// <inheritdoc />
public IReadOnlyList<IGetDependantEntries_Entries_Items_Categories> Categories
{
get => _categories;
private set => SetAndNotify(ref _categories, value);
}
#endregion
}
@@ -55,6 +55,6 @@ public class WorkshopLayoutProvider : ILayoutProvider
throw new InvalidOperationException($"Cannot use a workshop entry of type {entry.EntryType} as a layout");
device.LayoutSelection.Type = LayoutType;
device.LayoutSelection.Parameter = entry?.EntryId.ToString();
device.LayoutSelection.Parameter = entry?.Id.ToString();
}
}
@@ -26,4 +26,10 @@ query GetLayoutEntryById($id: Long!) {
...layoutInfo
}
}
}
query GetEntrySummaryById($id: Long!) {
entry(id: $id) {
...entrySummary
}
}
@@ -124,7 +124,7 @@ public interface IWorkshopService
/// Initializes the workshop service.
/// </summary>
void Initialize();
/// <summary>
/// Represents the status of the workshop.
/// </summary>
@@ -133,4 +133,5 @@ public interface IWorkshopService
public event EventHandler<InstalledEntry>? OnInstalledEntrySaved;
public event EventHandler<InstalledEntry>? OnEntryUninstalled;
public event EventHandler<InstalledEntry>? OnEntryInstalled;
}
@@ -178,7 +178,7 @@ public class WorkshopService : IWorkshopService
if (result.IsSuccess)
OnEntryUninstalled?.Invoke(this, installedEntry);
else
_logger.Warning("Failed to uninstall entry {EntryId}: {Message}", installedEntry.EntryId, result.Message);
_logger.Warning("Failed to uninstall entry {EntryId}: {Message}", installedEntry.Id, result.Message);
return result;
}