1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-08 09:32:07 +01:00

site searching from vault folder view

This commit is contained in:
Kyle Spearrin 2016-12-07 23:20:49 -05:00
parent 1caa2312c8
commit 88deaed83f
2 changed files with 60 additions and 42 deletions

View File

@ -3,7 +3,9 @@
.controller('vaultViewFolderController', function ($scope, siteService, folderService, $q, $state, $stateParams, toastr,
syncService, $analytics, i18nService) {
var pageSize = 100;
var pageSize = 100,
decFolder = null,
decSites = [];
$scope.folder = {
id: $stateParams.folderId || null,
@ -18,8 +20,6 @@
loadVault();
function loadVault() {
var decFolder = null;
var decSites = [];
var promises = [];
if ($scope.folder.id) {
@ -35,48 +35,13 @@
var sitePromise = $q.when(siteService.getAllDecryptedForFolder($scope.folder.id));
sitePromise.then(function (sites) {
decSites = sites;
decSites = sites.sort(siteSort);
});
promises.push(sitePromise);
$q.all(promises).then(function () {
$scope.loaded = true;
$scope.vaultSites = decSites.sort(function (a, b) {
if (!a.name) {
return -1;
}
if (!b.name) {
return 1;
}
var aName = a.name.toLowerCase(),
bName = b.name.toLowerCase();
if (aName > bName) {
return 1;
}
if (aName < bName) {
return -1;
}
if (!a.username) {
return -1;
}
if (!b.username) {
return 1;
}
var aUsername = a.username.toLowerCase(),
bUsername = b.username.toLowerCase();
if (aUsername > bUsername) {
return 1;
}
if (aUsername < bUsername) {
return -1;
}
// a must be equal to b
return 0;
});;
$scope.vaultSites = decSites;
if (decFolder) {
$scope.folder.name = decFolder.name;
@ -85,6 +50,43 @@
});
}
function siteSort(a, b) {
if (!a.name) {
return -1;
}
if (!b.name) {
return 1;
}
var aName = a.name.toLowerCase(),
bName = b.name.toLowerCase();
if (aName > bName) {
return 1;
}
if (aName < bName) {
return -1;
}
if (!a.username) {
return -1;
}
if (!b.username) {
return 1;
}
var aUsername = a.username.toLowerCase(),
bUsername = b.username.toLowerCase();
if (aUsername > bUsername) {
return 1;
}
if (aUsername < bUsername) {
return -1;
}
// a must be equal to b
return 0;
}
$scope.loadMore = function () {
var pagedLength = $scope.pagedVaultSites.length;
if ($scope.vaultSites.length > pagedLength) {
@ -100,12 +102,28 @@
$scope.searchSites = function () {
if (!$scope.searchText || $scope.searchText.length < 2) {
if ($scope.vaultSites.length !== decSites.length) {
resetList(decSites);
}
return;
}
return searchSite;
var matchedSites = [];
for (var i = 0; i < decSites.length; i++) {
if (searchSite(decSites[i])) {
matchedSites.push(decSites[i]);
}
}
resetList(matchedSites);
};
function resetList(sites) {
$scope.vaultSites = sites;
$scope.pagedVaultSites = [];
$scope.loadMore();
}
function searchSite(site) {
var searchTerm = $scope.searchText.toLowerCase();
if (site.name && site.name.toLowerCase().indexOf(searchTerm) !== -1) {

View File

@ -6,7 +6,7 @@
<a href="" ng-click="addSite()"><i class="fa fa-plus fa-lg"></i></a>
</div>
<div class="search">
<input type="search" placeholder="{{i18n.searchFolder}}" ng-model="searchText" id="search" />
<input type="search" placeholder="{{i18n.searchFolder}}" ng-model="searchText" ng-change="searchSites()" id="search" />
<i class="fa fa-search"></i>
</div>
</div>