From e61a0314858792359c65efe7a2bbd7c0ce27d66a Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 17 Dec 2020 21:09:42 +0100 Subject: [PATCH] Profile editor - Added profile rename Profile editor - Cleaned up buttons next to profile selection --- .../Models/Profile/ProfileDescriptor.cs | 41 ++++++---- src/Artemis.UI/Artemis.UI.csproj | 3 + .../Dialogs/ProfileEditView.xaml | 29 ++++++++ .../Dialogs/ProfileEditViewModel.cs | 42 +++++++++++ .../Dialogs/ProfileExportView.xaml | 12 ++- .../Dialogs/ProfileImportView.xaml | 12 ++- .../ProfileEditor/ProfileEditorView.xaml | 74 ++++++++++--------- .../ProfileEditor/ProfileEditorViewModel.cs | 17 ++++- 8 files changed, 174 insertions(+), 56 deletions(-) create mode 100644 src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditView.xaml create mode 100644 src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditViewModel.cs diff --git a/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs b/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs index ee5c67b87..7898eeae2 100644 --- a/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs +++ b/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs @@ -7,35 +7,44 @@ namespace Artemis.Core /// /// Represents a descriptor that describes a profile /// - public class ProfileDescriptor + public class ProfileDescriptor : CorePropertyChanged { + private readonly ProfileEntity _profileEntity; + internal ProfileDescriptor(ProfileModule profileModule, ProfileEntity profileEntity) { + _profileEntity = profileEntity; ProfileModule = profileModule; - - Id = profileEntity.Id; - Name = profileEntity.Name; - IsLastActiveProfile = profileEntity.IsActive; } - /// - /// Gets a boolean indicating whether this was the last active profile - /// - public bool IsLastActiveProfile { get; } - - /// - /// Gets the unique ID of the profile by which it can be loaded from storage - /// - public Guid Id { get; } - /// /// Gets the module backing the profile /// public ProfileModule ProfileModule { get; } + /// + /// Gets the unique ID of the profile by which it can be loaded from storage + /// + public Guid Id => _profileEntity.Id; + /// /// Gets the name of the profile /// - public string Name { get; } + public string Name => _profileEntity.Name; + + /// + /// Gets a boolean indicating whether this was the last active profile + /// + public bool IsLastActiveProfile => _profileEntity.IsActive; + + /// + /// Triggers a property change for all properties linked to the backing profile entity ¯\_(ツ)_/¯ + /// + public void Update() + { + OnPropertyChanged(nameof(Id)); + OnPropertyChanged(nameof(Name)); + OnPropertyChanged(nameof(IsLastActiveProfile)); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 23cbc872d..85bc20796 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -338,5 +338,8 @@ Designer + + $(DefaultXamlRuntime) + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditView.xaml new file mode 100644 index 000000000..9950f9ae3 --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditView.xaml @@ -0,0 +1,29 @@ + + + + Edit profile + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditViewModel.cs new file mode 100644 index 000000000..5fc6693d9 --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileEditViewModel.cs @@ -0,0 +1,42 @@ +using System.Threading.Tasks; +using Artemis.Core; +using Artemis.UI.Shared.Services; +using FluentValidation; +using Stylet; + +namespace Artemis.UI.Screens.ProfileEditor.Dialogs +{ + public class ProfileEditViewModel : DialogViewModelBase + { + private string _profileName; + + public ProfileEditViewModel(IModelValidator validator, Profile profile) : base(validator) + { + ProfileName = profile.Name; + } + + public string ProfileName + { + get => _profileName; + set => SetAndNotify(ref _profileName, value); + } + + public async Task Accept() + { + await ValidateAsync(); + + if (HasErrors) + return; + + Session.Close(ProfileName); + } + } + + public class ProfileEditViewModelValidator : AbstractValidator + { + public ProfileEditViewModelValidator() + { + RuleFor(m => m.ProfileName).NotEmpty().WithMessage("Profile name may not be empty"); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportView.xaml index 443e23fab..7e67d06c8 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportView.xaml @@ -17,11 +17,19 @@ Export current profile - + Please note that exporting profiles like this is placeholder functionality. The idea is that this will eventually happen via the workshop. - + The workshop will include tools to make profiles convert easily and look good on different layouts. That means right now when someone imports this export unless they have the exact same setup as you, they'll have to select LEDs for each layer in the profile. diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportView.xaml index cf8bc9e5a..fbf9ad5e3 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportView.xaml @@ -19,11 +19,19 @@ Import profile to current module - + Please note that importing profiles like this is placeholder functionality. The idea is that this will eventually happen via the workshop. - + The workshop will include tools to make profiles convert easily and look good on different layouts. That means right now when you import this profile unless you have the exact same setup as the person who exported it, you'll have to select LEDs for each layer in the profile. diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml index b135d570e..3a47534f6 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml @@ -123,8 +123,6 @@ - - - - - - + + + + + + + + + + + diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs index 24532605a..fea7338c5 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs @@ -182,6 +182,21 @@ namespace Artemis.UI.Screens.ProfileEditor RemoveProfile(SelectedProfile); } + public async Task RenameActiveProfile() + { + if (_profileEditorService.SelectedProfile == null) + return; + + Profile profile = _profileEditorService.SelectedProfile; + object result = await DialogService.ShowDialog(new Dictionary {{"profile", profile}}); + if (result is string name) + { + profile.Name = name; + _profileEditorService.UpdateSelectedProfile(); + SelectedProfile.Update(); + } + } + public async Task ExportActiveProfile() { await DialogService.ShowDialog(new Dictionary @@ -228,7 +243,7 @@ namespace Artemis.UI.Screens.ProfileEditor await Task.Delay(50); focusedElement?.Focus(); }); - + _snackbarMessageQueue.Enqueue("Undid profile update", "REDO", Redo); }