tracking vault state with stateService
This commit is contained in:
parent
ced707647f
commit
e414dd1867
|
@ -75,7 +75,7 @@
|
||||||
url: '/vault',
|
url: '/vault',
|
||||||
templateUrl: 'app/vault/views/vault.html',
|
templateUrl: 'app/vault/views/vault.html',
|
||||||
controller: 'vaultController',
|
controller: 'vaultController',
|
||||||
params: { scrollY: 0, searchText: null, syncOnLoad: false }
|
params: { syncOnLoad: false }
|
||||||
})
|
})
|
||||||
.state('tabs.settings', {
|
.state('tabs.settings', {
|
||||||
url: '/settings',
|
url: '/settings',
|
||||||
|
@ -93,24 +93,21 @@
|
||||||
templateUrl: 'app/vault/views/vaultViewFolder.html',
|
templateUrl: 'app/vault/views/vaultViewFolder.html',
|
||||||
controller: 'vaultViewFolderController',
|
controller: 'vaultViewFolderController',
|
||||||
data: { authorize: true },
|
data: { authorize: true },
|
||||||
params: { animation: null, returnScrollY: 0, returnSearchText: null, from: 'vault' }
|
params: { animation: null, from: 'vault' }
|
||||||
})
|
})
|
||||||
.state('viewSite', {
|
.state('viewSite', {
|
||||||
url: '/view-site?siteId',
|
url: '/view-site?siteId',
|
||||||
templateUrl: 'app/vault/views/vaultViewSite.html',
|
templateUrl: 'app/vault/views/vaultViewSite.html',
|
||||||
controller: 'vaultViewSiteController',
|
controller: 'vaultViewSiteController',
|
||||||
data: { authorize: true },
|
data: { authorize: true },
|
||||||
params: { animation: null, returnScrollY: 0, returnSearchText: null, from: 'vault' }
|
params: { animation: null, from: 'vault' }
|
||||||
})
|
})
|
||||||
.state('addSite', {
|
.state('addSite', {
|
||||||
url: '/add-site',
|
url: '/add-site',
|
||||||
templateUrl: 'app/vault/views/vaultAddSite.html',
|
templateUrl: 'app/vault/views/vaultAddSite.html',
|
||||||
controller: 'vaultAddSiteController',
|
controller: 'vaultAddSiteController',
|
||||||
data: { authorize: true },
|
data: { authorize: true },
|
||||||
params: {
|
params: { animation: null, name: null, uri: null, site: null, from: 'vault' }
|
||||||
animation: null, returnScrollY: 0, returnSearchText: null, name: null,
|
|
||||||
uri: null, site: null, from: 'vault'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.state('editSite', {
|
.state('editSite', {
|
||||||
url: '/edit-site?siteId',
|
url: '/edit-site?siteId',
|
||||||
|
@ -189,8 +186,12 @@
|
||||||
params: { animation: null }
|
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) {
|
$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) {
|
cryptoService.getKey(false, function (key) {
|
||||||
tokenService.getToken(function (token) {
|
tokenService.getToken(function (token) {
|
||||||
userService.isAuthenticated(function (isAuthenticated) {
|
userService.isAuthenticated(function (isAuthenticated) {
|
||||||
|
|
|
@ -65,7 +65,8 @@ angular
|
||||||
$state.go('addSite', {
|
$state.go('addSite', {
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
name: domain,
|
name: domain,
|
||||||
uri: url
|
uri: url,
|
||||||
|
from: 'current'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,5 +17,13 @@
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_service.removeState = function (key) {
|
||||||
|
delete _state[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
_service.purgeState = function () {
|
||||||
|
_state = {};
|
||||||
|
};
|
||||||
|
|
||||||
return _service;
|
return _service;
|
||||||
});
|
});
|
||||||
|
|
|
@ -94,9 +94,7 @@
|
||||||
$state.go('addSite', {
|
$state.go('addSite', {
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down',
|
||||||
from: addState.from,
|
from: addState.from,
|
||||||
site: addState.site,
|
site: addState.site
|
||||||
returnScrollY: addState.returnScrollY,
|
|
||||||
returnSearchText: addState.returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (editState) {
|
else if (editState) {
|
||||||
|
@ -104,9 +102,7 @@
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down',
|
||||||
site: editState.site,
|
site: editState.site,
|
||||||
fromView: editState.fromView,
|
fromView: editState.fromView,
|
||||||
siteId: editState.siteId,
|
siteId: editState.siteId
|
||||||
returnScrollY: editState.returnScrollY,
|
|
||||||
returnSearchText: editState.returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
.controller('vaultAddSiteController', function ($scope, $state, $stateParams, siteService, folderService,
|
.controller('vaultAddSiteController', function ($scope, $state, $stateParams, siteService, folderService,
|
||||||
cryptoService, $q, toastr, utilsService, $analytics, i18nService) {
|
cryptoService, $q, toastr, utilsService, $analytics, i18nService) {
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
var returnScrollY = $stateParams.returnScrollY;
|
var from = $stateParams.from;
|
||||||
var returnSearchText = $stateParams.returnSearchText;
|
|
||||||
var fromCurrent = $stateParams.from;
|
|
||||||
|
|
||||||
$scope.site = {
|
$scope.site = {
|
||||||
folderId: null,
|
folderId: null,
|
||||||
|
@ -55,16 +53,12 @@
|
||||||
}
|
}
|
||||||
else if (from === 'folder') {
|
else if (from === 'folder') {
|
||||||
$state.go('viewFolder', {
|
$state.go('viewFolder', {
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down'
|
||||||
scrollY: returnScrollY || 0,
|
|
||||||
searchText: returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(from === 'vault') {
|
else {
|
||||||
$state.go('tabs.vault', {
|
$state.go('tabs.vault', {
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down'
|
||||||
scrollY: returnScrollY || 0,
|
|
||||||
searchText: returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -75,9 +69,7 @@
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
addState: {
|
addState: {
|
||||||
from: from,
|
from: from,
|
||||||
site: $scope.site,
|
site: $scope.site
|
||||||
returnScrollY: returnScrollY,
|
|
||||||
returnSearchText: returnSearchText
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr,
|
.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;
|
$scope.i18n = i18nService;
|
||||||
$('#search').focus();
|
$('#search').focus();
|
||||||
|
|
||||||
|
@ -62,8 +65,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.searchText = null;
|
$scope.searchText = null;
|
||||||
if ($stateParams.searchText) {
|
if (state.searchText) {
|
||||||
$scope.searchText = $stateParams.searchText;
|
$scope.searchText = state.searchText;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.folderSort = function (item) {
|
$scope.folderSort = function (item) {
|
||||||
|
@ -98,28 +101,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.addSite = function () {
|
$scope.addSite = function () {
|
||||||
|
storeState();
|
||||||
$state.go('addSite', {
|
$state.go('addSite', {
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
returnScrollY: getScrollY(),
|
from: 'vault'
|
||||||
returnSearchText: $scope.searchText
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.viewSite = function (site) {
|
$scope.viewSite = function (site) {
|
||||||
|
storeState();
|
||||||
$state.go('viewSite', {
|
$state.go('viewSite', {
|
||||||
siteId: site.id,
|
siteId: site.id,
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
returnScrollY: getScrollY(),
|
from: 'vault'
|
||||||
returnSearchText: $scope.searchText
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.viewFolder = function (folder) {
|
$scope.viewFolder = function (folder) {
|
||||||
|
storeState();
|
||||||
$state.go('viewFolder', {
|
$state.go('viewFolder', {
|
||||||
folderId: folder.id || '',
|
folderId: folder.id || '0',
|
||||||
animation: 'in-slide-left',
|
animation: 'in-slide-left'
|
||||||
returnScrollY: getScrollY(),
|
|
||||||
returnSearchText: $scope.searchText
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -137,15 +139,22 @@
|
||||||
setTimeout(loadVault, 500);
|
setTimeout(loadVault, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function storeState() {
|
||||||
|
stateService.saveState(stateKey, {
|
||||||
|
scrollY: getScrollY(),
|
||||||
|
searchText: $scope.searchText
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getScrollY() {
|
function getScrollY() {
|
||||||
var content = document.getElementsByClassName('content')[0];
|
var content = document.getElementsByClassName('content')[0];
|
||||||
return content.scrollTop;
|
return content.scrollTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setScrollY() {
|
function setScrollY() {
|
||||||
if ($stateParams.scrollY) {
|
if (state.scrollY) {
|
||||||
var content = document.getElementsByClassName('content')[0];
|
var content = document.getElementsByClassName('content')[0];
|
||||||
content.scrollTop = $stateParams.scrollY;
|
content.scrollTop = state.scrollY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,8 +4,6 @@ angular
|
||||||
.controller('vaultEditSiteController', function ($scope, $state, $stateParams, siteService, folderService,
|
.controller('vaultEditSiteController', function ($scope, $state, $stateParams, siteService, folderService,
|
||||||
cryptoService, $q, toastr, SweetAlert, utilsService, $analytics, i18nService) {
|
cryptoService, $q, toastr, SweetAlert, utilsService, $analytics, i18nService) {
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
var returnScrollY = $stateParams.returnScrollY;
|
|
||||||
var returnSearchText = $stateParams.returnSearchText;
|
|
||||||
var siteId = $stateParams.siteId;
|
var siteId = $stateParams.siteId;
|
||||||
var fromView = $stateParams.fromView;
|
var fromView = $stateParams.fromView;
|
||||||
var from = $stateParams.from;
|
var from = $stateParams.from;
|
||||||
|
@ -73,16 +71,12 @@ angular
|
||||||
$state.go('viewSite', {
|
$state.go('viewSite', {
|
||||||
siteId: siteId,
|
siteId: siteId,
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down',
|
||||||
returnScrollY: returnScrollY || 0,
|
|
||||||
returnSearchText: returnSearchText,
|
|
||||||
from: from
|
from: from
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$state.go('tabs.vault', {
|
$state.go('tabs.vault', {
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down'
|
||||||
scrollY: returnScrollY || 0,
|
|
||||||
searchText: returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -114,9 +108,7 @@ angular
|
||||||
editState: {
|
editState: {
|
||||||
fromView: fromView,
|
fromView: fromView,
|
||||||
siteId: siteId,
|
siteId: siteId,
|
||||||
site: $scope.site,
|
site: $scope.site
|
||||||
returnScrollY: returnScrollY,
|
|
||||||
returnSearchText: returnSearchText
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,18 @@
|
||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.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, stateService) {
|
||||||
|
var stateKey = 'viewFolder',
|
||||||
|
state = stateService.getState(stateKey) || {};
|
||||||
|
|
||||||
|
state.folderId = $stateParams.folderId || state.folderId;
|
||||||
|
|
||||||
var pageSize = 100,
|
var pageSize = 100,
|
||||||
decFolder = null,
|
decFolder = null,
|
||||||
decSites = [];
|
decSites = [];
|
||||||
|
|
||||||
$scope.folder = {
|
$scope.folder = {
|
||||||
id: $stateParams.folderId || null,
|
id: !state.folderId || state.folderId === '0' ? null : state.folderId,
|
||||||
name: '(none)'
|
name: '(none)'
|
||||||
};
|
};
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
|
@ -17,6 +22,7 @@
|
||||||
$scope.loaded = false;
|
$scope.loaded = false;
|
||||||
$scope.vaultSites = [];
|
$scope.vaultSites = [];
|
||||||
$scope.pagedVaultSites = [];
|
$scope.pagedVaultSites = [];
|
||||||
|
$scope.searchText = null;
|
||||||
loadVault();
|
loadVault();
|
||||||
|
|
||||||
function loadVault() {
|
function loadVault() {
|
||||||
|
@ -46,7 +52,13 @@
|
||||||
if (decFolder) {
|
if (decFolder) {
|
||||||
$scope.folder.name = decFolder.name;
|
$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 () {
|
$scope.searchSites = function () {
|
||||||
if (!$scope.searchText || $scope.searchText.length < 2) {
|
if (!$scope.searchText || $scope.searchText.length < 2) {
|
||||||
if ($scope.vaultSites.length !== decSites.length) {
|
if ($scope.vaultSites.length !== decSites.length) {
|
||||||
|
@ -140,20 +147,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.addSite = function () {
|
$scope.addSite = function () {
|
||||||
|
storeState();
|
||||||
$state.go('addSite', {
|
$state.go('addSite', {
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
returnScrollY: getScrollY(),
|
|
||||||
returnSearchText: $scope.searchText,
|
|
||||||
from: 'folder'
|
from: 'folder'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.viewSite = function (site) {
|
$scope.viewSite = function (site) {
|
||||||
|
storeState();
|
||||||
$state.go('viewSite', {
|
$state.go('viewSite', {
|
||||||
siteId: site.id,
|
siteId: site.id,
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
returnScrollY: getScrollY(),
|
|
||||||
returnSearchText: $scope.searchText,
|
|
||||||
from: 'folder'
|
from: 'folder'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -168,15 +173,24 @@
|
||||||
toastr.info(type + i18nService.valueCopied);
|
toastr.info(type + i18nService.valueCopied);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function storeState() {
|
||||||
|
angular.extend(state, {
|
||||||
|
scrollY: getScrollY(),
|
||||||
|
searchText: $scope.searchText
|
||||||
|
});
|
||||||
|
|
||||||
|
stateService.saveState(stateKey, state);
|
||||||
|
}
|
||||||
|
|
||||||
function getScrollY() {
|
function getScrollY() {
|
||||||
var content = document.getElementsByClassName('content')[0];
|
var content = document.getElementsByClassName('content')[0];
|
||||||
return content.scrollTop;
|
return content.scrollTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setScrollY() {
|
function setScrollY() {
|
||||||
if ($stateParams.scrollY) {
|
if (state.scrollY) {
|
||||||
var content = document.getElementsByClassName('content')[0];
|
var content = document.getElementsByClassName('content')[0];
|
||||||
content.scrollTop = $stateParams.scrollY;
|
content.scrollTop = state.scrollY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,8 +4,6 @@ angular
|
||||||
.controller('vaultViewSiteController', function ($scope, $state, $stateParams, siteService, tldjs, toastr, $q,
|
.controller('vaultViewSiteController', function ($scope, $state, $stateParams, siteService, tldjs, toastr, $q,
|
||||||
$analytics, i18nService) {
|
$analytics, i18nService) {
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
var returnScrollY = $stateParams.returnScrollY;
|
|
||||||
var returnSearchText = $stateParams.returnSearchText;
|
|
||||||
var from = $stateParams.from;
|
var from = $stateParams.from;
|
||||||
|
|
||||||
$scope.site = null;
|
$scope.site = null;
|
||||||
|
@ -47,8 +45,6 @@ angular
|
||||||
animation: 'in-slide-up',
|
animation: 'in-slide-up',
|
||||||
siteId: site.id,
|
siteId: site.id,
|
||||||
fromView: true,
|
fromView: true,
|
||||||
returnScrollY: returnScrollY || 0,
|
|
||||||
returnSearchText: returnSearchText,
|
|
||||||
from: from
|
from: from
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -61,16 +57,12 @@ angular
|
||||||
}
|
}
|
||||||
else if (from === 'folder') {
|
else if (from === 'folder') {
|
||||||
$state.go('viewFolder', {
|
$state.go('viewFolder', {
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down'
|
||||||
scrollY: returnScrollY || 0,
|
|
||||||
searchText: returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$state.go('tabs.vault', {
|
$state.go('tabs.vault', {
|
||||||
animation: 'out-slide-down',
|
animation: 'out-slide-down'
|
||||||
scrollY: returnScrollY || 0,
|
|
||||||
searchText: returnSearchText
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue