From 7e981a61d30e38b0f79ad17a66c48897ba9eafcc Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 15 Mar 2024 17:13:21 +0100 Subject: [PATCH] Storage - Fix new profile creation UI - Fix a crash when dragging and dropping in the sidebar --- src/Artemis.Core/Models/Profile/Folder.cs | 4 +--- src/Artemis.Core/Models/Profile/Layer.cs | 1 - .../ProfileConfiguration.cs | 5 +++- .../Migrations/IProfileMigration.cs | 9 ------- .../Entities/Profile/FolderEntity.cs | 5 +--- .../Entities/Profile/LayerEntity.cs | 5 +--- .../ArtemisDbContextModelSnapshot.cs | 24 +++++++++---------- .../Repositories/ProfileRepository.cs | 5 ++++ .../Sidebar/SidebarCategoryViewModel.cs | 3 +++ 9 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 src/Artemis.Storage.Legacy/Migrations/IProfileMigration.cs diff --git a/src/Artemis.Core/Models/Profile/Folder.cs b/src/Artemis.Core/Models/Profile/Folder.cs index a845bd331..99ea6f0e1 100644 --- a/src/Artemis.Core/Models/Profile/Folder.cs +++ b/src/Artemis.Core/Models/Profile/Folder.cs @@ -363,9 +363,7 @@ internal override void Save() FolderEntity.Name = Name; FolderEntity.IsExpanded = IsExpanded; FolderEntity.Suspended = Suspended; - - FolderEntity.ProfileId = Profile.EntityId; - + SaveRenderElement(); } diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 2f7de1d48..bed5609f5 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -321,7 +321,6 @@ internal override void Save() LayerEntity.Order = Order; LayerEntity.Suspended = Suspended; LayerEntity.Name = Name; - LayerEntity.ProfileId = Profile.EntityId; General.ApplyToEntity(); Transform.ApplyToEntity(); diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs index 521561610..06e0dd205 100644 --- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs +++ b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs @@ -41,6 +41,9 @@ internal ProfileConfiguration(ProfileCategory category, string name, string icon Icon = new ProfileConfigurationIcon(Entity); Icon.SetIconByName(icon); ActivationCondition = new NodeScript("Activate profile", "Whether or not the profile should be active", this); + + Entity.Profile.Id = Guid.NewGuid(); + Entity.ProfileConfiguration.ProfileId = Entity.Profile.Id; } internal ProfileConfiguration(ProfileCategory category, ProfileContainerEntity entity) @@ -188,7 +191,7 @@ public Module? Module /// alongside any activation requirements of the , if set /// public NodeScript ActivationCondition { get; } - + /// /// Gets the entity used by this profile config /// diff --git a/src/Artemis.Storage.Legacy/Migrations/IProfileMigration.cs b/src/Artemis.Storage.Legacy/Migrations/IProfileMigration.cs deleted file mode 100644 index 53d1d1eda..000000000 --- a/src/Artemis.Storage.Legacy/Migrations/IProfileMigration.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Text.Json.Nodes; - -namespace Artemis.Storage.Legacy.Migrations; - -public interface IProfileMigration -{ - int Version { get; } - void Migrate(JsonObject configurationJson, JsonObject profileJson); -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/FolderEntity.cs b/src/Artemis.Storage/Entities/Profile/FolderEntity.cs index f761dd98b..5be25e526 100644 --- a/src/Artemis.Storage/Entities/Profile/FolderEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/FolderEntity.cs @@ -1,5 +1,4 @@ -using System; -using Artemis.Storage.Entities.Profile.Abstract; +using Artemis.Storage.Entities.Profile.Abstract; namespace Artemis.Storage.Entities.Profile; @@ -9,6 +8,4 @@ public class FolderEntity : RenderElementEntity public string? Name { get; set; } public bool IsExpanded { get; set; } public bool Suspended { get; set; } - - public Guid ProfileId { get; set; } } \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs index d7e9dfe09..bc47ca40d 100644 --- a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Artemis.Storage.Entities.Profile.Abstract; using Artemis.Storage.Entities.Profile.AdaptionHints; @@ -23,6 +22,4 @@ public LayerEntity() public PropertyGroupEntity? GeneralPropertyGroup { get; set; } public PropertyGroupEntity? TransformPropertyGroup { get; set; } public LayerBrushEntity? LayerBrush { get; set; } - - public Guid ProfileId { get; set; } } \ No newline at end of file diff --git a/src/Artemis.Storage/Migrations/ArtemisDbContextModelSnapshot.cs b/src/Artemis.Storage/Migrations/ArtemisDbContextModelSnapshot.cs index 270d88797..fbda34982 100644 --- a/src/Artemis.Storage/Migrations/ArtemisDbContextModelSnapshot.cs +++ b/src/Artemis.Storage/Migrations/ArtemisDbContextModelSnapshot.cs @@ -38,7 +38,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Version") .IsUnique(); - b.ToTable("Releases"); + b.ToTable("Releases", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Plugins.PluginEntity", b => @@ -58,7 +58,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("PluginGuid") .IsUnique(); - b.ToTable("Plugins"); + b.ToTable("Plugins", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Plugins.PluginFeatureEntity", b => @@ -81,7 +81,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("PluginEntityId"); - b.ToTable("PluginFeatures"); + b.ToTable("PluginFeatures", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Plugins.PluginSettingEntity", b => @@ -109,7 +109,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Name", "PluginGuid") .IsUnique(); - b.ToTable("PluginSettings"); + b.ToTable("PluginSettings", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Profile.ProfileCategoryEntity", b => @@ -137,7 +137,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Name") .IsUnique(); - b.ToTable("ProfileCategories"); + b.ToTable("ProfileCategories", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Profile.ProfileContainerEntity", b => @@ -165,7 +165,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("ProfileCategoryId"); - b.ToTable("ProfileContainers"); + b.ToTable("ProfileContainers", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Surface.DeviceEntity", b => @@ -227,7 +227,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("Devices"); + b.ToTable("Devices", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Workshop.EntryEntity", b => @@ -268,7 +268,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("EntryId") .IsUnique(); - b.ToTable("Entries"); + b.ToTable("Entries", (string)null); }); modelBuilder.Entity("Artemis.Storage.Entities.Plugins.PluginFeatureEntity", b => @@ -291,7 +291,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Artemis.Storage.Entities.Surface.DeviceEntity", b => { - b.OwnsOne("System.Collections.Generic.List", "InputIdentifiers", b1 => + b.OwnsOne("Artemis.Storage.Entities.Surface.DeviceEntity.InputIdentifiers#System.Collections.Generic.List", "InputIdentifiers", b1 => { b1.Property("DeviceEntityId") .HasColumnType("TEXT"); @@ -301,7 +301,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b1.HasKey("DeviceEntityId"); - b1.ToTable("Devices"); + b1.ToTable("Devices", (string)null); b1.ToJson("InputIdentifiers"); @@ -309,7 +309,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("DeviceEntityId"); }); - b.OwnsOne("System.Collections.Generic.List", "InputMappings", b1 => + b.OwnsOne("Artemis.Storage.Entities.Surface.DeviceEntity.InputMappings#System.Collections.Generic.List", "InputMappings", b1 => { b1.Property("DeviceEntityId") .HasColumnType("TEXT"); @@ -319,7 +319,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b1.HasKey("DeviceEntityId"); - b1.ToTable("Devices"); + b1.ToTable("Devices", (string)null); b1.ToJson("InputMappings"); diff --git a/src/Artemis.Storage/Repositories/ProfileRepository.cs b/src/Artemis.Storage/Repositories/ProfileRepository.cs index 84e72cb2b..dd129e23e 100644 --- a/src/Artemis.Storage/Repositories/ProfileRepository.cs +++ b/src/Artemis.Storage/Repositories/ProfileRepository.cs @@ -30,6 +30,8 @@ public void Remove(ProfileContainerEntity profileContainerEntity) public void Save(ProfileContainerEntity profileContainerEntity) { + profileContainerEntity.ProfileConfiguration.Version = profileMigrators.Max(m => m.Version); + using ArtemisDbContext dbContext = getContext(); dbContext.Update(profileContainerEntity); dbContext.SaveChanges(); @@ -37,6 +39,9 @@ public void Save(ProfileContainerEntity profileContainerEntity) public void SaveRange(List profileContainerEntities) { + foreach (ProfileContainerEntity profileContainerEntity in profileContainerEntities) + profileContainerEntity.ProfileConfiguration.Version = profileMigrators.Max(m => m.Version); + using ArtemisDbContext dbContext = getContext(); dbContext.UpdateRange(profileContainerEntities); dbContext.SaveChanges(); diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs index fe6cf2d9e..9ad46d8ce 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs @@ -105,6 +105,9 @@ public SidebarCategoryViewModel(ProfileCategory profileCategory, IProfileService public void AddProfileConfiguration(ProfileConfiguration profileConfiguration, ProfileConfiguration? target) { + if (profileConfiguration == target) + return; + ProfileCategory oldCategory = profileConfiguration.Category; ProfileCategory.AddProfileConfiguration(profileConfiguration, target);