diff --git a/src/App/Pages/Vault/AddEditPage.xaml b/src/App/Pages/Vault/AddEditPage.xaml index 59d21590d..f690e8a54 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml +++ b/src/App/Pages/Vault/AddEditPage.xaml @@ -348,7 +348,7 @@ - + @@ -383,12 +383,28 @@ + + + + + + - + - + diff --git a/src/App/Pages/Vault/AddEditPage.xaml.cs b/src/App/Pages/Vault/AddEditPage.xaml.cs index 0af305ed6..703bcf147 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml.cs +++ b/src/App/Pages/Vault/AddEditPage.xaml.cs @@ -28,6 +28,7 @@ namespace Bit.App.Pages _cardBrandPicker.ItemDisplayBinding = new Binding("Key"); _cardExpMonthPicker.ItemDisplayBinding = new Binding("Key"); _identityTitlePicker.ItemDisplayBinding = new Binding("Key"); + _folderPicker.ItemDisplayBinding = new Binding("Key"); } protected override async void OnAppearing() diff --git a/src/App/Pages/Vault/AddEditPageViewModel.cs b/src/App/Pages/Vault/AddEditPageViewModel.cs index 6fbe319d0..51a86a024 100644 --- a/src/App/Pages/Vault/AddEditPageViewModel.cs +++ b/src/App/Pages/Vault/AddEditPageViewModel.cs @@ -16,6 +16,7 @@ namespace Bit.App.Pages { private readonly IDeviceActionService _deviceActionService; private readonly ICipherService _cipherService; + private readonly IFolderService _folderService; private readonly IUserService _userService; private readonly IPlatformUtilsService _platformUtilsService; private readonly IAuditService _auditService; @@ -27,6 +28,7 @@ namespace Bit.App.Pages private int _cardBrandSelectedIndex; private int _cardExpMonthSelectedIndex; private int _identityTitleSelectedIndex; + private int _folderSelectedIndex; private string[] _additionalCipherProperties = new string[] { nameof(IsLogin), @@ -60,6 +62,7 @@ namespace Bit.App.Pages { _deviceActionService = ServiceContainer.Resolve("deviceActionService"); _cipherService = ServiceContainer.Resolve("cipherService"); + _folderService = ServiceContainer.Resolve("folderService"); _userService = ServiceContainer.Resolve("userService"); _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); _auditService = ServiceContainer.Resolve("auditService"); @@ -117,6 +120,7 @@ namespace Bit.App.Pages new KeyValuePair(AppResources.Ms, AppResources.Ms), new KeyValuePair(AppResources.Dr, AppResources.Dr), }; + FolderOptions = new List>(); } public Command GeneratePasswordCommand { get; set; } @@ -134,6 +138,7 @@ namespace Bit.App.Pages public List> CardBrandOptions { get; set; } public List> CardExpMonthOptions { get; set; } public List> IdentityTitleOptions { get; set; } + public List> FolderOptions { get; set; } public ExtendedObservableCollection Uris { get; set; } public ExtendedObservableCollection Fields { get; set; } public int TypeSelectedIndex @@ -172,6 +177,15 @@ namespace Bit.App.Pages IdentityTitleChanged(); } } + public int FolderSelectedIndex + { + get => _folderSelectedIndex; + set + { + SetProperty(ref _folderSelectedIndex, value); + FolderChanged(); + } + } public CipherView Cipher { get => _cipher; @@ -217,54 +231,62 @@ namespace Bit.App.Pages public async Task LoadAsync() { // TODO: load collections + var folders = await _folderService.GetAllDecryptedAsync(); + FolderOptions = folders.Select(f => new KeyValuePair(f.Name, f.Id)).ToList(); - if(EditMode) + if(Cipher == null) { - var cipher = await _cipherService.GetAsync(CipherId); - Cipher = await cipher.DecryptAsync(); - - if(Cipher.Card != null) + if(EditMode) { - CardBrandSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.Brand) ? 0 : - CardBrandOptions.FindIndex(k => k.Value == Cipher.Card.Brand); - CardExpMonthSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.ExpMonth) ? 0 : - CardExpMonthOptions.FindIndex(k => k.Value == Cipher.Card.ExpMonth); + var cipher = await _cipherService.GetAsync(CipherId); + Cipher = await cipher.DecryptAsync(); + + FolderSelectedIndex = string.IsNullOrWhiteSpace(Cipher.FolderId) ? FolderOptions.Count - 1 : + FolderOptions.FindIndex(k => k.Value == Cipher.FolderId); ; + if(Cipher.Card != null) + { + CardBrandSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.Brand) ? 0 : + CardBrandOptions.FindIndex(k => k.Value == Cipher.Card.Brand); + CardExpMonthSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.ExpMonth) ? 0 : + CardExpMonthOptions.FindIndex(k => k.Value == Cipher.Card.ExpMonth); + } + if(Cipher.Identity != null) + { + IdentityTitleSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Identity.Title) ? 0 : + IdentityTitleOptions.FindIndex(k => k.Value == Cipher.Identity.Title); + } } - if(Cipher.Identity != null) + else { - IdentityTitleSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Identity.Title) ? 0 : - IdentityTitleOptions.FindIndex(k => k.Value == Cipher.Identity.Title); + Cipher = new CipherView + { + OrganizationId = OrganizationId, + FolderId = FolderId, + Type = Type.GetValueOrDefault(CipherType.Login), + Login = new LoginView(), + Card = new CardView(), + Identity = new IdentityView(), + SecureNote = new SecureNoteView() + }; + Cipher.Login.Uris = new List { new LoginUriView() }; + Cipher.SecureNote.Type = SecureNoteType.Generic; + + TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type); + CardBrandSelectedIndex = 0; + CardExpMonthSelectedIndex = 0; + IdentityTitleSelectedIndex = 0; + FolderSelectedIndex = FolderOptions.Count - 1; + // TODO: org/collection stuff } - } - else - { - Cipher = new CipherView + + if(Cipher.Login.Uris != null) { - OrganizationId = OrganizationId, - FolderId = FolderId, - Type = Type.GetValueOrDefault(CipherType.Login), - Login = new LoginView(), - Card = new CardView(), - Identity = new IdentityView(), - SecureNote = new SecureNoteView() - }; - Cipher.Login.Uris = new List { new LoginUriView() }; - Cipher.SecureNote.Type = SecureNoteType.Generic; - - TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type); - CardBrandSelectedIndex = 0; - CardExpMonthSelectedIndex = 0; - IdentityTitleSelectedIndex = 0; - // TODO: org/collection stuff - } - - if(Cipher.Login.Uris != null) - { - Uris.ResetWithRange(Cipher.Login.Uris); - } - if(Cipher.Fields != null) - { - Fields.ResetWithRange(Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f))); + Uris.ResetWithRange(Cipher.Login.Uris); + } + if(Cipher.Fields != null) + { + Fields.ResetWithRange(Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f))); + } } } @@ -484,6 +506,14 @@ namespace Bit.App.Pages } } + private void FolderChanged() + { + if(Cipher != null && FolderSelectedIndex > -1) + { + Cipher.FolderId = FolderOptions[FolderSelectedIndex].Value; + } + } + private void TriggerCipherChanged() { TriggerPropertyChanged(nameof(Cipher), _additionalCipherProperties); diff --git a/src/App/Resources/AppResources.Designer.cs b/src/App/Resources/AppResources.Designer.cs index 013fff196..793cc35d8 100644 --- a/src/App/Resources/AppResources.Designer.cs +++ b/src/App/Resources/AppResources.Designer.cs @@ -2274,6 +2274,15 @@ namespace Bit.App.Resources { } } + /// + /// Looks up a localized string similar to Miscellaneous. + /// + public static string Miscellaneous { + get { + return ResourceManager.GetString("Miscellaneous", resourceCulture); + } + } + /// /// Looks up a localized string similar to More. /// diff --git a/src/App/Resources/AppResources.resx b/src/App/Resources/AppResources.resx index 9f1a16291..85a6dad6f 100644 --- a/src/App/Resources/AppResources.resx +++ b/src/App/Resources/AppResources.resx @@ -1417,4 +1417,7 @@ Move Up + + Miscellaneous + \ No newline at end of file