From 88deaed83fb010df7381bebc2f94780ffb4c4a73 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 7 Dec 2016 23:20:49 -0500 Subject: [PATCH] site searching from vault folder view --- .../app/vault/vaultViewFolderController.js | 100 +++++++++++------- .../app/vault/views/vaultViewFolder.html | 2 +- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/popup/app/vault/vaultViewFolderController.js b/src/popup/app/vault/vaultViewFolderController.js index f03a223120..67d011467f 100644 --- a/src/popup/app/vault/vaultViewFolderController.js +++ b/src/popup/app/vault/vaultViewFolderController.js @@ -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) { diff --git a/src/popup/app/vault/views/vaultViewFolder.html b/src/popup/app/vault/views/vaultViewFolder.html index de12f11c15..8a38b49205 100644 --- a/src/popup/app/vault/views/vaultViewFolder.html +++ b/src/popup/app/vault/views/vaultViewFolder.html @@ -6,7 +6,7 @@