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
{
Task<Folder> GetByIdAsync(int id);
Task<IEnumerable<Folder>> GetAllAsync();
Task SaveAsync(Folder folder);
}

View file

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

View file

@ -16,10 +16,19 @@ namespace Bit.App.Pages
{
var cryptoService = Resolver.Resolve<ICryptoService>();
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 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 passwordEntry = new Entry { IsPassword = true };
var notesEditor = new Editor();
@ -30,7 +39,7 @@ namespace Bit.App.Pages
stackLayout.Children.Add(new Label { Text = "Name" });
stackLayout.Children.Add(nameEntry);
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(usernameEntry);
stackLayout.Children.Add(new Label { Text = "Password" });
@ -64,9 +73,14 @@ namespace Bit.App.Pages
Name = nameEntry.Text.Encrypt(),
Username = usernameEntry.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 Navigation.PopAsync();
}, ToolbarItemOrder.Default, 0);

View file

@ -21,9 +21,19 @@ namespace Bit.App.Pages
_siteService = Resolver.Resolve<ISiteService>();
var addSiteToolBarItem = new ToolbarItem("+", null, async () =>
{
var selection = await DisplayActionSheet("Add", "Cancel", null, "Add New Folder", "Add New Site");
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);
ToolbarItems.Add(addSiteToolBarItem);

View file

@ -20,6 +20,12 @@ namespace Bit.App.Services
_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()
{
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
{
private readonly IAuthService _authService;
private readonly IFolderService _folderService;
public SiteService(
ISqlService sqlService,
IAuthService authService)
IAuthService authService,
IFolderService folderService)
: base(sqlService)
{
_authService = authService;
_folderService = folderService;
}
public new Task<IEnumerable<Site>> GetAllAsync()
@ -31,6 +34,15 @@ namespace Bit.App.Services
var data = new SiteData(site, _authService.UserId);
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)
{
await CreateAsync(data);