From 62746e94a019ad764e2e5aa162e602a18fe4badb Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Mon, 13 Mar 2017 11:18:17 +0100 Subject: [PATCH] - share links now use base path - fix #390 - Optimize code for HTTPS redirection, and remove it for device build --- www/js/app.js | 26 ++++++++----------- www/js/controllers/wallet-controllers.js | 3 ++- www/js/controllers/wot-controllers.js | 3 ++- .../es/js/controllers/market-controllers.js | 2 +- .../es/js/controllers/registry-controllers.js | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index cedd5eed7..eaf82f55c 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -310,6 +310,11 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht $rootScope.walletData = csWallet.data; $rootScope.device = Device; + // Compute the root path + var hashIndex = $window.location.href.indexOf('#'); + $rootScope.rootPath = (hashIndex != -1) ? $window.location.href.substr(0, hashIndex) : $window.location.href; + console.debug('[app] Detecting root path: ' + $rootScope.rootPath); + // removeIf(device) // Automatic redirection to large state (if define) $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { @@ -321,25 +326,16 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht } } }); - // endRemoveIf(device) - // Force redirection to HTTPS - if (csConfig.httpsMode === true || csConfig.httpsMode === "true" || csConfig.httpsMode === 'force') { + // Automatic redirection to HTTPS + if ((csConfig.httpsMode == true || csConfig.httpsMode === 'force') && + $window.location.protocol != 'https:') { $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if($window.location.protocol != 'https:') { - var href = $window.location.href; - var hashIndex = href.indexOf('#'); - var rootPath = (hashIndex != -1) ? href.substr(0, hashIndex) : href; - var path = 'https' + rootPath.substr(4) + $state.href(next, nextParams); - if (csConfig.httpsModeDebug) { - console.debug('[httpsMode] --- Should redirect to: ' + path); - } - else { - $window.location.href = path; - } - } + var path = 'https' + $rootScope.rootPath.substr(4) + $state.href(next, nextParams); + $window.location.href = path; }); } + // endRemoveIf(device) // Update some translations, when locale changed function onLocaleChange() { diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index 91e1b0a8d..0b1284159 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -465,7 +465,8 @@ function WalletController($scope, $q, $ionicPopup, $timeout, $state, $scope.hideActionsPopover(); var title = $scope.formData.name || $scope.formData.uid || $scope.formData.pubkey; - var url = $state.href('app.wot_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.name || $scope.formData.uid}, {absolute: true}); + // Use rootPath (fix #390) + var url = $rootScope.rootPath + $state.href('app.wot_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.name || $scope.formData.uid}); UIUtils.popover.share(event, { bindings: { url: url, diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js index af33f1e09..bfc74d37a 100644 --- a/www/js/controllers/wot-controllers.js +++ b/www/js/controllers/wot-controllers.js @@ -807,7 +807,8 @@ function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $ $scope.showSharePopover = function(event) { var title = $scope.formData.name || $scope.formData.uid || $scope.formData.pubkey; - var url = $state.href('app.wot_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.uid}, {absolute: true}); + // Use rootPath (fix #390) + var url = $rootScope.rootPath + $state.href('app.wot_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.uid}); UIUtils.popover.share(event, { bindings: { url: url, diff --git a/www/plugins/es/js/controllers/market-controllers.js b/www/plugins/es/js/controllers/market-controllers.js index b1b1650d7..e7fa60c79 100644 --- a/www/plugins/es/js/controllers/market-controllers.js +++ b/www/plugins/es/js/controllers/market-controllers.js @@ -552,7 +552,7 @@ function ESMarketRecordViewController($scope, $anchorScroll, $ionicPopover, $sta $scope.hideActionsPopover(); var title = $scope.formData.title; - var url = $state.href('app.market_view_record', {title: title, id: $scope.id}, {absolute: true}); + var url = $rootScope.rootPath + $state.href('app.market_view_record', {title: title, id: $scope.id}); UIUtils.popover.share(event, { bindings: { url: url, diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index e0cc8f5ab..32eed77a8 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -518,7 +518,7 @@ function ESRegistryRecordViewController($scope, $state, $q, $timeout, $ionicPopo $scope.showSharePopover = function(event) { $scope.hideActionsPopover(); var title = $scope.formData.title; - var url = $state.href('app.registry_view_record', {title: title, id: $scope.id}, {absolute: true}); + var url = $rootScope.rootPath + $state.href('app.registry_view_record', {title: title, id: $scope.id}); UIUtils.popover.share(event, { bindings: { url: url, -- GitLab