Commit ec3e7f48 authored by Sascha Pfeiffer's avatar Sascha Pfeiffer

added offline mode

Signed-off-by: default avatarSascha Pfeiffer <sascha.pfeiffer@psono.com>
parent a194a47b
......@@ -5,9 +5,12 @@ var template_cache = require('gulp-angular-templatecache');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var htmlreplace = require('gulp-html-replace');
var replace = require('gulp-replace');
var htmlmin = require('gulp-htmlmin');
var jeditor = require("gulp-json-editor");
var minify = require('gulp-minify');
var uglify = require('gulp-uglify');
var maps = require('gulp-sourcemaps');
var saveLicense = require('uglify-save-license');
var gulpDocs = require('gulp-ngdocs');
var removeFiles = require('gulp-remove-files');
var run = require('gulp-run');
......@@ -96,7 +99,7 @@ var build = function(build_path, type) {
// All files in data/js
if (type === 'webclient') {
// minify
// uglify
gulp.src([
"src/common/data/js/lib/ecma-nacl.min.js",
......@@ -137,6 +140,7 @@ var build = function(build_path, type) {
"src/common/data/js/module/ng-tree.js",
"src/common/data/js/main.js",
"src/webclient/data/js/service-worker-load.js",
"src/common/data/js/directive/fileReader.js",
"src/common/data/js/directive/treeView.js",
......@@ -165,6 +169,7 @@ var build = function(build_path, type) {
"src/common/data/js/controller/modal/DisplayShareRightsCtrl.js",
"src/common/data/js/controller/modal/EditEntryCtrl.js",
"src/common/data/js/controller/modal/EditFolderCtrl.js",
"src/common/data/js/controller/modal/GoOfflineCtrl.js",
"src/common/data/js/controller/modal/NewFolderCtrl.js",
"src/common/data/js/controller/modal/VerifyCtrl.js",
"src/common/data/js/controller/modal/NewGroupCtrl.js",
......@@ -208,6 +213,7 @@ var build = function(build_path, type) {
"src/common/data/js/service/converter.js",
"src/common/data/js/service/openpgp.js",
"src/common/data/js/service/storage.js",
"src/common/data/js/service/offline-cache.js",
"src/common/data/js/service/account.js",
"src/common/data/js/service/settings.js",
"src/common/data/js/service/manager-base.js",
......@@ -239,15 +245,14 @@ var build = function(build_path, type) {
"src/common/data/view/templates.js",
"src/common/data/js/google-analytics.js"
])
.pipe(minify({
ext:{
min:'.js'
},
ignoreFiles: ['.min.js'],
noSource: true,
preserveComments: 'some'
.pipe(maps.init())
.pipe(uglify({
output: {
comments: saveLicense
}
}))
.pipe(concat('bundle.min.js'))
.pipe(maps.write('./'))
.pipe(gulp.dest(path.join(build_path, 'js')));
gulp.src([
......@@ -260,6 +265,7 @@ var build = function(build_path, type) {
gulp.src([
'src/common/data/js/**/*',
'!src/common/data/js/google-analytics.js',
'!src/common/data/js/service-worker-load.js',
'!src/common/data/js/service/browser-client.js'
])
.pipe(gulp.dest(path.join(build_path, 'js')));
......@@ -267,8 +273,23 @@ var build = function(build_path, type) {
// All files in data
if (type === 'webclient') {
gulp.src([
'src/webclient/data/service-worker.js'
])
.pipe(replace('%%PSONOVERSION%%', timestamp))
.pipe(maps.init())
.pipe(uglify({
output: {
comments: saveLicense
}
}))
.pipe(maps.write('./'))
.pipe(gulp.dest(path.join(build_path)));
return gulp.src([
'src/common/data/*',
'!src/common/data/service-worker.js',
'!src/common/data/background.html',
'!src/common/data/default_popup.html',
'!src/common/data/sass'
......@@ -282,6 +303,7 @@ var build = function(build_path, type) {
} else {
return gulp.src([
'src/common/data/*',
'!src/common/data/service-worker.js',
'!src/common/data/sass'
])
.pipe(htmlmin({collapseWhitespace: true}))
......
......@@ -2,7 +2,8 @@
"name": "psono-client",
"version": "1.0.0",
"private": true,
"dependencies": {},
"dependencies": {
},
"devDependencies": {
"gulp": "*",
"gulp-angular-templatecache": "^1.9.1",
......@@ -11,11 +12,13 @@
"gulp-html-replace": "^1.6.2",
"gulp-htmlmin": "^3.0.0",
"gulp-json-editor": "^2.2.1",
"gulp-minify": "0.0.14",
"gulp-ngdocs": "^0.3.0",
"gulp-remove-files": "0.0.3",
"gulp-replace": "^0.6.1",
"gulp-run": "^1.7.1",
"gulp-sass": "*",
"gulp-sourcemaps": "^2.6.4",
"gulp-uglify": "^3.0.0",
"jasmine-core": "~2.8.0",
"jsonwebtoken": "^8.2.0",
"karma": "~1.7.1",
......@@ -24,6 +27,7 @@
"karma-firefox-launcher": "~1.0.0",
"karma-jasmine": "~1.1.0",
"run-sequence": "^1.2.2",
"uglify-save-license": "^0.4.1",
"webstore-upload": "0.0.7"
}
}
......@@ -136,6 +136,7 @@
<script src="js/module/ng-tree.js" type="application/javascript"></script>
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......@@ -164,6 +165,7 @@
<script src="js/controller/modal/DisplayShareRightsCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditEntryCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GoOfflineCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
......@@ -207,6 +209,7 @@
<script src="js/service/converter.js" type="application/javascript"></script>
<script src="js/service/openpgp.js" type="application/javascript"></script>
<script src="js/service/storage.js" type="application/javascript"></script>
<script src="js/service/offline-cache.js" type="application/javascript"></script>
<script src="js/service/account.js" type="application/javascript"></script>
<script src="js/service/settings.js" type="application/javascript"></script>
<script src="js/service/manager-base.js" type="application/javascript"></script>
......
......@@ -63,6 +63,7 @@
<script src="js/module/ng-tree.js" type="application/javascript"></script>
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......@@ -91,6 +92,7 @@
<script src="js/controller/modal/DisplayShareRightsCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditEntryCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GoOfflineCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
......@@ -134,6 +136,7 @@
<script src="js/service/converter.js" type="application/javascript"></script>
<script src="js/service/openpgp.js" type="application/javascript"></script>
<script src="js/service/storage.js" type="application/javascript"></script>
<script src="js/service/offline-cache.js" type="application/javascript"></script>
<script src="js/service/account.js" type="application/javascript"></script>
<script src="js/service/settings.js" type="application/javascript"></script>
<script src="js/service/manager-base.js" type="application/javascript"></script>
......
......@@ -354,6 +354,7 @@
<script src="js/module/ng-tree.js" type="application/javascript"></script>
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......@@ -382,6 +383,7 @@
<script src="js/controller/modal/DisplayShareRightsCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditEntryCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GoOfflineCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
......@@ -425,6 +427,7 @@
<script src="js/service/converter.js" type="application/javascript"></script>
<script src="js/service/openpgp.js" type="application/javascript"></script>
<script src="js/service/storage.js" type="application/javascript"></script>
<script src="js/service/offline-cache.js" type="application/javascript"></script>
<script src="js/service/account.js" type="application/javascript"></script>
<script src="js/service/settings.js" type="application/javascript"></script>
<script src="js/service/manager-base.js" type="application/javascript"></script>
......
......@@ -136,6 +136,7 @@
<script src="js/module/ng-tree.js" type="application/javascript"></script>
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......@@ -164,6 +165,7 @@
<script src="js/controller/modal/DisplayShareRightsCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditEntryCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GoOfflineCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
......@@ -207,6 +209,7 @@
<script src="js/service/converter.js" type="application/javascript"></script>
<script src="js/service/openpgp.js" type="application/javascript"></script>
<script src="js/service/storage.js" type="application/javascript"></script>
<script src="js/service/offline-cache.js" type="application/javascript"></script>
<script src="js/service/account.js" type="application/javascript"></script>
<script src="js/service/settings.js" type="application/javascript"></script>
<script src="js/service/manager-base.js" type="application/javascript"></script>
......
......@@ -48,7 +48,7 @@
</a>
<div class="navbar-text navbar-left">
<div class="btn-group" uib-dropdown keyboard-nav ng-if="data_stores.length > 1">
<div class="btn-group" uib-dropdown keyboard-nav ng-if="data_stores.length > 1 && !offline">
<button id="simple-btn-keyboard-nav" type="button" class="btn btn-primary" uib-dropdown-toggle>
Datastore <span class="caret"></span>
</button>
......@@ -83,18 +83,22 @@
{{user_username}} <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="email-button">
<li role="menuitem"><a href="#!/account"><i class="fa fa-sliders fa-fw"></i> Account</a></li>
<li role="menuitem"><a href="#!/settings"><i class="fa fa-cogs fa-fw"></i> Settings</a></li>
<li role="menuitem"><a href="#!/other"><i class="fa fa-tasks fa-fw"></i> Other</a></li>
<li role="menuitem"><a href="#!/account" ng-if="!offline"><i class="fa fa-sliders fa-fw"></i> Account</a></li>
<li role="menuitem"><a href="#!/settings" ng-if="!offline"><i class="fa fa-cogs fa-fw"></i> Settings</a></li>
<li role="menuitem"><a href="#!/other" ng-if="!offline"><i class="fa fa-tasks fa-fw"></i> Other</a></li>
<li role="menuitem"><a href="#" ng-if="!offline" ng-click="go_offline()"><i class="fa fa-plane fa-fw"></i> Go Offline</a></li>
<li role="menuitem"><a href="" ng-if="offline" ng-click="go_online()"><i class="fa fa-globe fa-fw"></i> Go Online</a></li>
<li class="divider"></li>
<li role="menuitem"><a href="#" ng-click="logout()"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li>
</ul>
</div>
<div ng-if="! isNavCollapsed">
<ul class="nav navbar-nav" ng-if="! isNavCollapsed">
<li role="menuitem"><a href="#!/account"><i class="fa fa-sliders fa-fw"></i> Account</a></li>
<li role="menuitem"><a href="#!/settings"><i class="fa fa-cogs fa-fw"></i> Settings</a></li>
<li role="menuitem"><a href="#!/other"><i class="fa fa-tasks fa-fw"></i> Other</a></li>
<li role="menuitem"><a href="#!/account" ng-if="!offline"><i class="fa fa-sliders fa-fw"></i> Account</a></li>
<li role="menuitem"><a href="#!/settings" ng-if="!offline"><i class="fa fa-cogs fa-fw"></i> Settings</a></li>
<li role="menuitem"><a href="#!/other" ng-if="!offline"><i class="fa fa-tasks fa-fw"></i> Other</a></li>
<li role="menuitem"><a href="#" ng-if="!offline" ng-click="go_offline()"><i class="fa fa-plane fa-fw"></i> Go Offline</a></li>
<li role="menuitem"><a href="" ng-if="offline" ng-click="go_offline()"><i class="fa fa-globe fa-fw"></i> Go Online</a></li>
<li role="menuitem"><a href="#" ng-click="logout()"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li>
</ul>
</div>
......@@ -113,8 +117,8 @@
</li>
<!--<li ng-class="get_link_state('/test')"><a href="#!/test">Test</a></li>-->
</ul>
<h2>Share Details</h2>
<ul class="navigations">
<h2 ng-if="!offline">Share Details</h2>
<ul class="navigations" ng-if="!offline">
<li ng-class="get_link_state('/share/pendingshares')">
<a class="navigationitem2" href="#!/share/pendingshares">
<span class="fa-stack"><i class="fa fa-share-alt fa-fw"></i></span>Pending Requests
......@@ -429,6 +433,7 @@
<script src="js/module/ng-tree.js" type="application/javascript"></script>
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......@@ -457,6 +462,7 @@
<script src="js/controller/modal/DisplayShareRightsCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditEntryCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/GoOfflineCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewFolderCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
......@@ -500,6 +506,7 @@
<script src="js/service/converter.js" type="application/javascript"></script>
<script src="js/service/openpgp.js" type="application/javascript"></script>
<script src="js/service/storage.js" type="application/javascript"></script>
<script src="js/service/offline-cache.js" type="application/javascript"></script>
<script src="js/service/account.js" type="application/javascript"></script>
<script src="js/service/settings.js" type="application/javascript"></script>
<script src="js/service/manager-base.js" type="application/javascript"></script>
......
......@@ -13,6 +13,7 @@
* @requires psonocli.manager
* @requires psonocli.managerDatastorePassword
* @requires psonocli.managerDatastore
* @requires psonocli.offlineCache
* @requires psonocli.itemBlueprint
* @requires psonocli.managerWidget
* @requires psonocli.managerSecret
......@@ -21,10 +22,10 @@
* Main Controller for the datastore widget
*/
angular.module('psonocli').controller('DatastoreCtrl', ["$rootScope", "$scope", "$uibModal", "$routeParams", "$timeout",
"manager", "managerDatastorePassword", 'managerDatastore',
"manager", "managerDatastorePassword", 'managerDatastore', 'offlineCache',
"itemBlueprint", "managerWidget", "managerSecret", "dropDownMenuWatcher",
function($rootScope, $scope, $uibModal, $routeParams, $timeout,
manager, managerDatastorePassword, managerDatastore,
manager, managerDatastorePassword, managerDatastore, offlineCache,
itemBlueprint, managerWidget, managerSecret, dropDownMenuWatcher){
var contextMenusOpen = 0;
......@@ -191,6 +192,15 @@
activate();
function activate() {
$scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
$scope.offline = true;
});
$rootScope.$on('offline_mode_disabled', function() {
$scope.offline = false;
});
load_datastore().then(function(){
managerDatastore.register('on_datastore_overview_update', load_datastore);
});
......
......@@ -4,6 +4,7 @@
/**
* @ngdoc controller
* @name psonocli.controller:GPGEncryptMessageCtrl
* @requires $rootScope
* @requires $scope
* @requires $routeParams
* @requires $uibModal
......@@ -12,6 +13,7 @@
* @requires psonocli.managerDatastoreSetting
* @requires psonocli.managerDatastore
* @requires psonocli.browserClient
* @requires psonocli.offlineCache
* @requires psonocli.settings
* @requires psonocli.helper
* @requires psonocli.openpgp
......@@ -19,12 +21,12 @@
* @description
* Controller for the Group view
*/
angular.module('psonocli').controller('GPGEncryptMessageCtrl', ["$scope", "$timeout", "$routeParams", "$uibModal",
angular.module('psonocli').controller('GPGEncryptMessageCtrl', ["$rootScope", "$scope", "$timeout", "$routeParams", "$uibModal",
"cryptoLibrary", "managerDatastorePassword", "managerDatastoreSetting", "managerDatastore", "managerDatastoreGPGUser",
"browserClient", "settings", "helper", "openpgp",
function ($scope, $timeout, $routeParams, $uibModal,
"browserClient", "offlineCache", "settings", "helper", "openpgp",
function ($rootScope, $scope, $timeout, $routeParams, $uibModal,
cryptoLibrary, managerDatastorePassword, managerDatastoreSetting, managerDatastore, managerDatastoreGPGUser,
browserClient, settings, helper, openpgp) {
browserClient, offlineCache, settings, helper, openpgp) {
var receiver_index = {};
......@@ -49,8 +51,16 @@
activate();
function activate() {
$scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
$scope.offline = true;
});
$rootScope.$on('offline_mode_disabled', function() {
$scope.offline = false;
});
browserClient.emit_sec("write-gpg", $routeParams.gpg_message_id, function(data) {
console.log(data);
$scope.$evalAsync(function() {
load_receiver(data.receiver);
});
......
......@@ -14,6 +14,7 @@
* @requires psonocli.managerSecret
* @requires psonocli.browserClient
* @requires psonocli.storage
* @requires psonocli.offlineCache
* @requires snapRemote
* @requires $window
* @requires $route
......@@ -25,16 +26,18 @@
*/
angular.module('psonocli').controller('MainCtrl', ['$scope', '$rootScope', '$filter', '$timeout', 'account',
'managerDatastorePassword', 'managerDatastoreUser', 'managerDatastore', 'managerSecret', 'browserClient',
'storage', 'snapRemote', '$window', '$route', '$routeParams', '$location', '$uibModal',
'storage', 'offlineCache', 'snapRemote', '$window', '$route', '$routeParams', '$location', '$uibModal',
function ($scope, $rootScope, $filter, $timeout, account,
managerDatastorePassword, managerDatastoreUser, managerDatastore, managerSecret, browserClient,
storage, snapRemote, $window, $route, $routeParams, $location, $uibModal) {
storage, offlineCache, snapRemote, $window, $route, $routeParams, $location, $uibModal) {
$scope.open_tab = browserClient.open_tab;
$scope.create_new_datastore = create_new_datastore;
$scope.get_link_state = get_link_state;
$scope.logout = managerDatastoreUser.logout;
$scope.go_offline = go_offline;
$scope.go_online = go_online;
$scope.on_item_click = managerSecret.on_item_click;
$scope.on_datastore_switch_click = on_datastore_switch_click;
......@@ -58,6 +61,16 @@
}
$scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
$scope.offline = true;
});
$rootScope.$on('offline_mode_disabled', function() {
$scope.offline = false;
});
browserClient.load_version().then(function(version) {
$scope.version = version;
});
......@@ -99,6 +112,38 @@
});
}
/**
* @ngdoc
* @name psonocli.controller:OtherDatastoreCtrl#go_offline
* @methodOf psonocli.controller:OtherDatastoreCtrl
*
* @description
* Triggered once someone clicks the offline button in the top menu
*/
function go_offline() {
$uibModal.open({
templateUrl: 'view/modal-go-offline.html',
controller: 'ModalGoOfflineCtrl',
backdrop: 'static',
resolve: {
}
});
}
/**
* @ngdoc
* @name psonocli.controller:OtherDatastoreCtrl#go_online
* @methodOf psonocli.controller:OtherDatastoreCtrl
*
* @description
* Triggered once someone clicks the online button in the top menu
*/
function go_online() {
offlineCache.disable();
offlineCache.clear();
$scope.offline = false;
}
/**
* @ngdoc
* @name psonocli.controller:OtherDatastoreCtrl#refresh_datastore_dropdown
......
......@@ -4,15 +4,17 @@
/**
* @ngdoc controller
* @name psonocli.controller:ModalEditEntryCtrl
* @requires $rootScope
* @requires $scope
* @requires $uibModalInstance
* @requires psonocli.itemBlueprint
* @requires psonocli.offlineCache
*
* @description
* Controller for the "Edit Entry" modal
*/
angular.module('psonocli').controller('ModalEditEntryCtrl', ['$scope', '$uibModalInstance', 'itemBlueprint', 'node', 'path', 'data',
function ($scope, $uibModalInstance, itemBlueprint, node, path, data) {
angular.module('psonocli').controller('ModalEditEntryCtrl', ['$rootScope', '$scope', '$uibModalInstance', 'itemBlueprint', 'offlineCache', 'node', 'path', 'data',
function ($rootScope, $scope, $uibModalInstance, itemBlueprint, offlineCache, node, path, data) {
$scope.reset = reset;
$scope.save = save;
......@@ -29,6 +31,16 @@
activate();
function activate(){
scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
scope.offline = true;
});
$rootScope.$on('offline_mode_disabled', function() {
scope.offline = false;
});
$scope.bp = {
all: itemBlueprint.get_blueprints(),
selected: itemBlueprint.get_blueprint($scope.node.type)
......
......@@ -4,18 +4,22 @@
/**
* @ngdoc controller
* @name psonocli.controller:ModalEditGPGUserCtrl
* @requires $rootScope
* @requires $scope
* @requires $uibModalInstance
* @requires psonocli.managerDatastoreGPGUser
* @requires psonocli.helper
* @requires psonocli.offlineCache
* @requires psonocli.settings
* @requires psonocli.openpgp
*
* @description
* Controller for the "Edit Folder" modal
*/
angular.module('psonocli').controller('ModalEditGPGUserCtrl', ['$scope', '$uibModalInstance', 'managerDatastoreGPGUser', 'helper', 'settings', 'openpgp', 'user',
function ($scope, $uibModalInstance, managerDatastoreGPGUser, helper, settings, openpgp, user) {
angular.module('psonocli').controller('ModalEditGPGUserCtrl', ['$rootScope', '$scope', '$uibModalInstance',
'managerDatastoreGPGUser', 'helper', 'offlineCache', 'settings', 'openpgp', 'user',
function ($rootScope, $scope, $uibModalInstance,
managerDatastoreGPGUser, helper, offlineCache, settings, openpgp, user) {
$scope.cancel = cancel;
$scope.add_public_key = add_public_key;
......@@ -27,7 +31,18 @@
$scope.data = user;
$scope.data.new_email = user.email;
console.log(user);
activate();
function activate() {
$scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
$scope.offline = true;
});
$rootScope.$on('offline_mode_disabled', function() {
$scope.offline = false;
});
}
/**
* @ngdoc
......
(function(angular) {
'use strict';
/**
* @ngdoc controller
* @name psonocli.controller:ModalGoOfflineCtrl
* @requires $scope
* @requires $rootScope
* @requires $uibModalInstance
* @requires $uibModal
* @requires psonocli.offlineCache
*
* @description
* Controller for the "AcceptShare" modal
*/
angular.module('psonocli').controller('ModalGoOfflineCtrl', ['$scope', '$rootScope', '$uibModalInstance', '$uibModal',
'offlineCache', 'managerDatastore', 'managerDatastorePassword', 'managerExport',
function ($scope, $rootScope, $uibModalInstance, $uibModal,
offlineCache, managerDatastore, managerDatastorePassword, managerExport) {
$scope.cancel = cancel;
$scope.state = {
open_requests: 0,
closed_requests: 0,
finished_load_all_datastores: false
};
activate();
function activate() {
offlineCache.enable();
managerExport.on('get-secret-started', function(){
$scope.state.open_requests = $scope.state.open_requests + 1;
});
managerExport.on('get-secret-complete', function(){
$scope.state.closed_requests = $scope.state.closed_requests + 1;
});
managerDatastore.get_datastore_overview(true)
.then(load_all_datastores)
}
function potentially_close_modal() {
if ($scope.state.closed_requests === $scope.state.open_requests) {
$uibModalInstance.close();
}
}
function load_all_datastores(datastore_overview) {
for (var i = 0; i < datastore_overview.data.datastores.length; i++) {
$scope.state.open_requests = $scope.state.open_requests + 1;
if (datastore_overview.data.datastores[i]['type'] === 'password') {
managerDatastorePassword.get_password_datastore(datastore_overview.data.datastores[i]['id'])
.then(function(datastore) {
$scope.state.closed_requests = $scope.state.closed_requests + 1;
$scope.state.open_requests = $scope.state.open_requests + 1;
managerExport.get_all_secrets(datastore).then(function() {
$scope.state.closed_requests = $scope.state.closed_requests + 1;
potentially_close_modal();
});
});
} else {
managerDatastore.get_datastore_with_id(datastore_overview.data.datastores[i]['id']).then(function(datastore) {
$scope.state.closed_requests = $scope.state.closed_requests + 1;
potentially_close_modal();
})
}
}
$scope.state.finished_load_all_datastores = true;
potentially_close_modal();
}
/**
* @ngdoc
* @name psonocli.controller:ModalGoOfflineCtrl#cancel
* @methodOf psonocli.controller:ModalGoOfflineCtrl
*
* @description
* Triggered once someone clicks the cancel button in the modal
*/
function cancel() {
offlineCache.disable();
offlineCache.clear();
$uibModalInstance.dismiss('cancel');
}
}]
);
}(angular));
\ No newline at end of file
......@@ -4,17 +4,19 @@
/**
* @ngdoc directive
* @name ngTree.directive:treeViewNode
* @requires $rootScope
* @requires $q
* @requires $compile
* @requires $timeout
* @requires $uibModal
* @requires psonocli.offlineCache
* @requires ngTree.dropDownMenuWatcher
* @restrict A
*
* @description
* Directive for the node in a tree structure
*/
var treeViewNode = function($q, $compile, $timeout, $uibModal, dropDownMenuWatcher) {
var treeViewNode = function($rootScope, $q, $compile, $timeout, $uibModal, offlineCache, dropDownMenuWatcher) {
return {
restrict: 'A',
require: '^treeView',
......@@ -34,6 +36,16 @@
}, 5000);
scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
scope.offline = true;
});
$rootScope.$on('offline_mode_disabled', function() {
scope.offline = false;