2016-09-11 05:30:17 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngdoc service
|
|
|
|
* @name passmanApp.VaultService
|
|
|
|
* @description
|
|
|
|
* # VaultService
|
|
|
|
* Service in the passmanApp.
|
|
|
|
*/
|
|
|
|
angular.module('passmanApp')
|
2016-09-25 23:36:03 +08:00
|
|
|
.service('VaultService', ['$http', function ($http) {
|
2016-09-11 05:30:17 +08:00
|
|
|
// AngularJS will instantiate a singleton by calling "new" on this function
|
2016-09-12 01:45:20 +08:00
|
|
|
var _activeVault;
|
2016-09-11 05:30:17 +08:00
|
|
|
return {
|
|
|
|
getVaults: function(){
|
2016-09-12 01:45:20 +08:00
|
|
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults');
|
2016-09-11 05:30:17 +08:00
|
|
|
return $http.get(queryUrl).then(function (response) {
|
|
|
|
if(response.data){
|
|
|
|
return response.data;
|
|
|
|
} else {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-09-12 01:45:20 +08:00
|
|
|
setActiveVault: function(vault){
|
2016-09-26 03:25:37 +08:00
|
|
|
this.getVaults().then(function(vaults){
|
|
|
|
for(var v = 0; v < vaults.length; v++){
|
|
|
|
if(vaults[v].vault_id == vault.vault_id){
|
|
|
|
_activeVault = angular.merge(_activeVault, vaults[v]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-09-12 01:45:20 +08:00
|
|
|
_activeVault = vault;
|
|
|
|
},
|
|
|
|
getActiveVault: function(vault){
|
|
|
|
return _activeVault;
|
|
|
|
},
|
2016-09-11 18:33:09 +08:00
|
|
|
createVault: function (vaultName) {
|
2016-09-12 01:45:20 +08:00
|
|
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults');
|
2016-09-11 18:33:09 +08:00
|
|
|
return $http.post(queryUrl, { vault_name: vaultName }).then(function (response) {
|
|
|
|
if(response.data){
|
|
|
|
return response.data;
|
|
|
|
} else {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getVault: function (vault) {
|
2016-09-12 01:45:20 +08:00
|
|
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id);
|
2016-09-11 18:33:09 +08:00
|
|
|
return $http.get(queryUrl).then(function (response) {
|
|
|
|
if(response.data){
|
|
|
|
return response.data;
|
|
|
|
} else {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateVault: function (vault) {
|
2016-09-12 01:45:20 +08:00
|
|
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id);
|
2016-09-11 18:33:09 +08:00
|
|
|
return $http.post(queryUrl).then(function (response) {
|
|
|
|
if(response.data){
|
|
|
|
return response.data;
|
|
|
|
} else {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-09-26 00:34:33 +08:00
|
|
|
updateSharingKeys: function (vault) {
|
|
|
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id +'/sharing-keys');
|
|
|
|
return $http.post(queryUrl, vault).then(function (response) {
|
|
|
|
if(response.data){
|
|
|
|
return response.data;
|
|
|
|
} else {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-09-11 18:33:09 +08:00
|
|
|
deleteVault: function (vault) {
|
2016-09-12 01:45:20 +08:00
|
|
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id);
|
2016-09-11 18:33:09 +08:00
|
|
|
return $http.delete(queryUrl).then(function (response) {
|
|
|
|
if(response.data){
|
|
|
|
return response.data;
|
|
|
|
} else {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
});
|
2016-09-11 05:30:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}]);
|