misc section with folders

This commit is contained in:
Kyle Spearrin 2019-05-09 12:18:23 -04:00
parent b07afa7f11
commit fb5c36071d
5 changed files with 103 additions and 44 deletions

View file

@ -348,7 +348,7 @@
<controls:RepeaterView ItemsSource="{Binding Uris}">
<controls:RepeaterView.ItemTemplate>
<DataTemplate x:DataType="views:LoginUriView">
<Grid StyleClass="box-row">
<Grid StyleClass="box-row, box-row-input">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
@ -383,12 +383,28 @@
<Button Text="{u:I18n NewUri}" StyleClass="box-button-row"
Clicked="NewUri_Clicked"></Button>
</StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Miscellaneous}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input">
<Label
Text="{u:I18n Folder}"
StyleClass="box-label" />
<Picker
x:Name="_folderPicker"
ItemsSource="{Binding FolderOptions, Mode=OneTime}"
SelectedIndex="{Binding FolderSelectedIndex}"
StyleClass="box-value" />
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Notes}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
<StackLayout StyleClass="box-row">
<StackLayout StyleClass="box-row, box-row-input">
<Editor
Text="{Binding Cipher.Notes}"
StyleClass="box-value"
@ -404,7 +420,7 @@
<controls:RepeaterView.ItemTemplate>
<DataTemplate x:DataType="pages:AddEditPageFieldViewModel">
<StackLayout Spacing="0" Padding="0">
<Grid StyleClass="box-row">
<Grid StyleClass="box-row, box-row-input">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />

View file

@ -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()

View file

@ -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<IDeviceActionService>("deviceActionService");
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
_folderService = ServiceContainer.Resolve<IFolderService>("folderService");
_userService = ServiceContainer.Resolve<IUserService>("userService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_auditService = ServiceContainer.Resolve<IAuditService>("auditService");
@ -117,6 +120,7 @@ namespace Bit.App.Pages
new KeyValuePair<string, string>(AppResources.Ms, AppResources.Ms),
new KeyValuePair<string, string>(AppResources.Dr, AppResources.Dr),
};
FolderOptions = new List<KeyValuePair<string, string>>();
}
public Command GeneratePasswordCommand { get; set; }
@ -134,6 +138,7 @@ namespace Bit.App.Pages
public List<KeyValuePair<string, string>> CardBrandOptions { get; set; }
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
public List<KeyValuePair<string, string>> IdentityTitleOptions { get; set; }
public List<KeyValuePair<string, string>> FolderOptions { get; set; }
public ExtendedObservableCollection<LoginUriView> Uris { get; set; }
public ExtendedObservableCollection<AddEditPageFieldViewModel> 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<string, string>(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<LoginUriView> { 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<LoginUriView> { 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);

View file

@ -2274,6 +2274,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Miscellaneous.
/// </summary>
public static string Miscellaneous {
get {
return ResourceManager.GetString("Miscellaneous", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to More.
/// </summary>

View file

@ -1417,4 +1417,7 @@
<data name="MoveUp" xml:space="preserve">
<value>Move Up</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>