Profiles - Reworked profile system

Sidebar - Redesigned sidebar with customizable categories
Profiles - Added the ability to configure custom profile icons
Profiles - Added the ability to activate multiple profiles for modules at once
Profiles - Added the ability to create profiles for no modules
Profiles - Added the ability to suspend a profile or an entire category
Profiles - Added profile activation conditions
Profiles - Added file-based importing/exporting
Profile editor - Condensed UI, removed tabs 
Profile editor - Disable condition operators until a left-side is picked
This commit is contained in:
Robert Beekman authored and GitHub committed 2021-06-03 22:34:43 +02:00
1 parent 4152c290d2
commit ceeaa4bf6d
164 files changed
+5019 -4220

No files matched your search

@@ -1,17 +0,0 @@
using System;
namespace Artemis.Storage.Entities.Module
{
public class ModuleSettingsEntity
{
public ModuleSettingsEntity()
{
Id = Guid.NewGuid();
}
public Guid Id { get; set; }
public string ModuleId { get; set; }
public int PriorityCategory { get; set; }
public int Priority { get; set; }
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile
{
public class ProfileCategoryEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public bool IsCollapsed { get; set; }
public bool IsSuspended { get; set; }
public int Order { get; set; }
public List<ProfileConfigurationEntity> ProfileConfigurations { get; set; } = new();
}
}
@@ -0,0 +1,22 @@
using System;
using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Storage.Entities.Profile
{
public class ProfileConfigurationEntity
{
public string Name { get; set; }
public string MaterialIcon { get; set; }
public Guid FileIconId { get; set; }
public int IconType { get; set; }
public bool IsSuspended { get; set; }
public int ActivationBehaviour { get; set; }
public DataModelConditionGroupEntity ActivationCondition { get; set; }
public string ModuleId { get; set; }
public Guid ProfileCategoryId { get; set; }
public Guid ProfileId { get; set; }
}
}
@@ -13,10 +13,8 @@ namespace Artemis.Storage.Entities.Profile
}
public Guid Id { get; set; }
public string ModuleId { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public bool IsFreshImport { get; set; }
public List<FolderEntity> Folders { get; set; }
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Artemis.Storage.Entities.Module;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
@@ -87,18 +86,6 @@ namespace Artemis.Storage.Migrations
// Remove the default brush the user selected, this will make the UI pick a new one
repository.Database.Execute("DELETE PluginSettingEntity WHERE $.Name = \"ProfileEditor.DefaultLayerBrushDescriptor\"");
// Module settings
repository.Database.GetCollection<ModuleSettingsEntity>().DropIndex("PluginGuid");
ILiteCollection<BsonDocument> modules = repository.Database.GetCollection("ModuleSettingsEntity");
foreach (BsonDocument bsonDocument in modules.FindAll())
{
if (ReplaceIfFound(bsonDocument, "PluginGuid", "ModuleId", pluginMap))
modules.Update(bsonDocument);
else if (bsonDocument.ContainsKey("PluginGuid"))
modules.Delete(bsonDocument["_id"]);
}
repository.Database.GetCollection<ModuleSettingsEntity>().EnsureIndex(s => s.ModuleId, true);
// Profiles
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
@@ -0,0 +1,48 @@
using System.Linq;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0012ProfileCategories : IStorageMigration
{
public int UserVersion => 12;
public void Apply(LiteRepository repository)
{
ILiteCollection<ProfileCategoryEntity> profileCategories = repository.Database.GetCollection<ProfileCategoryEntity>();
profileCategories.EnsureIndex(s => s.Name, true);
ProfileCategoryEntity? profileCategoryEntity = profileCategories.Find(c => c.Name == "Converted").FirstOrDefault();
if (profileCategoryEntity == null)
{
profileCategoryEntity = new ProfileCategoryEntity {Name = "Imported"};
profileCategories.Insert(profileCategoryEntity);
}
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
// Profiles with a ModuleId have not been converted
if (bsonDocument.ContainsKey("ModuleId"))
{
string moduleId = bsonDocument["ModuleId"].AsString;
bsonDocument.Remove("ModuleId");
ProfileConfigurationEntity profileConfiguration = new()
{
Name = bsonDocument["Name"].AsString,
MaterialIcon = "ApplicationImport",
ModuleId = moduleId,
ProfileId = bsonDocument["_id"].AsGuid
};
profileCategoryEntity.ProfileConfigurations.Add(profileConfiguration);
collection.Update(bsonDocument);
}
}
profileCategories.Update(profileCategoryEntity);
}
}
}
@@ -1,14 +0,0 @@
using System.Collections.Generic;
using Artemis.Storage.Entities.Module;
namespace Artemis.Storage.Repositories.Interfaces
{
public interface IModuleRepository : IRepository
{
void Add(ModuleSettingsEntity moduleSettingsEntity);
ModuleSettingsEntity GetByModuleId(string moduleId);
List<ModuleSettingsEntity> GetAll();
List<ModuleSettingsEntity> GetByCategory(int category);
void Save(ModuleSettingsEntity moduleSettingsEntity);
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Storage.Repositories.Interfaces
{
public interface IProfileCategoryRepository : IRepository
{
void Add(ProfileCategoryEntity profileCategoryEntity);
void Remove(ProfileCategoryEntity profileCategoryEntity);
List<ProfileCategoryEntity> GetAll();
ProfileCategoryEntity Get(Guid id);
Stream GetProfileIconStream(Guid id);
void SaveProfileIconStream(ProfileConfigurationEntity profileConfigurationEntity, Stream stream);
ProfileCategoryEntity IsUnique(string name, Guid? id);
void Save(ProfileCategoryEntity profileCategoryEntity);
}
}
@@ -10,7 +10,6 @@ namespace Artemis.Storage.Repositories.Interfaces
void Remove(ProfileEntity profileEntity);
List<ProfileEntity> GetAll();
ProfileEntity Get(Guid id);
List<ProfileEntity> GetByModuleId(string moduleId);
void Save(ProfileEntity profileEntity);
}
}
@@ -1,43 +0,0 @@
using System.Collections.Generic;
using Artemis.Storage.Entities.Module;
using Artemis.Storage.Repositories.Interfaces;
using LiteDB;
namespace Artemis.Storage.Repositories
{
internal class ModuleRepository : IModuleRepository
{
private readonly LiteRepository _repository;
public ModuleRepository(LiteRepository repository)
{
_repository = repository;
_repository.Database.GetCollection<ModuleSettingsEntity>().EnsureIndex(s => s.ModuleId, true);
}
public void Add(ModuleSettingsEntity moduleSettingsEntity)
{
_repository.Insert(moduleSettingsEntity);
}
public ModuleSettingsEntity GetByModuleId(string moduleId)
{
return _repository.FirstOrDefault<ModuleSettingsEntity>(s => s.ModuleId == moduleId);
}
public List<ModuleSettingsEntity> GetAll()
{
return _repository.Query<ModuleSettingsEntity>().ToList();
}
public List<ModuleSettingsEntity> GetByCategory(int category)
{
return _repository.Query<ModuleSettingsEntity>().Where(s => s.PriorityCategory == category).ToList();
}
public void Save(ModuleSettingsEntity moduleSettingsEntity)
{
_repository.Upsert(moduleSettingsEntity);
}
}
}
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Repositories.Interfaces;
using LiteDB;
namespace Artemis.Storage.Repositories
{
internal class ProfileCategoryRepository : IProfileCategoryRepository
{
private readonly LiteRepository _repository;
private readonly ILiteStorage<Guid> _profileIcons;
public ProfileCategoryRepository(LiteRepository repository)
{
_repository = repository;
_repository.Database.GetCollection<ProfileCategoryEntity>().EnsureIndex(s => s.Name, true);
_profileIcons = _repository.Database.GetStorage<Guid>("profileIcons");
}
public void Add(ProfileCategoryEntity profileCategoryEntity)
{
_repository.Insert(profileCategoryEntity);
}
public void Remove(ProfileCategoryEntity profileCategoryEntity)
{
_repository.Delete<ProfileCategoryEntity>(profileCategoryEntity.Id);
}
public List<ProfileCategoryEntity> GetAll()
{
return _repository.Query<ProfileCategoryEntity>().ToList();
}
public ProfileCategoryEntity Get(Guid id)
{
return _repository.FirstOrDefault<ProfileCategoryEntity>(p => p.Id == id);
}
public ProfileCategoryEntity IsUnique(string name, Guid? id)
{
if (id == null)
return _repository.FirstOrDefault<ProfileCategoryEntity>(p => p.Name == name);
return _repository.FirstOrDefault<ProfileCategoryEntity>(p => p.Name == name && p.Id != id.Value);
}
public void Save(ProfileCategoryEntity profileCategoryEntity)
{
_repository.Upsert(profileCategoryEntity);
}
public Stream GetProfileIconStream(Guid id)
{
if (!_profileIcons.Exists(id))
return null;
MemoryStream stream = new();
_profileIcons.Download(id, stream);
return stream;
}
public void SaveProfileIconStream(ProfileConfigurationEntity profileConfigurationEntity, Stream stream)
{
if (profileConfigurationEntity.FileIconId == Guid.Empty)
profileConfigurationEntity.FileIconId = Guid.NewGuid();
if (stream == null && _profileIcons.Exists(profileConfigurationEntity.FileIconId))
_profileIcons.Delete(profileConfigurationEntity.FileIconId);
_profileIcons.Upload(profileConfigurationEntity.FileIconId, "image", stream);
}
}
}
@@ -36,15 +36,6 @@ namespace Artemis.Storage.Repositories
return _repository.FirstOrDefault<ProfileEntity>(p => p.Id == id);
}
public List<ProfileEntity> GetByModuleId(string moduleId)
{
return _repository.Query<ProfileEntity>()
.Include(p => p.Folders)
.Include(p => p.Layers)
.Where(s => s.ModuleId == moduleId)
.ToList();
}
public void Save(ProfileEntity profileEntity)
{
_repository.Upsert(profileEntity);