From a4578469157e7f6826addce0e4af5ba053464f3a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 22 Nov 2017 17:54:24 -0500 Subject: [PATCH] display favorites and collections in my vault --- src/_locales/en/messages.json | 6 +++ src/popup/app/services/auth.service.ts | 1 + src/popup/app/services/background.service.ts | 1 + src/popup/app/services/services.module.ts | 1 + src/popup/app/vault/vaultController.js | 45 +++++++++++----- src/popup/app/vault/views/vault.html | 56 +++++++++++++++++--- 6 files changed, 89 insertions(+), 21 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 02dab22faec..b67f9ca9d7f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -956,5 +956,11 @@ }, "back": { "message": "Back" + }, + "collections": { + "message": "Collections" + }, + "favorites": { + "message": "Favorites" } } diff --git a/src/popup/app/services/auth.service.ts b/src/popup/app/services/auth.service.ts index 24dfad78689..83441a6f199 100644 --- a/src/popup/app/services/auth.service.ts +++ b/src/popup/app/services/auth.service.ts @@ -67,6 +67,7 @@ class AuthService { logOut(callback: Function) { this.$rootScope.vaultCiphers = null; this.$rootScope.vaultFolders = null; + this.$rootScope.vaultCollections = null; callback(); } } diff --git a/src/popup/app/services/background.service.ts b/src/popup/app/services/background.service.ts index ccf72ebc97f..4693bd0566f 100644 --- a/src/popup/app/services/background.service.ts +++ b/src/popup/app/services/background.service.ts @@ -25,3 +25,4 @@ export const settingsService = getBackgroundService('settingsService'); export const lockService = getBackgroundService('lockService'); export const totpService = getBackgroundService('totpService'); export const environmentService = getBackgroundService('environmentService'); +export const collectionService = getBackgroundService('collectionService'); diff --git a/src/popup/app/services/services.module.ts b/src/popup/app/services/services.module.ts index 051d4d60042..535b9974c31 100644 --- a/src/popup/app/services/services.module.ts +++ b/src/popup/app/services/services.module.ts @@ -27,5 +27,6 @@ export default angular .factory('lockService', backgroundServices.lockService) .factory('totpService', backgroundServices.totpService) .factory('environmentService', backgroundServices.environmentService) + .factory('collectionService', backgroundServices.collectionService) .name; diff --git a/src/popup/app/vault/vaultController.js b/src/popup/app/vault/vaultController.js index e232b6fb4c1..a3629dddd4a 100644 --- a/src/popup/app/vault/vaultController.js +++ b/src/popup/app/vault/vaultController.js @@ -2,12 +2,12 @@ angular .module('bit.vault') .controller('vaultController', function ($scope, $rootScope, cipherService, folderService, $q, $state, $stateParams, toastr, - syncService, utilsService, $analytics, i18nService, stateService, $timeout, $window) { + syncService, utilsService, $analytics, i18nService, stateService, $timeout, $window, collectionService) { var stateKey = 'vault', state = stateService.getState(stateKey) || {}; $scope.i18n = i18nService; - $scope.showFolderCounts = !utilsService.isEdge(); + $scope.showGroupingCounts = !utilsService.isEdge(); $scope.disableSearch = utilsService.isEdge(); document.getElementById('search').focus(); @@ -31,6 +31,11 @@ angular delayLoad = false; $scope.loaded = false; } + if (!$rootScope.vaultCollections) { + $rootScope.vaultCollections = []; + delayLoad = false; + $scope.loaded = false; + } if (delayLoad) { $timeout(setScrollY, 100); @@ -42,29 +47,32 @@ angular function loadVault() { var decFolders = []; + var decCollections = []; var decCiphers = []; - var promises = []; var folderPromise = folderService.getAllDecrypted().then(function (folders) { decFolders = folders; }); - promises.push(folderPromise); + + var collectionPromise = collectionService.getAllDecrypted().then(function (collections) { + decCollections = collections; + }); var cipherPromise = cipherService.getAllDecrypted().then(function (ciphers) { decCiphers = ciphers; }); - promises.push(cipherPromise); - $q.all(promises).then(function () { + $q.all([folderPromise, collectionPromise, cipherPromise]).then(function () { $scope.loaded = true; $rootScope.vaultFolders = decFolders; + $rootScope.vaultCollections = decCollections; $rootScope.vaultCiphers = decCiphers; - if ($scope.showFolderCounts) { - // compute item count for each folder - for (var i = 0; i < decFolders.length; i++) { - var itemCount = 0; - for (var j = 0; j < decCiphers.length; j++) { + if ($scope.showGroupingCounts) { + // compute item count for each grouping + for (let i = 0; i < decFolders.length; i++) { + let itemCount = 0; + for (let j = 0; j < decCiphers.length; j++) { if (decCiphers[j].folderId === decFolders[i].id) { itemCount++; } @@ -72,6 +80,17 @@ angular $rootScope.vaultFolders[i].itemCount = itemCount; } + for (let i = 0; i < decCollections.length; i++) { + let itemCount = 0; + for (let j = 0; j < decCiphers.length; j++) { + if (decCiphers[j].collectionIds && + decCiphers[j].collectionIds.indexOf(decCollections[i].id) > -1) { + itemCount++; + } + } + + $rootScope.vaultCollections[i].itemCount = itemCount; + } } if (!delayLoad) { @@ -153,10 +172,10 @@ angular }, 200); }; - $scope.viewFolder = function (folder) { + $scope.viewGrouping = function (grouping) { storeState(); $state.go('viewFolder', { - folderId: folder.id || '0', + folderId: grouping.id || '0', animation: 'in-slide-left' }); }; diff --git a/src/popup/app/vault/views/vault.html b/src/popup/app/vault/views/vault.html index e27a56d7517..db54feb1765 100644 --- a/src/popup/app/vault/views/vault.html +++ b/src/popup/app/vault/views/vault.html @@ -9,20 +9,60 @@
- +
-
+
+
+ {{::i18n.favorites}} + {{favoriteCiphers.length}} +
+ +
+ +
+
+ {{::i18n.collections}} + {{vaultCollections.length}} +
+