1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-16 10:35:31 +01:00

tracking vault state with stateService

This commit is contained in:
Kyle Spearrin 2016-12-08 00:56:38 -05:00
parent ced707647f
commit e414dd1867
9 changed files with 80 additions and 75 deletions

View File

@ -75,7 +75,7 @@
url: '/vault',
templateUrl: 'app/vault/views/vault.html',
controller: 'vaultController',
params: { scrollY: 0, searchText: null, syncOnLoad: false }
params: { syncOnLoad: false }
})
.state('tabs.settings', {
url: '/settings',
@ -93,24 +93,21 @@
templateUrl: 'app/vault/views/vaultViewFolder.html',
controller: 'vaultViewFolderController',
data: { authorize: true },
params: { animation: null, returnScrollY: 0, returnSearchText: null, from: 'vault' }
params: { animation: null, from: 'vault' }
})
.state('viewSite', {
url: '/view-site?siteId',
templateUrl: 'app/vault/views/vaultViewSite.html',
controller: 'vaultViewSiteController',
data: { authorize: true },
params: { animation: null, returnScrollY: 0, returnSearchText: null, from: 'vault' }
params: { animation: null, from: 'vault' }
})
.state('addSite', {
url: '/add-site',
templateUrl: 'app/vault/views/vaultAddSite.html',
controller: 'vaultAddSiteController',
data: { authorize: true },
params: {
animation: null, returnScrollY: 0, returnSearchText: null, name: null,
uri: null, site: null, from: 'vault'
}
params: { animation: null, name: null, uri: null, site: null, from: 'vault' }
})
.state('editSite', {
url: '/edit-site?siteId',
@ -189,8 +186,12 @@
params: { animation: null }
});
})
.run(function ($rootScope, userService, loginService, cryptoService, tokenService, $state, constantsService) {
.run(function ($rootScope, userService, loginService, cryptoService, tokenService, $state, constantsService, stateService) {
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
stateService.purgeState();
}
cryptoService.getKey(false, function (key) {
tokenService.getToken(function (token) {
userService.isAuthenticated(function (isAuthenticated) {

View File

@ -65,7 +65,8 @@ angular
$state.go('addSite', {
animation: 'in-slide-up',
name: domain,
uri: url
uri: url,
from: 'current'
});
};

View File

@ -17,5 +17,13 @@
return null;
};
_service.removeState = function (key) {
delete _state[key];
};
_service.purgeState = function () {
_state = {};
};
return _service;
});

View File

@ -94,9 +94,7 @@
$state.go('addSite', {
animation: 'out-slide-down',
from: addState.from,
site: addState.site,
returnScrollY: addState.returnScrollY,
returnSearchText: addState.returnSearchText
site: addState.site
});
}
else if (editState) {
@ -104,9 +102,7 @@
animation: 'out-slide-down',
site: editState.site,
fromView: editState.fromView,
siteId: editState.siteId,
returnScrollY: editState.returnScrollY,
returnSearchText: editState.returnSearchText
siteId: editState.siteId
});
}
else {

View File

@ -4,9 +4,7 @@
.controller('vaultAddSiteController', function ($scope, $state, $stateParams, siteService, folderService,
cryptoService, $q, toastr, utilsService, $analytics, i18nService) {
$scope.i18n = i18nService;
var returnScrollY = $stateParams.returnScrollY;
var returnSearchText = $stateParams.returnSearchText;
var fromCurrent = $stateParams.from;
var from = $stateParams.from;
$scope.site = {
folderId: null,
@ -55,16 +53,12 @@
}
else if (from === 'folder') {
$state.go('viewFolder', {
animation: 'out-slide-down',
scrollY: returnScrollY || 0,
searchText: returnSearchText
animation: 'out-slide-down'
});
}
else if(from === 'vault') {
else {
$state.go('tabs.vault', {
animation: 'out-slide-down',
scrollY: returnScrollY || 0,
searchText: returnSearchText
animation: 'out-slide-down'
});
}
};
@ -75,9 +69,7 @@
animation: 'in-slide-up',
addState: {
from: from,
site: $scope.site,
returnScrollY: returnScrollY,
returnSearchText: returnSearchText
site: $scope.site
}
});
};

View File

@ -2,7 +2,10 @@
.module('bit.vault')
.controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr,
syncService, utilsService, $analytics, i18nService) {
syncService, utilsService, $analytics, i18nService, stateService) {
var stateKey = 'vault',
state = stateService.getState(stateKey) || {};
$scope.i18n = i18nService;
$('#search').focus();
@ -62,8 +65,8 @@
}
$scope.searchText = null;
if ($stateParams.searchText) {
$scope.searchText = $stateParams.searchText;
if (state.searchText) {
$scope.searchText = state.searchText;
}
$scope.folderSort = function (item) {
@ -98,28 +101,27 @@
}
$scope.addSite = function () {
storeState();
$state.go('addSite', {
animation: 'in-slide-up',
returnScrollY: getScrollY(),
returnSearchText: $scope.searchText
from: 'vault'
});
};
$scope.viewSite = function (site) {
storeState();
$state.go('viewSite', {
siteId: site.id,
animation: 'in-slide-up',
returnScrollY: getScrollY(),
returnSearchText: $scope.searchText
from: 'vault'
});
};
$scope.viewFolder = function (folder) {
storeState();
$state.go('viewFolder', {
folderId: folder.id || '',
animation: 'in-slide-left',
returnScrollY: getScrollY(),
returnSearchText: $scope.searchText
folderId: folder.id || '0',
animation: 'in-slide-left'
});
};
@ -137,15 +139,22 @@
setTimeout(loadVault, 500);
});
function storeState() {
stateService.saveState(stateKey, {
scrollY: getScrollY(),
searchText: $scope.searchText
});
}
function getScrollY() {
var content = document.getElementsByClassName('content')[0];
return content.scrollTop;
}
function setScrollY() {
if ($stateParams.scrollY) {
if (state.scrollY) {
var content = document.getElementsByClassName('content')[0];
content.scrollTop = $stateParams.scrollY;
content.scrollTop = state.scrollY;
}
}
});

View File

@ -4,8 +4,6 @@ angular
.controller('vaultEditSiteController', function ($scope, $state, $stateParams, siteService, folderService,
cryptoService, $q, toastr, SweetAlert, utilsService, $analytics, i18nService) {
$scope.i18n = i18nService;
var returnScrollY = $stateParams.returnScrollY;
var returnSearchText = $stateParams.returnSearchText;
var siteId = $stateParams.siteId;
var fromView = $stateParams.fromView;
var from = $stateParams.from;
@ -73,16 +71,12 @@ angular
$state.go('viewSite', {
siteId: siteId,
animation: 'out-slide-down',
returnScrollY: returnScrollY || 0,
returnSearchText: returnSearchText,
from: from
});
}
else {
$state.go('tabs.vault', {
animation: 'out-slide-down',
scrollY: returnScrollY || 0,
searchText: returnSearchText
animation: 'out-slide-down'
});
}
};
@ -114,9 +108,7 @@ angular
editState: {
fromView: fromView,
siteId: siteId,
site: $scope.site,
returnScrollY: returnScrollY,
returnSearchText: returnSearchText
site: $scope.site
}
});
}

View File

@ -2,13 +2,18 @@
.module('bit.vault')
.controller('vaultViewFolderController', function ($scope, siteService, folderService, $q, $state, $stateParams, toastr,
syncService, $analytics, i18nService) {
syncService, $analytics, i18nService, stateService) {
var stateKey = 'viewFolder',
state = stateService.getState(stateKey) || {};
state.folderId = $stateParams.folderId || state.folderId;
var pageSize = 100,
decFolder = null,
decSites = [];
$scope.folder = {
id: $stateParams.folderId || null,
id: !state.folderId || state.folderId === '0' ? null : state.folderId,
name: '(none)'
};
$scope.i18n = i18nService;
@ -17,6 +22,7 @@
$scope.loaded = false;
$scope.vaultSites = [];
$scope.pagedVaultSites = [];
$scope.searchText = null;
loadVault();
function loadVault() {
@ -46,7 +52,13 @@
if (decFolder) {
$scope.folder.name = decFolder.name;
}
setScrollY();
if (state.searchText) {
$scope.searchText = state.searchText;
$scope.searchSites();
}
setTimeout(setScrollY, 200);
});
}
@ -95,11 +107,6 @@
}
};
$scope.searchText = null;
if ($stateParams.searchText) {
$scope.searchText = $stateParams.searchText;
}
$scope.searchSites = function () {
if (!$scope.searchText || $scope.searchText.length < 2) {
if ($scope.vaultSites.length !== decSites.length) {
@ -140,20 +147,18 @@
}
$scope.addSite = function () {
storeState();
$state.go('addSite', {
animation: 'in-slide-up',
returnScrollY: getScrollY(),
returnSearchText: $scope.searchText,
from: 'folder'
});
};
$scope.viewSite = function (site) {
storeState();
$state.go('viewSite', {
siteId: site.id,
animation: 'in-slide-up',
returnScrollY: getScrollY(),
returnSearchText: $scope.searchText,
from: 'folder'
});
};
@ -168,15 +173,24 @@
toastr.info(type + i18nService.valueCopied);
};
function storeState() {
angular.extend(state, {
scrollY: getScrollY(),
searchText: $scope.searchText
});
stateService.saveState(stateKey, state);
}
function getScrollY() {
var content = document.getElementsByClassName('content')[0];
return content.scrollTop;
}
function setScrollY() {
if ($stateParams.scrollY) {
if (state.scrollY) {
var content = document.getElementsByClassName('content')[0];
content.scrollTop = $stateParams.scrollY;
content.scrollTop = state.scrollY;
}
}
});

View File

@ -4,8 +4,6 @@ angular
.controller('vaultViewSiteController', function ($scope, $state, $stateParams, siteService, tldjs, toastr, $q,
$analytics, i18nService) {
$scope.i18n = i18nService;
var returnScrollY = $stateParams.returnScrollY;
var returnSearchText = $stateParams.returnSearchText;
var from = $stateParams.from;
$scope.site = null;
@ -47,8 +45,6 @@ angular
animation: 'in-slide-up',
siteId: site.id,
fromView: true,
returnScrollY: returnScrollY || 0,
returnSearchText: returnSearchText,
from: from
});
};
@ -61,16 +57,12 @@ angular
}
else if (from === 'folder') {
$state.go('viewFolder', {
animation: 'out-slide-down',
scrollY: returnScrollY || 0,
searchText: returnSearchText
animation: 'out-slide-down'
});
}
else {
$state.go('tabs.vault', {
animation: 'out-slide-down',
scrollY: returnScrollY || 0,
searchText: returnSearchText
animation: 'out-slide-down'
});
}
};