Add folder page, folder picker on add site page.

This commit is contained in:
Kyle Spearrin 2016-05-02 18:35:01 -04:00
parent e05ed4c1f2
commit c6222c8ed3
6 changed files with 51 additions and 7 deletions

View file

@ -6,6 +6,7 @@ namespace Bit.App.Abstractions
{ {
public interface IFolderService public interface IFolderService
{ {
Task<Folder> GetByIdAsync(int id);
Task<IEnumerable<Folder>> GetAllAsync(); Task<IEnumerable<Folder>> GetAllAsync();
Task SaveAsync(Folder folder); Task SaveAsync(Folder folder);
} }

View file

@ -39,8 +39,9 @@ namespace Bit.App.Pages
var folder = new Folder var folder = new Folder
{ {
Name = new CipherString(nameEntry.Text) Name = nameEntry.Text.Encrypt()
}; };
await folderService.SaveAsync(folder); await folderService.SaveAsync(folder);
await Navigation.PopAsync(); await Navigation.PopAsync();
}, ToolbarItemOrder.Default, 0); }, ToolbarItemOrder.Default, 0);

View file

@ -16,10 +16,19 @@ namespace Bit.App.Pages
{ {
var cryptoService = Resolver.Resolve<ICryptoService>(); var cryptoService = Resolver.Resolve<ICryptoService>();
var siteService = Resolver.Resolve<ISiteService>(); var siteService = Resolver.Resolve<ISiteService>();
var folderService = Resolver.Resolve<IFolderService>();
var folders = folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name);
var uriEntry = new Entry { Keyboard = Keyboard.Url }; var uriEntry = new Entry { Keyboard = Keyboard.Url };
var nameEntry = new Entry(); var nameEntry = new Entry();
var folderEntry = new Entry { }; var folderPicker = new Picker { Title = "Folder" };
folderPicker.Items.Add("(none)");
folderPicker.SelectedIndex = 0;
foreach(var folder in folders)
{
folderPicker.Items.Add(folder.Name.Decrypt());
}
var usernameEntry = new Entry(); var usernameEntry = new Entry();
var passwordEntry = new Entry { IsPassword = true }; var passwordEntry = new Entry { IsPassword = true };
var notesEditor = new Editor(); var notesEditor = new Editor();
@ -30,7 +39,7 @@ namespace Bit.App.Pages
stackLayout.Children.Add(new Label { Text = "Name" }); stackLayout.Children.Add(new Label { Text = "Name" });
stackLayout.Children.Add(nameEntry); stackLayout.Children.Add(nameEntry);
stackLayout.Children.Add(new Label { Text = "Folder" }); stackLayout.Children.Add(new Label { Text = "Folder" });
stackLayout.Children.Add(folderEntry); stackLayout.Children.Add(folderPicker);
stackLayout.Children.Add(new Label { Text = "Username" }); stackLayout.Children.Add(new Label { Text = "Username" });
stackLayout.Children.Add(usernameEntry); stackLayout.Children.Add(usernameEntry);
stackLayout.Children.Add(new Label { Text = "Password" }); stackLayout.Children.Add(new Label { Text = "Password" });
@ -64,9 +73,14 @@ namespace Bit.App.Pages
Name = nameEntry.Text.Encrypt(), Name = nameEntry.Text.Encrypt(),
Username = usernameEntry.Text?.Encrypt(), Username = usernameEntry.Text?.Encrypt(),
Password = passwordEntry.Text?.Encrypt(), Password = passwordEntry.Text?.Encrypt(),
Notes = notesEditor.Text?.Encrypt() Notes = notesEditor.Text?.Encrypt(),
}; };
if(folderPicker.SelectedIndex > 0)
{
site.FolderId = folders.ElementAt(folderPicker.SelectedIndex - 1).Id;
}
await siteService.SaveAsync(site); await siteService.SaveAsync(site);
await Navigation.PopAsync(); await Navigation.PopAsync();
}, ToolbarItemOrder.Default, 0); }, ToolbarItemOrder.Default, 0);

View file

@ -22,8 +22,18 @@ namespace Bit.App.Pages
var addSiteToolBarItem = new ToolbarItem("+", null, async () => var addSiteToolBarItem = new ToolbarItem("+", null, async () =>
{ {
var addSitePage = new VaultAddSitePage(); var selection = await DisplayActionSheet("Add", "Cancel", null, "Add New Folder", "Add New Site");
await Navigation.PushAsync(addSitePage); if(selection == "Add New Folder")
{
var addFolderPage = new VaultAddFolderPage();
await Navigation.PushAsync(addFolderPage);
}
else
{
var addSitePage = new VaultAddSitePage();
await Navigation.PushAsync(addSitePage);
}
}, ToolbarItemOrder.Default, 0); }, ToolbarItemOrder.Default, 0);
ToolbarItems.Add(addSiteToolBarItem); ToolbarItems.Add(addSiteToolBarItem);

View file

@ -20,6 +20,12 @@ namespace Bit.App.Services
_authService = authService; _authService = authService;
} }
public new Task<Folder> GetByIdAsync(int id)
{
var data = Connection.Table<FolderData>().Where(f => f.UserId == _authService.UserId && f.Id == id).FirstOrDefault();
return Task.FromResult(new Folder(data));
}
public new Task<IEnumerable<Folder>> GetAllAsync() public new Task<IEnumerable<Folder>> GetAllAsync()
{ {
var data = Connection.Table<FolderData>().Where(f => f.UserId == _authService.UserId).Cast<FolderData>(); var data = Connection.Table<FolderData>().Where(f => f.UserId == _authService.UserId).Cast<FolderData>();

View file

@ -11,13 +11,16 @@ namespace Bit.App.Services
public class SiteService : Repository<SiteData, int>, ISiteService public class SiteService : Repository<SiteData, int>, ISiteService
{ {
private readonly IAuthService _authService; private readonly IAuthService _authService;
private readonly IFolderService _folderService;
public SiteService( public SiteService(
ISqlService sqlService, ISqlService sqlService,
IAuthService authService) IAuthService authService,
IFolderService folderService)
: base(sqlService) : base(sqlService)
{ {
_authService = authService; _authService = authService;
_folderService = folderService;
} }
public new Task<IEnumerable<Site>> GetAllAsync() public new Task<IEnumerable<Site>> GetAllAsync()
@ -31,6 +34,15 @@ namespace Bit.App.Services
var data = new SiteData(site, _authService.UserId); var data = new SiteData(site, _authService.UserId);
data.RevisionDateTime = DateTime.UtcNow; data.RevisionDateTime = DateTime.UtcNow;
if(site.FolderId.HasValue && site.ServerFolderId == null)
{
var folder = await _folderService.GetByIdAsync(site.FolderId.Value);
if(folder != null)
{
site.ServerFolderId = folder.ServerId;
}
}
if(site.Id == 0) if(site.Id == 0)
{ {
await CreateAsync(data); await CreateAsync(data);