diff --git a/www/js/app.js b/www/js/app.js index ae3b11533a95fd58b83c51db4c8e0b2a817bd751..f84094f92ba81e926ef10eff6f384d3714c3bae9 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -27,9 +27,6 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht Device, UIUtils, $ionicConfig, PluginService, csPlatform, csWallet) { 'ngInject'; - // Allow access to service data, from HTML templates - $rootScope.walletData = csWallet.data; - // Must be done before any other $stateChangeStart listeners csPlatform.disableChangeState(); @@ -60,8 +57,12 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht // endRemoveIf(ios) // endRemoveIf(android) + var wallet = nextParams.wallet && nextParams.wallet != "default" ? csWallet.children.get(nextParams.wallet) : csWallet; + if (nextParams.wallet && !wallet) { + console.warn("[app] Unable to find the children wallet: " + nextParams.wallet); + } // If state need auth - if (next.data.auth && !csWallet.isAuth()) { + if (next.data.auth && !wallet.isAuth()) { event.preventDefault(); options = next.data.minData ? {minData: true} : undefined; preventStateChange = true; @@ -101,11 +102,11 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht // If state need login or auth, make sure to load wallet data else if (next.data.login || next.data.auth) { options = next.data.minData ? {minData: true} : undefined; - if (!csWallet.isDataLoaded(options)) { + if (!wallet.isDataLoaded(options)) { event.preventDefault(); // Show loading message, when full load if (!options || !options.minData) UIUtils.loading.show(); - return csWallet.loadData(options) + return wallet.loadData(options) .then(function() { preventStateChange = false; return $state.go(next.name, nextParams); diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index 07b7d9d8092f7fe3cbc83928f49b1a9b9bc32026..768b17069e9f39e3cb2136752d419e00e4c98a01 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -69,6 +69,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ ) { 'ngInject'; + $scope.walletData = csWallet.data; $scope.search = {}; $scope.login = csWallet.isLogin(); $scope.auth = csWallet.isAuth(); @@ -384,9 +385,9 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ .catch(UIUtils.onError()); }; - // Login and go to a state (or wallet if not) + // Do authentification $scope.doAuth = function() { - return $scope.loadWallet({auth: true}) + return csWallet.auth() .then(function() { UIUtils.loading.hide(); }); @@ -400,20 +401,10 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ // add listener on wallet event csWallet.api.data.on.login($scope, function(data, deferred) { $scope.login = true; - //$rootScope.walletData = data || {}; - $scope.walletData = data || {}; - // $scope.walletData = { - // pubkey: data.pubkey, - // uid: data.uid, - // name: data.name, - // avatar: data.avatar - // }; return deferred ? deferred.resolve() : $q.when(); }); csWallet.api.data.on.logout($scope, function() { $scope.login = false; - //$rootScope.walletData = {}; - $scope.walletData = {}; }); csWallet.api.data.on.auth($scope, function(data, deferred) { $scope.auth = true; diff --git a/www/js/controllers/currency-controllers.js b/www/js/controllers/currency-controllers.js index af06607b2b4852e2ecfd215e188fe6cd6bcc9ba2..79e23f674bf8698bf910a3e8b56ed5e90ce74e2d 100644 --- a/www/js/controllers/currency-controllers.js +++ b/www/js/controllers/currency-controllers.js @@ -79,7 +79,7 @@ angular.module('cesium.currency.controllers', ['ngFileSaver', 'cesium.services'] function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA, UIUtils, csSettings, csCurrency, csNetwork, ModalUtils) { $scope.formData = { - useRelative: csSettings.data.useRelative, + useRelative: false, // Override in enter() currency: '', M: 0, MoverN: 0, @@ -117,7 +117,7 @@ function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA $scope.enter = function(e, state) { if ($scope.loading) { // run only once (first enter) - + $scope.formData.useRelative = csSettings.data.useRelative; csCurrency.get() .then($scope.load) .then(function() { @@ -277,7 +277,7 @@ function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA csSettings.store(); } }; - $scope.$watch('formData.allRules', $scope.onAllRulesChange, true); + $scope.$watch('formData.allRules', $scope.onAllRulesChange); $scope.onAllWotRulesChange = function() { csSettings.data.currency = csSettings.data.currency || {}; @@ -286,7 +286,7 @@ function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA csSettings.store(); } }; - $scope.$watch('formData.allWotRules', $scope.onAllWotRulesChange, true); + $scope.$watch('formData.allWotRules', $scope.onAllWotRulesChange); /* -- help tip -- */ diff --git a/www/js/controllers/login-controllers.js b/www/js/controllers/login-controllers.js index e3de96e9aeb95a5c18efc65e3b6bd55ef4c18c93..48571c588afeb5aa4ffb4a48bce954047db3572b 100644 --- a/www/js/controllers/login-controllers.js +++ b/www/js/controllers/login-controllers.js @@ -179,7 +179,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, } // Not a pubkey: launch search on else { - return $scope.showWotLookupModal(pubkey) + return $scope.showWotLookupModal(pubkey); } } } diff --git a/www/js/controllers/network-controllers.js b/www/js/controllers/network-controllers.js index 914509be96eede3f64a44b2f4e920312657a6d4e..0a1eb9c26700619dc30438f5d0a0c086965f6972 100644 --- a/www/js/controllers/network-controllers.js +++ b/www/js/controllers/network-controllers.js @@ -423,7 +423,6 @@ function NetworkLookupPopoverController($scope, $controller) { $scope.showHelpTip = function() {}; // Enter the popover - console.log("Will enter the popover !"); $scope.enter(); } diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index a8dcccc95c7d2c8d3319fa0ccc11657b0be8b8e0..c65809ff1d3f4cdd4f9129548ba4b80f50d34f19 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -604,7 +604,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, $scope.showSecurityModal = function(){ $scope.hideActionsPopover(); - return Modals.showAccountSecurity() + return Modals.showAccountSecurity({wallet: wallet}) .then(function(res) { if (!res) return; @@ -694,7 +694,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, .then(function(newWallet) { if (!newWallet || newWallet.id === wallet.id) return; if (newWallet.isDefault()) { - return $state.go('app.view_wallet') + return $state.go('app.view_wallet'); } return $state.go('app.view_wallet_by_id', {id: newWallet.id}); }); @@ -1010,7 +1010,7 @@ function WalletTxController($scope, $ionicPopover, $state, $timeout, $location, .then(function(newWallet) { if (!newWallet || newWallet.id === wallet.id) return; if (newWallet.isDefault()) { - return $scope.goState('app.view_wallet_tx') + return $scope.goState('app.view_wallet_tx'); } return $scope.goState('app.view_wallet_tx_by_id', {id: newWallet.id}); }); @@ -1092,7 +1092,9 @@ function WalletTxErrorController($scope, UIUtils, csSettings, csWallet) { } -function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ +function WalletSecurityModalController($scope, UIUtils, csWallet, $translate, parameters){ + + var wallet = parameters && parameters.wallet || csWallet; $scope.slides = { slider: null, @@ -1108,10 +1110,11 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ $scope.recover = {}; $scope.isValidFile = false; - $scope.isLogin = csWallet.isLogin(); - $scope.hasSelf = csWallet.hasSelf(); - $scope.needSelf = $scope.isLogin && csWallet.data.requirements.needSelf; - $scope.needMembership = $scope.isLogin && csWallet.data.requirements.needMembership; + + $scope.isLogin = wallet.isLogin(); + $scope.hasSelf = wallet.hasSelf(); + $scope.needSelf = $scope.isLogin && wallet.data.requirements.needSelf; + $scope.needMembership = $scope.isLogin && wallet.data.requirements.needMembership; $scope.option = $scope.isLogin ? 'saveID' : 'recoverID'; $scope.formData = { @@ -1295,7 +1298,7 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ $scope.recover.answer += element.answer; }); - return csWallet.recoverId($scope.recover) + return wallet.recoverId($scope.recover) .then(function (recover){ if (angular.isDefined(recover)) { $scope.recover = recover; @@ -1321,7 +1324,7 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ $scope.downloadSaveIDFile = function(){ // Force user re-auth var loginData; - return csWallet.auth({ + return wallet.auth({ forceAuth: true, expectedPubkey: $scope.pubkey, silent: true, @@ -1352,9 +1355,9 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ record.answer += question.answer; }); - return csWallet.getCryptedId(record) + return wallet.getCryptedId(record) .then(function(record){ - csWallet.downloadSaveId(record); + wallet.downloadSaveId(record); $scope.closeModal(); }); }) @@ -1382,11 +1385,11 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ */ $scope.downloadRevokeFile = function () { // Force re-authentication - return csWallet.auth({forceAuth: true}) + return wallet.auth({forceAuth: true}) // Download file .then(function() { - return csWallet.downloadRevocation(); + return wallet.downloadRevocation(); }) .then(function() { @@ -1410,7 +1413,7 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ } // Make sure user re-auth - return csWallet.auth({forceAuth: true}) + return wallet.auth({forceAuth: true}) .then(function(confirm) { UIUtils.loading.hide(); if (!confirm) return; @@ -1450,10 +1453,10 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ return UIUtils.loading.show() .then(function () { if (!$scope.revocation){ - return csWallet.revoke(); + return wallet.revoke(); } else { - return csWallet.revokeWithFile($scope.revocation); + return wallet.revokeWithFile($scope.revocation); } }) .then(function () { @@ -1484,11 +1487,11 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate){ */ $scope.downloadKeyFile = function (format) { // Force re-authentication - return csWallet.auth({forceAuth: true}) + return wallet.auth({forceAuth: true}) // Download file .then(function() { - return csWallet.downloadKeyFile(format); + return wallet.downloadKeyFile(format); }) .then(function() { @@ -1578,9 +1581,7 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl } UIUtils.onError('ERROR.SAVE_WALLET_LIST_FAILED')(err); }); - }) - - + }); }; /* -- modals -- */ diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index 43d11601fd61699413f90a711c54b1c3ca31990b..80679e0f8696f429aef17d9109dbd187e811307b 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -48,8 +48,8 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) var constants = { - OLD_STORAGE_KEY: 'CESIUM_SETTINGS', - STORAGE_KEY: 'settings', + OLD_STORAGE_KEY: 'CESIUM_SETTINGS', // for version < v1.1 + STORAGE_KEY: 'settings', // for version >= v1.1.0 KEEP_AUTH_IDLE_SESSION: 9999 }, defaultSettings = angular.merge({ @@ -221,7 +221,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) var now = new Date().getTime(); return $q.all([ - localStorage.getObject(constants.OLD_STORAGE_KEY), + localStorage.getObject(constants.OLD_STORAGE_KEY), // for version < v1.1 localStorage.getObject(constants.STORAGE_KEY) ]) .then(function(res) { diff --git a/www/js/services/storage-services.js b/www/js/services/storage-services.js index 3f6645931cfe407180fbfff5bc620056b92aec23..7034667da986834d4a7d2b5d02b24c444cdaf0fe 100644 --- a/www/js/services/storage-services.js +++ b/www/js/services/storage-services.js @@ -24,7 +24,7 @@ angular.module('cesium.storage.services', [ 'cesium.config']) }; exports.getObject = function(key) { - return $q.when(JSON.parse(exports.storage[key] || '{}')); + return $q.when(JSON.parse(exports.storage[key] || 'null')); }; return exports; @@ -74,7 +74,7 @@ angular.module('cesium.storage.services', [ 'cesium.config']) }; exports.standard.getObject = function(key) { - return $q.when(JSON.parse(exports.standard.storage[key] || '{}')); + return $q.when(JSON.parse(exports.standard.storage[key] || 'null')); }; /* -- Use secure storage (using a cordova plugin) -- */ @@ -124,7 +124,7 @@ angular.module('cesium.storage.services', [ 'cesium.config']) exports.secure.getObject = function(key) { return exports.secure.storage.get(key) .then(function(value) { - return (value && JSON.parse(value)) || {}; + return JSON.parse(value||'null'); }); }; diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index c3d2cb5be133ea876a0d1801abd549176a574196..8a147530f07541d35bc7d4ea26c6914045360bc2 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -32,7 +32,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se TX_MAX_INPUTS_COUNT: 40 // Allow to get a TX with less than 100 rows (=max row count in Duniter protocol) }, data = {}, - encrypted = false, + settings, listeners, started, startPromise, @@ -71,7 +71,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se api.data.raise.init(data); } else { - if (isDefault() && !csSettings.data.useLocalStorage) { + if (isDefault() && settings && !settings.useLocalStorage) { csSettings.reset(); } api.data.raise.reset(data); @@ -375,9 +375,9 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // store pubkey and uid store = function(pubkey) { pubkey = pubkey && typeof pubkey == 'string' ? pubkey : data.pubkey; - if (csSettings.data.useLocalStorage) { + if (settings.useLocalStorage) { - if (isLogin() && csSettings.data.rememberMe) { + if (isLogin() && settings.rememberMe) { var now = new Date().getTime(); console.debug("[wallet] Storing..."); @@ -385,7 +385,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se var jobs = []; // Use session storage for secret key - fix #372 - if (csSettings.data.keepAuthIdle == constants.KEEP_AUTH_IDLE_SESSION && isAuth()) { + if (settings.keepAuthIdle == constants.KEEP_AUTH_IDLE_SESSION && isAuth()) { jobs.push(sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.base58.encode(data.keypair.signSk))); } else { @@ -434,15 +434,18 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // reset data store for this pubkey resetStore = function(pubkey) { + console.debug("[wallet] Resetting stored pubkey (and uid) in local storage..."); + sessionStorage.put(constants.STORAGE_SECKEY, null); localStorage.put(constants.STORAGE_PUBKEY, null); localStorage.put(constants.STORAGE_UID, null); - if (csSettings.data.useLocalStorage) { + if (settings.useLocalStorage) { // Clean data (only in the session storage - keep local) - return pubkey ? sessionStorage.put(constants.STORAGE_DATA_PREFIX + pubkey, null) : $q.when() + return pubkey ? sessionStorage.put(constants.STORAGE_DATA_PREFIX + pubkey, null) : $q.when(); } else { + console.debug("[wallet] Resetting stored data in local storage..."); return $q.all([ pubkey ? sessionStorage.put(constants.STORAGE_DATA_PREFIX + pubkey, null) : $q.when(), pubkey ? localStorage.put(constants.STORAGE_DATA_PREFIX + pubkey, null) : $q.when() @@ -454,7 +457,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se storeData = function() { if (!isLogin()) throw {message:'ERROR.NEED_LOGIN_FIRST'}; - var useEncryption = csSettings.data.useLocalStorageEncryption; + var useEncryption = settings.useLocalStorageEncryption; var storageKey = constants.STORAGE_DATA_PREFIX + data.pubkey; var content; // Init only if used @@ -526,7 +529,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }); //console.debug("[wallet] Storing with encryption: ", content); return localStorage.put(storageKey, JSON.stringify(content)); - }) + }); }); }, @@ -593,15 +596,12 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se if (isNew()) return $q.when(data); // Skip restore // Get pubkey's data return $q.all([ - sessionStorage.get(constants.STORAGE_DATA_PREFIX + data.pubkey), - localStorage.get(constants.STORAGE_DATA_PREFIX + data.pubkey) + sessionStorage.getObject(constants.STORAGE_DATA_PREFIX + data.pubkey), + localStorage.getObject(constants.STORAGE_DATA_PREFIX + data.pubkey) ]) // Apply data, first from the session storage, then from local storage .then(function (res) { - var sessionData = res[0] && res[0] != "null" && res[0]; - var localData = res[1] && res[1] != "null" && res[1]; - var restoredData = sessionData || localData; - return applyRestoredData(restoredData && JSON.parse(restoredData)); + return applyRestoredData(res[0] || res[1]); }); }, @@ -717,7 +717,6 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se addEvents = function() { // Add user events if (data.requirements.revoked) { - console.log("REVOKED !!"); addEvent({type:'info', message: 'ERROR.WALLET_REVOKED', context: 'requirements'}); } else if (data.requirements.pendingRevocation) { @@ -949,7 +948,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se return api.data.raisePromise.load(data) .then(function(){ return data; - }) + }); }); }, @@ -1612,7 +1611,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se return $q.all([ CryptoUtils.box.pack(record.salt, nonce, record.keypair.boxPk, record.keypair.boxSk), CryptoUtils.box.pack(record.pwd, nonce, record.keypair.boxPk, record.keypair.boxSk) - ]) + ]); }) .then(function (res) { record.salt = res[0]; @@ -2020,17 +2019,17 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }); }, - checkAuthIdle = function(isAuth) { - isAuth = angular.isDefined(isAuth) ? isAuth : isAuth(); - var enable = isAuth && csSettings.data.keepAuthIdle > 0 && csSettings.data.keepAuthIdle != csSettings.constants.KEEP_AUTH_IDLE_SESSION; + checkAuthIdle = function(isAuthRes) { + isAuthRes = angular.isDefined(isAuthRes) ? isAuthRes : isAuth(); + var enable = isAuthRes && settings.keepAuthIdle > 0 && settings.keepAuthIdle != csSettings.constants.KEEP_AUTH_IDLE_SESSION; var changed = (enableAuthIdle != enable); // need start/top watching if (changed) { // start idle if (enable) { - console.debug("[wallet] Start idle (delay: {0}s)".format(csSettings.data.keepAuthIdle)); - Idle.setIdle(csSettings.data.keepAuthIdle); + console.debug("[wallet] Start idle (delay: {0}s)".format(settings.keepAuthIdle)); + Idle.setIdle(settings.keepAuthIdle); Idle.watch(); } // stop idle, if need @@ -2042,30 +2041,46 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se } // if idle time changed: apply it - else if (enable && Idle.getIdle() !== csSettings.data.keepAuthIdle) { - console.debug("[idle] Updating auth idle (delay: {0}s)".format(csSettings.data.keepAuthIdle)); - Idle.setIdle(csSettings.data.keepAuthIdle); + else if (enable && Idle.getIdle() !== settings.keepAuthIdle) { + console.debug("[idle] Updating auth idle (delay: {0}s)".format(settings.keepAuthIdle)); + Idle.setIdle(settings.keepAuthIdle); } }; - var settings = initSettingsChanged(csSettings.data); - - function initSettingsChanged(settings) { + function getWalletSettings(settings) { return { useLocalStorage: settings.useLocalStorage, useLocalStorageEncryption: settings.useLocalStorageEncryption, - rememberMe: settings.useLocalStorage, + rememberMe: settings.rememberMe, keepAuthIdle: settings.keepAuthIdle }; } - function onSettingsChanged(newSettings) { - var hasChanged = !angular.equals(settings, initSettingsChanged(newSettings)); + function onSettingsChanged(allSettings) { + var newSettings = getWalletSettings(allSettings); + var hasChanged = !angular.equals(settings, newSettings); if (hasChanged) { - console.debug("[wallet] Settings changed: applying to wallet (will store, and recheck idle)"); - store(); - storeData(); - checkAuthIdle(); + var useStorageChanged = !angular.equals(settings.useLocalStorage, newSettings.useLocalStorage) || + !angular.equals(settings.useLocalStorageEncryption, newSettings.useLocalStorageEncryption); + var keepAuthIdleChanged = !angular.equals(settings.keepAuthIdle, newSettings.keepAuthIdle); + + settings = newSettings; + + if (keepAuthIdleChanged) { + checkAuthIdle(); + } + + if (useStorageChanged) { + // Reset stored data + if (!settings.useLocalStorage) { + resetStore(data.pubkey); + } + else { + // Or stored login data + store(); + storeData(); + } + } } } @@ -2117,7 +2132,10 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se var now = new Date().getTime(); startPromise = $q.all([ - csSettings.ready(), + csSettings.ready() + .then(function() { + settings = getWalletSettings(csSettings.data); + }), csCurrency.ready(), BMA.ready() ]); diff --git a/www/plugins/es/js/controllers/invitation-controllers.js b/www/plugins/es/js/controllers/invitation-controllers.js index 5c7e6e048710647db7b7a0d47d3aee410c281d22..41e5c95a5ac7d79fa8fee5bf02feab0ecb28f16a 100644 --- a/www/plugins/es/js/controllers/invitation-controllers.js +++ b/www/plugins/es/js/controllers/invitation-controllers.js @@ -175,7 +175,7 @@ function InvitationsController($scope, $q, $ionicPopover, $state, $timeout, UIUt if (!$scope.search.results || !$scope.search.results.length) return; var lastNotification = $scope.search.results[0]; var readTime = lastNotification.time ? lastNotification.time : 0; - if (readTime && (!wallet.data.invitations.time != readTime)) { + if (readTime && (!wallet.data.invitations.readTime || wallet.data.invitations.readTime != readTime)) { wallet.data.invitations.readTime = readTime; wallet.storeData(); } @@ -276,7 +276,7 @@ function InvitationsController($scope, $q, $ionicPopover, $state, $timeout, UIUt esInvitation.api.data.on.new($scope, $scope.onNewInvitation) ); } - } + }; } function PopoverInvitationController($scope, $controller, csWallet) { diff --git a/www/plugins/es/js/controllers/message-controllers.js b/www/plugins/es/js/controllers/message-controllers.js index b2f7e1c0a26bd94bb51a96ac89100cd217124710..5cd8f2b4167f351a0c0dfc0a74a664fe7ca64ec6 100644 --- a/www/plugins/es/js/controllers/message-controllers.js +++ b/www/plugins/es/js/controllers/message-controllers.js @@ -550,7 +550,7 @@ function ESMessageComposeModalController($scope, Modals, UIUtils, csWallet, esHt if (err === 'CANCELLED') { $scope.cancel(); } - }) + }); }; $scope.$on('modal.shown', $scope.load); diff --git a/www/plugins/es/js/controllers/notification-controllers.js b/www/plugins/es/js/controllers/notification-controllers.js index 53f38dde95d2c1f080f472ebe7f9af9d3c23488a..edbb1d82f441eb28584370a279234fa22edab173 100644 --- a/www/plugins/es/js/controllers/notification-controllers.js +++ b/www/plugins/es/js/controllers/notification-controllers.js @@ -28,7 +28,7 @@ angular.module('cesium.es.notification.controllers', ['cesium.es.services']) ; -function NotificationsController($scope, $ionicPopover, $state, $timeout, UIUtils, esHttp, csSettings, csWallet, esNotification) { +function NotificationsController($scope, $ionicPopover, $state, $timeout, UIUtils, esHttp, csWallet, esNotification) { 'ngInject'; var defaultSearchLimit = 40; @@ -158,11 +158,14 @@ function NotificationsController($scope, $ionicPopover, $state, $timeout, UIUtil }; $scope.resetUnreadCount = function() { + if ($scope.search.loading || !wallet.data.notifications) { + return $timeout($scope.resetUnreadCount, 2000); + } if (!wallet.data.notifications.unreadCount || !$scope.search.results || !$scope.search.results.length) return; wallet.data.notifications.unreadCount = 0; var lastNotification = $scope.search.results[0]; var readTime = lastNotification.time ? lastNotification.time : 0; - if (readTime && (!wallet.data.notifications.readTime != readTime)) { + if (readTime && (!wallet.data.notifications.readTime || wallet.data.notifications.readTime != readTime)) { wallet.data.notifications.readTime = readTime; wallet.storeData(); } diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index 2db3b94e916f94c6b890b4acbbfcc5f67ba2f12a..11d9676b22eab26a7f344a20404486a040cf6a43 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -1026,6 +1026,7 @@ function ESRegistryRecordEditController($scope, $timeout, $state, $q, $ionicHis if ($scope.loading) { wallet = (state.stateParams && state.stateParams.wallet && state.stateParams.wallet != 'default') ? csWallet.children.get(state.stateParams.wallet) : csWallet; + console.log(wallet); if (!wallet) { UIUtils.alert.error('ERROR.UNKNOWN_WALLET_ID'); return $scope.showHome(); diff --git a/www/plugins/es/js/controllers/subscription-controllers.js b/www/plugins/es/js/controllers/subscription-controllers.js index fd084fc5c77cc6c64852621b09d9576fab6539dd..43b843da2ce36104dbc67a2da504d9cb5bedabb6 100644 --- a/www/plugins/es/js/controllers/subscription-controllers.js +++ b/www/plugins/es/js/controllers/subscription-controllers.js @@ -81,7 +81,7 @@ function ViewSubscriptionsController($scope, $q, $ionicHistory, csWot, csWallet, if (err == 'CANCELLED') { UIUtils.loading.hide(10); $ionicHistory.goBack(); - return + return; } UIUtils.onError('SUBSCRIPTION.ERROR.LOAD_SUBSCRIPTIONS_FAILED')(err); }); diff --git a/www/plugins/es/js/controllers/wallet-controllers.js b/www/plugins/es/js/controllers/wallet-controllers.js index 664b4f0ded763479065065cd73cb40e0b9f2d979..395f1c1c39370927ee7c79ccb77c2ba6a3fc46bb 100644 --- a/www/plugins/es/js/controllers/wallet-controllers.js +++ b/www/plugins/es/js/controllers/wallet-controllers.js @@ -24,7 +24,7 @@ angular.module('cesium.es.wallet.controllers', ['cesium.es.services']) ; -function ESWalletController($scope, $controller, esModals) { +function ESWalletController($scope, $controller, $state, esModals, csWallet) { 'ngInject'; // Initialize the super class and extend it. @@ -35,7 +35,13 @@ function ESWalletController($scope, $controller, esModals) { /* -- modals -- */ $scope.showNewPageModal = function() { - return esModals.showNewPage(); + var wallet = ($state.params && $state.params.id) ? csWallet.children.get($state.params.id) : csWallet; + if (!wallet) { + UIUtils.alert.error('ERROR.UNKNOWN_WALLET_ID'); + return; + } + + return esModals.showNewPage({wallet: wallet}); }; } diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index 2630d2996513a4397d89502bfa3901e551f2f7e2..853c78e8e69dea8dfcd7bf150de01e2483f924d8 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -151,7 +151,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', api.data.raise.sent(res); return res; - }) + }); }); } diff --git a/www/plugins/es/js/services/notification-services.js b/www/plugins/es/js/services/notification-services.js index 0e5f8840c4ab2ec532ef7a610207d218e1597afb..6ba475cad14c5810f5f29cf92f6d5fd64657c6b8 100644 --- a/www/plugins/es/js/services/notification-services.js +++ b/www/plugins/es/js/services/notification-services.js @@ -279,9 +279,7 @@ angular.module('cesium.es.notification.services', ['cesium.platform', 'cesium.es console.debug('[ES] [notification] Loaded count (' + unreadCount + ') in '+(new Date().getTime()-now)+'ms'); deferred.resolve(data); }) - .catch(deferred.reject) - - + .catch(deferred.reject); return deferred.promise; } diff --git a/www/plugins/es/js/services/settings-services.js b/www/plugins/es/js/services/settings-services.js index 3d7a52c7656c0f881fa07a158f386940e7ef0968..d05402be681c30bd9fa069e5550bc2c5fccb80da 100644 --- a/www/plugins/es/js/services/settings-services.js +++ b/www/plugins/es/js/services/settings-services.js @@ -283,10 +283,11 @@ angular.module('cesium.es.settings.services', ['cesium.services', 'cesium.es.htt that.add(record) : that.update(record, {id: record.issuer}) .catch(function(err) { - // update failed: try add + // Workaround if update failed: try to add() instead + // Can occur when changing the cesium+ pod if (err && err.ucode == 404) return that.add(record); throw err; - }) + }); }) .then(function() { return true; diff --git a/www/plugins/es/templates/document/item_document.html b/www/plugins/es/templates/document/item_document.html index c2f764fc50fa310b1849f63a27a536e9807147e0..2aac1e6d0d566c2f04016f9751bd8a8a555e4c54 100644 --- a/www/plugins/es/templates/document/item_document.html +++ b/www/plugins/es/templates/document/item_document.html @@ -28,7 +28,7 @@ <div class="col"> <a - ng-if=":rebind:login && doc.pubkey==$root.walletData.pubkey" + ng-if=":rebind:login && doc.pubkey==walletData.pubkey" ng-click="remove($index)" class="gray pull-right" title="{{'DOCUMENT.LOOKUP.BTN_REMOVE'|translate}}"> diff --git a/www/plugins/map/js/controllers/registry-controllers.js b/www/plugins/map/js/controllers/registry-controllers.js index 9efde6a6ea1f07351b0eb8d053b1dd4ca963056c..8c458fb9e8466bc1092717f4bd654f999f4a0e4d 100644 --- a/www/plugins/map/js/controllers/registry-controllers.js +++ b/www/plugins/map/js/controllers/registry-controllers.js @@ -50,7 +50,8 @@ angular.module('cesium.map.registry.controllers', ['cesium.services', 'cesium.ma function MapRegistryViewController($scope, $filter, $templateCache, $interpolate, $timeout, $location, $translate, $q, - leafletData, UIUtils, csSettings, csWallet, MapUtils, mapRegistry) { + ionicReady, leafletData, + UIUtils, csSettings, csWallet, MapUtils, mapRegistry) { 'ngInject'; var @@ -115,6 +116,15 @@ function MapRegistryViewController($scope, $filter, $templateCache, $interpolate loading: true }, $scope.mapId); + // Variables for marker + $scope.formData = {}; + $scope.showDescription = false; + ionicReady().then(function() { + $scope.enableDescription = !UIUtils.screen.isSmall() && ionic.Platform.grade.toLowerCase() === 'a'; + if (!$scope.enableDescription) { + console.debug("[map] [wot] Disable profile description.", ionic.Platform.grade); + } + }); $scope.$on('$ionicView.beforeEnter', function (event, viewData) { // Enable back button (workaround need for navigation outside tabs - https://stackoverflow.com/a/35064602) @@ -168,19 +178,6 @@ function MapRegistryViewController($scope, $filter, $templateCache, $interpolate if (!$scope.map.loading) return map; // already loaded if (!UIUtils.screen.isSmall()) { - // Add a start tour button - /*L.easyButton({ - position: 'topright', // inherited from L.Control -- the corner it goes in - type: 'replace', // set to animate when you're comfy with css - leafletClasses: true, // use leaflet classes to style the button? - states:[{ // specify different icons and responses for your button - stateName: 'show-help-tour', - onClick: $scope.startHelpTour, - title: translations['COMMON.BTN_HELP_TOUR_SCREEN'], - icon: 'icon ion-easel' - }] - } - ).addTo(map);*/ // Add a refresh button L.easyButton({ @@ -291,7 +288,7 @@ function MapRegistryViewController($scope, $filter, $templateCache, $interpolate var options = { fields: { - description: !UIUtils.screen.isSmall() + description: $scope.enableDescription } }; @@ -307,41 +304,42 @@ function MapRegistryViewController($scope, $filter, $templateCache, $interpolate if (res && res.length) { var formatPubkey = $filter('formatPubkey'); - var userMarkerTemplate = $templateCache.get('plugins/map/templates/wot/popup_marker.html'); - var pageMarkerTemplate = $templateCache.get('plugins/map/templates/wot/popup_page_marker.html'); + var pageMarkerTemplate = $templateCache.get('plugins/map/templates/registry/popup_marker.html'); _.forEach(res, function (hit) { - var type = hit.type || (hit.pending ? 'pending' : (hit.uid ? 'member' : 'wallet')); var shortPubkey = formatPubkey(hit.pubkey); - var id = hit.index + '_' + (hit.id || (hit.uid ? (hit.uid + ':' + hit.pubkey) : hit.pubkey)).replace(/-/g, '_'); + var id = hit.index + '_' + (hit.id).replace(/-/g, '_'); var marker = { - layer: type, - icon: icons[type], - opacity: hit.uid || hit.type ? 1 : 0.7, + layer: hit.type, + icon: icons[hit.type], + opacity: 1, title: hit.name + ' | ' + shortPubkey, lat: hit.geoPoint.lat, lng: hit.geoPoint.lon, getMessageScope: function () { - var scope = $scope.$new(); - scope.hit = hit; - return scope; + $scope.loading = true; + $scope.$applyAsync(function() { + angular.extend($scope.formData, hit); + $scope.loading = false; + }); + return $scope; }, focus: false, - message: hit.type ? pageMarkerTemplate : userMarkerTemplate, + message: pageMarkerTemplate, id: id }; markers[id] = marker; // Create a search marker (will be hide) - var searchText = hit.name + ((hit.uid && hit.uid != hit.name) ? (' | ' + hit.uid) : '') + ' | ' + shortPubkey; + var searchText = hit.name + ' | ' + shortPubkey; var searchMarker = angular.merge({ - type: type, + type: hit.type, opacity: 0, icon: L.divIcon({ - className: type + ' ng-hide', + className: hit.type + ' ng-hide', iconSize: L.point(0, 0) }) - }, {title: searchText, pubkey: hit.pubkey, uid: hit.uid, name: hit.name, pending: hit.pending, popupMarkerId: id}); + }, {title: searchText, pubkey: hit.pubkey, name: hit.name, popupMarkerId: id}); markersSearchLayer.addLayer(new L.Marker({ lat: hit.geoPoint.lat, lng: hit.geoPoint.lon diff --git a/www/plugins/map/js/controllers/wot-controllers.js b/www/plugins/map/js/controllers/wot-controllers.js index 93ca78e0171bcbeb4b661b32339558881e7985d3..892abd3fe245f41d279b7257d4259f655783d4e3 100644 --- a/www/plugins/map/js/controllers/wot-controllers.js +++ b/www/plugins/map/js/controllers/wot-controllers.js @@ -112,10 +112,11 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti loading: true }, $scope.mapId); - $scope.showDescription = !UIUtils.screen.isSmall(); + // Variables for marker + $scope.showDescription = false; ionicReady().then(function() { - $scope.showDescription = $scope.showDescription && ionic.Platform.grade.toLowerCase() === 'a'; - if (!$scope.showDescription) { + $scope.enableDescription = !UIUtils.screen.isSmall() && ionic.Platform.grade.toLowerCase() === 'a'; + if (!$scope.enableDescription) { console.debug("[map] [wot] Disable profile description.", ionic.Platform.grade); } }); @@ -301,8 +302,7 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti var options = { fields: { - description: ionic.Platform.grade.toLowerCase()==='a' && - !UIUtils.screen.isSmall() + description: $scope.enableDescription } }; @@ -324,8 +324,7 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti if (res && res.length) { var formatPubkey = $filter('formatPubkey'); - var userMarkerTemplate = $templateCache.get('plugins/map/templates/wot/popup_marker.html'); - var pageMarkerTemplate = $templateCache.get('plugins/map/templates/wot/popup_page_marker.html'); + var markerTemplate = $templateCache.get('plugins/map/templates/wot/popup_marker.html'); _.forEach(res, function (hit) { var type = hit.pending ? 'pending' : (hit.uid ? 'member' : 'wallet'); @@ -334,7 +333,7 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti var marker = { layer: type, icon: icons[type], - opacity: hit.uid || hit.type ? 1 : 0.7, + opacity: hit.uid ? 1 : 0.7, title: hit.name + ' | ' + shortPubkey, lat: hit.geoPoint.lat, lng: hit.geoPoint.lon, @@ -352,7 +351,7 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti return $scope; }, focus: false, - message: hit.type ? pageMarkerTemplate : userMarkerTemplate, + message: markerTemplate, id: id }; markers[id] = marker; diff --git a/www/plugins/map/templates/registry/popup_marker.html b/www/plugins/map/templates/registry/popup_marker.html new file mode 100644 index 0000000000000000000000000000000000000000..cec8ff96e7151f362cb307569d0785fa2eb95f96 --- /dev/null +++ b/www/plugins/map/templates/registry/popup_marker.html @@ -0,0 +1,51 @@ +<div class="item no-border no-padding item-avatar " + ng-if="loading"> + + <i class="item-image icon ion-person"></i> + + <div class="item-content item-avatar-left-padding padding-top" > + <h2 class="stable-bg"> + + </h2> + <h4 class="stable-bg col-75"> + + </h4> + <h4 class="stable-bg col-50"> + + </h4> + </div> +</div> + +<a class="item no-border no-padding item-avatar ink animate-fade-in animate-show-hide ng-hide" + ng-show="!loading" + ui-sref="app.view_page({id: formData.id, title: formData.name})"> + <i ng-if="formData.avatar" class="item-image avatar" style="background-image: url({{::formData.avatar.src}}"></i> + <i ng-if="!formData.avatar" class="item-image icon cion-page-{{::formData.type}}"></i> + <div class="item-content item-avatar-left-padding padding-top"> + <h2 class="dark"> + {{::formData.name}} + </h2> + <h4 ng-if="::formData.category" class="gray" title="{{::formData.category.name}}"> + <b class="ion-flag"></b> {{::formData.category.name}} + </h4> + <h4 ng-if="::formData.city" class="gray" title="{{::formData.city}}"> + <b class="ion-location"></b> {{::formData.city}} + </h4> + </div> +</a> +<!-- buttons --> +<div class="item no-border no-padding"> + <div class="pull-left gray"> + <!-- show description --> + <a class="animate-fade-in animate-show-hide gray ng-hide" + ng-class="{'ion-arrow-down-b': !showDescription, 'ion-arrow-up-b': showDescription}" + ng-click="showDescription=!showDescription;" + title="{{'PROFILE.DESCRIPTION'|translate}}" + ng-show="!loading && formData.description"> + + </a> + </div> +</div> +<div class="item no-border no-padding item-text-wrap hidden-xs ng-hide" ng-show="showDescription"> + <small trust-as-html="::formData.description|truncText:500"></small> +</div> diff --git a/www/plugins/map/templates/wot/popup_marker.html b/www/plugins/map/templates/wot/popup_marker.html index 7b00531e1154574823068d4e67408ee2e2fc7556..84322f5c700140fc74f475804c75bcbfca9a48f7 100644 --- a/www/plugins/map/templates/wot/popup_marker.html +++ b/www/plugins/map/templates/wot/popup_marker.html @@ -49,8 +49,8 @@ <div class="pull-left gray"> <!-- show description --> <a class="animate-fade-in animate-show-hide gray ng-hide" - ng-class="{'ion-arrow-down-b': !$parent.showDescription, 'ion-arrow-up-b': $parent.showDescription}" - ng-click="$parent.showDescription=!$parent.showDescription;" + ng-class="{'ion-arrow-down-b': !showDescription, 'ion-arrow-up-b': showDescription}" + ng-click="showDescription=!showDescription;" title="{{'PROFILE.DESCRIPTION'|translate}}" ng-show="!loading && formData.profile.description"> @@ -77,6 +77,6 @@ </div> </div> -<div class="item no-border no-padding item-text-wrap hidden-xs ng-hide" ng-show="$parent.showDescription"> +<div class="item no-border no-padding item-text-wrap hidden-xs ng-hide" ng-show="showDescription"> <small trust-as-html="formData.profile.description|truncText:500"></small> </div> diff --git a/www/plugins/map/templates/wot/popup_page_marker.html b/www/plugins/map/templates/wot/popup_page_marker.html deleted file mode 100644 index ded9405b0f6770a617f1956c45a2c3c41fc3f639..0000000000000000000000000000000000000000 --- a/www/plugins/map/templates/wot/popup_page_marker.html +++ /dev/null @@ -1,16 +0,0 @@ -<div class="item no-border no-padding item-avatar" ng-class="::{'item-avatar': hit.avatar}"> - <img ng-if="::hit.avatar" class="item-image avatar" ng-src="{{::hit.avatar.src}}"> - <i ng-if="::!hit.avatar" class="item-image icon cion-page-{{::hit.type}}"></i> - <div class="item-content item-avatar-left-padding padding-top"> - <h2 class="dark"><a ui-sref="app.view_page({id: hit.id, title: hit.title})">{{::hit.name}}</a></h2> - <h4 ng-if="::hit.category" class="gray" title="{{::hit.category.name}}"> - <a ui-sref="app.registry_lookup({category: hit.category.id})"><b class="ion-flag"></b> {{::hit.category.name}}</a> - </h4> - <h4 ng-if="::hit.city" class="gray" title="{{::hit.city}}"> - <b class="ion-location"></b> {{::hit.city}} - </h4> - </div> -</div> -<div class="item no-border no-padding item-text-wrap hidden-xs" ng-if="::hit.description"> - <small trust-as-html="::hit.description"></small> -</div>