fix sync and vault listing bugs
This commit is contained in:
parent
5a39d4c73e
commit
4092e2ecc3
|
@ -4,3 +4,4 @@ var apiService = new ApiService(tokenService);
|
|||
var userService = new UserService(tokenService, apiService);
|
||||
var siteService = new SiteService(cryptoService, userService, apiService);
|
||||
var folderService = new FolderService(cryptoService, userService, apiService);
|
||||
var syncService = new SyncService(siteService, folderService, userService, apiService);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
"services/userService.js",
|
||||
"services/folderService.js",
|
||||
"services/siteService.js",
|
||||
"services/syncService.js",
|
||||
"background.js"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
this.id = response.Id;
|
||||
this.folderId = response.FolderId;
|
||||
this.type = response.Type;
|
||||
this.favorite = response.favorite;
|
||||
this.favorite = response.Favorite;
|
||||
this.data = response.Data;
|
||||
this.revisionDate = response.RevisionDate;
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ var SiteResponse = function (response) {
|
|||
this.username = response.Username;
|
||||
this.password = response.Password;
|
||||
this.notes = response.Notes;
|
||||
this.favorite = response.favorite;
|
||||
this.favorite = response.Favorite;
|
||||
this.revisionDate = response.RevisionDate;
|
||||
|
||||
if(response.Folder) {
|
||||
|
@ -47,7 +47,7 @@ var TokenResponse = function (response) {
|
|||
};
|
||||
|
||||
var ListResponse = function (data) {
|
||||
this.Data = data;
|
||||
this.data = data;
|
||||
};
|
||||
|
||||
var ErrorResponse = function (response) {
|
||||
|
|
|
@ -1,41 +1,43 @@
|
|||
var FolderData = function (response, userId) {
|
||||
var data = null;
|
||||
this.id = response.id;
|
||||
this.userId = userId;
|
||||
|
||||
if (response instanceof FolderResponse) {
|
||||
data = response;
|
||||
this.name = response.name;
|
||||
}
|
||||
else if (response instanceof CipherResponse) {
|
||||
data = response.Data;
|
||||
this.name = response.data.Name;
|
||||
}
|
||||
else {
|
||||
throw 'unsupported instance';
|
||||
}
|
||||
|
||||
this.id = response.id;
|
||||
this.userId = userId;
|
||||
this.name = data.name;
|
||||
this.revisionDate = response.revisionDate;
|
||||
};
|
||||
|
||||
var SiteData = function (response, userId) {
|
||||
var data = null;
|
||||
this.id = response.id;
|
||||
this.folderId = response.folderId;
|
||||
this.userId = userId;
|
||||
|
||||
if (response instanceof SiteResponse) {
|
||||
data = response;
|
||||
this.name = response.name;
|
||||
this.uri = response.uri;
|
||||
this.username = response.username;
|
||||
this.password = response.password;
|
||||
this.notes = response.notes;
|
||||
}
|
||||
else if (response instanceof CipherResponse) {
|
||||
data = response.Data;
|
||||
this.name = response.data.Name;
|
||||
this.uri = response.data.Uri;
|
||||
this.username = response.data.Username;
|
||||
this.password = response.data.Password;
|
||||
this.notes = response.notes = response.data.Notes;;
|
||||
}
|
||||
else {
|
||||
throw 'unsupported instance';
|
||||
}
|
||||
|
||||
this.id = response.id;
|
||||
this.folderId = response.folderId;
|
||||
this.userId = userId;
|
||||
this.name = data.name;
|
||||
this.uri = data.uri;
|
||||
this.username = data.username;
|
||||
this.password = data.password;
|
||||
this.notes = data.notes;
|
||||
this.favorite = response.favorite;
|
||||
this.revisionDate = response.revisionDate;
|
||||
};
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
})
|
||||
.factory('siteService', function () {
|
||||
return chrome.extension.getBackgroundPage().siteService;
|
||||
})
|
||||
.factory('syncService', function () {
|
||||
return chrome.extension.getBackgroundPage().syncService;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
angular
|
||||
.module('bit.settings')
|
||||
|
||||
.controller('settingsController', function ($scope, loginService, $state) {
|
||||
.controller('settingsController', function ($scope, loginService, $state, syncService) {
|
||||
$scope.sync = function () {
|
||||
syncService.fullSync(function () {
|
||||
alert('Sync done!');
|
||||
});
|
||||
};
|
||||
|
||||
$scope.logOut = function (model) {
|
||||
loginService.logOut(function () {
|
||||
$state.go('login');
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
<ion-view view-title="Settings">
|
||||
<ion-content>
|
||||
<div class="list">
|
||||
<div class="item item-divider">
|
||||
Manage
|
||||
</div>
|
||||
<a class="item" href="#">
|
||||
Folders
|
||||
</a>
|
||||
<a class="item" ng-click="sync()">
|
||||
Sync
|
||||
</a>
|
||||
<div class="item item-divider">
|
||||
Current Session
|
||||
</div>
|
||||
|
|
|
@ -7,14 +7,11 @@
|
|||
$scope.folders = [];
|
||||
$scope.focusedSiteId = null;
|
||||
|
||||
$scope.$on("$ionicView.enter", function (event, data) {
|
||||
$scope.$on('$ionicView.enter', function (event, data) {
|
||||
loadVault();
|
||||
});
|
||||
|
||||
function loadVault() {
|
||||
$scope.sites = [];
|
||||
$scope.folders = [];
|
||||
|
||||
var decSites = [];
|
||||
var decFolders = [{
|
||||
id: null,
|
||||
|
@ -25,12 +22,12 @@
|
|||
siteService.getAll(function (sites) {
|
||||
var promises = [];
|
||||
|
||||
for (var i = 0; i < folders.length; i++) {
|
||||
for (var i = 1; i < folders.length; i++) {
|
||||
decFolders.push({
|
||||
id: folders[i].id
|
||||
});
|
||||
|
||||
var folderNamePromise = cipherService.decrypt(sites[i].name, i);
|
||||
var folderNamePromise = cipherService.decrypt(folders[i].name, i);
|
||||
promises.push(folderNamePromise);
|
||||
folderNamePromise.then(function (obj) {
|
||||
decFolders[obj.index].name = obj.val;
|
||||
|
@ -65,6 +62,14 @@
|
|||
});
|
||||
}
|
||||
|
||||
$scope.folderSort = function (item) {
|
||||
if (!item.id) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return item.name.toLowerCase();
|
||||
};
|
||||
|
||||
$scope.viewSite = function (site) {
|
||||
$scope.focusedSiteId = site.id;
|
||||
$ionicModal.fromTemplateUrl('app/vault/views/vaultViewSite.html', {
|
||||
|
@ -111,7 +116,7 @@
|
|||
$scope.focusedSiteId = null;
|
||||
};
|
||||
|
||||
$scope.$on('modal.hidden', function () {
|
||||
$scope.$on('closeViewSite.hidden', function () {
|
||||
console.log('modal hidden');
|
||||
loadVault();
|
||||
});
|
||||
|
|
|
@ -203,8 +203,8 @@ function initApiService() {
|
|||
dataType: 'json',
|
||||
success: function (response) {
|
||||
var data = [];
|
||||
for (var i = 0; i < response.length; i++) {
|
||||
data.push(new CipherResponse(response[i]));
|
||||
for (var i = 0; i < response.Data.length; i++) {
|
||||
data.push(new CipherResponse(response.Data[i]));
|
||||
}
|
||||
|
||||
success(new ListResponse(data))
|
||||
|
|
|
@ -15,39 +15,39 @@ function initSyncService() {
|
|||
}
|
||||
|
||||
var self = this;
|
||||
this.userService.isAuthenticated(function (isAuthenticated) {
|
||||
self.userService.isAuthenticated(function (isAuthenticated) {
|
||||
if (!isAuthenticated) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
syncStarted();
|
||||
var now = new Date();
|
||||
var ciphers = self.apiService.getCiphers(function (response) {
|
||||
var sites = {};
|
||||
var folders = {};
|
||||
self.userService.getUserId(function (userId) {
|
||||
syncStarted();
|
||||
var now = new Date();
|
||||
var ciphers = self.apiService.getCiphers(function (response) {
|
||||
var sites = {};
|
||||
var folders = {};
|
||||
|
||||
for (var i = 0; i < response.Data.lenth; i++) {
|
||||
var data = response.Data[i];
|
||||
if (data.type === 1) {
|
||||
sites[data.id] = new SiteData(data);
|
||||
for (var i = 0; i < response.data.length; i++) {
|
||||
var data = response.data[i];
|
||||
if (data.type === 1) {
|
||||
sites[data.id] = new SiteData(data, userId);
|
||||
}
|
||||
else if (data.type === 0) {
|
||||
folders[data.id] = new FolderData(data, userId);
|
||||
}
|
||||
}
|
||||
else if (data.type === 0) {
|
||||
folders[data.id] = new FolderData(data);
|
||||
}
|
||||
}
|
||||
|
||||
folderService.replace(folders, function () {
|
||||
siteService.replace(sites, function () {
|
||||
setLastSync(now, function () {
|
||||
syncCompleted(true);
|
||||
callback(true);
|
||||
self.folderService.replace(folders, function () {
|
||||
self.siteService.replace(sites, function () {
|
||||
self.setLastSync(now, function () {
|
||||
syncCompleted(true);
|
||||
callback(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}, handleError);
|
||||
|
||||
}, handleError);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -71,12 +71,12 @@ function initSyncService() {
|
|||
self.userService.getUserId(function (userId) {
|
||||
self.folderService.getAll(function (folders) {
|
||||
var localFolders = {};
|
||||
for (var i = 0; i < folders.lenth; i++) {
|
||||
for (var i = 0; i < folders.length; i++) {
|
||||
localFolders[folders[i].id] = folders[i];
|
||||
}
|
||||
|
||||
var data = [];
|
||||
for (var j = 0; j < serverFolders.lenth; j++) {
|
||||
for (var j = 0; j < serverFolders.length; j++) {
|
||||
var serverFolder = serverFolders[j];
|
||||
var existingLocalFolder = localFolders[serverFolder.id];
|
||||
|
||||
|
@ -105,12 +105,12 @@ function initSyncService() {
|
|||
self.userService.getUserId(function (userId) {
|
||||
self.siteService.getAll(function (sites) {
|
||||
var localSites = {};
|
||||
for (var i = 0; i < sites.lenth; i++) {
|
||||
for (var i = 0; i < sites.length; i++) {
|
||||
localSites[sites[i].id] = sites[i];
|
||||
}
|
||||
|
||||
var data = [];
|
||||
for (var j = 0; j < serverSites.lenth; j++) {
|
||||
for (var j = 0; j < serverSites.length; j++) {
|
||||
var serverSite = serverSites[j];
|
||||
var existingLocalSite = localSites[serverSite.id];
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ function initUserService() {
|
|||
}
|
||||
|
||||
var decodedToken = this.tokenService.decodeToken(token);
|
||||
var twoFactor = decodedToken.authmethod === "TwoFactor";
|
||||
var twoFactor = decodedToken.authmethod === 'TwoFactor';
|
||||
|
||||
_userProfile = {
|
||||
id: decodedToken.nameid,
|
||||
|
|
Loading…
Reference in New Issue