site searching from vault folder view
This commit is contained in:
parent
1caa2312c8
commit
88deaed83f
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
.controller('vaultViewFolderController', function ($scope, siteService, folderService, $q, $state, $stateParams, toastr,
|
.controller('vaultViewFolderController', function ($scope, siteService, folderService, $q, $state, $stateParams, toastr,
|
||||||
syncService, $analytics, i18nService) {
|
syncService, $analytics, i18nService) {
|
||||||
var pageSize = 100;
|
var pageSize = 100,
|
||||||
|
decFolder = null,
|
||||||
|
decSites = [];
|
||||||
|
|
||||||
$scope.folder = {
|
$scope.folder = {
|
||||||
id: $stateParams.folderId || null,
|
id: $stateParams.folderId || null,
|
||||||
|
@ -18,8 +20,6 @@
|
||||||
loadVault();
|
loadVault();
|
||||||
|
|
||||||
function loadVault() {
|
function loadVault() {
|
||||||
var decFolder = null;
|
|
||||||
var decSites = [];
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
if ($scope.folder.id) {
|
if ($scope.folder.id) {
|
||||||
|
@ -35,13 +35,22 @@
|
||||||
|
|
||||||
var sitePromise = $q.when(siteService.getAllDecryptedForFolder($scope.folder.id));
|
var sitePromise = $q.when(siteService.getAllDecryptedForFolder($scope.folder.id));
|
||||||
sitePromise.then(function (sites) {
|
sitePromise.then(function (sites) {
|
||||||
decSites = sites;
|
decSites = sites.sort(siteSort);
|
||||||
});
|
});
|
||||||
promises.push(sitePromise);
|
promises.push(sitePromise);
|
||||||
|
|
||||||
$q.all(promises).then(function () {
|
$q.all(promises).then(function () {
|
||||||
$scope.loaded = true;
|
$scope.loaded = true;
|
||||||
$scope.vaultSites = decSites.sort(function (a, b) {
|
$scope.vaultSites = decSites;
|
||||||
|
|
||||||
|
if (decFolder) {
|
||||||
|
$scope.folder.name = decFolder.name;
|
||||||
|
}
|
||||||
|
setScrollY();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function siteSort(a, b) {
|
||||||
if (!a.name) {
|
if (!a.name) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -76,13 +85,6 @@
|
||||||
|
|
||||||
// a must be equal to b
|
// a must be equal to b
|
||||||
return 0;
|
return 0;
|
||||||
});;
|
|
||||||
|
|
||||||
if (decFolder) {
|
|
||||||
$scope.folder.name = decFolder.name;
|
|
||||||
}
|
|
||||||
setScrollY();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.loadMore = function () {
|
$scope.loadMore = function () {
|
||||||
|
@ -100,12 +102,28 @@
|
||||||
|
|
||||||
$scope.searchSites = function () {
|
$scope.searchSites = function () {
|
||||||
if (!$scope.searchText || $scope.searchText.length < 2) {
|
if (!$scope.searchText || $scope.searchText.length < 2) {
|
||||||
|
if ($scope.vaultSites.length !== decSites.length) {
|
||||||
|
resetList(decSites);
|
||||||
|
}
|
||||||
return;
|
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) {
|
function searchSite(site) {
|
||||||
var searchTerm = $scope.searchText.toLowerCase();
|
var searchTerm = $scope.searchText.toLowerCase();
|
||||||
if (site.name && site.name.toLowerCase().indexOf(searchTerm) !== -1) {
|
if (site.name && site.name.toLowerCase().indexOf(searchTerm) !== -1) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<a href="" ng-click="addSite()"><i class="fa fa-plus fa-lg"></i></a>
|
<a href="" ng-click="addSite()"><i class="fa fa-plus fa-lg"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="search">
|
<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>
|
<i class="fa fa-search"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue