From 23ca040edaeb672a24ccbf517a17a6cae5d77422 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Mon, 21 Aug 2017 17:26:51 +0200
Subject: [PATCH] [fix] Share button now use a base URL defined in config
 (optional) - fix #530 and #496

---
 app/config.json                                       | 3 +++
 doc/configuration.md                                  | 2 ++
 www/js/config.js                                      | 3 ++-
 www/js/controllers/wallet-controllers.js              | 6 +++---
 www/js/controllers/wot-controllers.js                 | 6 +++---
 www/plugins/es/js/controllers/registry-controllers.js | 5 +++--
 6 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/app/config.json b/app/config.json
index e1da45a7c..51ea57242 100644
--- a/app/config.json
+++ b/app/config.json
@@ -13,6 +13,7 @@
     "expertMode": false,
     "decimalCount": 2,
     "httpsMode": false,
+    "shareBaseUrl": "https://g1.duniter.fr",
     "helptip": {
       "enable": true,
       "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md"
@@ -69,6 +70,7 @@
     "expertMode": false,
     "decimalCount": 2,
     "httpsMode": false,
+    "shareBaseUrl": "https://g1.duniter.fr",
     "helptip": {
       "enable": true,
       "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md"
@@ -118,6 +120,7 @@
     "useRelative": false,
     "expertMode": true,
     "decimalCount": 2,
+    "shareBaseUrl": "https://g1.duniter.fr",
     "helptip": {
       "enable": false,
       "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md"
diff --git a/doc/configuration.md b/doc/configuration.md
index cc88b445f..5dac7e812 100644
--- a/doc/configuration.md
+++ b/doc/configuration.md
@@ -22,6 +22,7 @@ angular.module("cesium.config", [])
   "expertMode": false,
   "decimalCount": 2,
   "httpsMode": false,
+  "shareBaseUrl": "https://g1.duniter.fr",
   "helptip": {
     "enable": true,
     "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md"
@@ -108,6 +109,7 @@ cacheTimeMs                 | Default network request cache time, in millisecond
 fallbackLanguage            | Default locale, if browser default language not exists in Cesium                               | `en`
 defaultLanguage             | Used to force the default language (ignore browser's language), on user first connection.      | =`fallbackLanguage`
 decimalCount                | Number of decimal to display, on float value (when using relative unit)                        | `4`
+shareBaseUrl                | Used in share buttons, to reference another web site.                                          | not defined (will use navigator's window location) 
 helptip.installDocUrl       | Used in features tour, for the link 'How-to install my own node'.                              | URL of [Duniter installation node](https://github.com/duniter/duniter/blob/master/doc/install-a-node.md)
 newIssueUrl                 | Used for link in the About screen, to submit new issue                                         | URL of [Cesium issues on GitHub](https://github.com/duniter/cesium/issues/new?labels=bug)
 timeout                     | Default network request timeout, in millisecond.                                               | `4000`
diff --git a/www/js/config.js b/www/js/config.js
index 047574a60..8efa94f92 100644
--- a/www/js/config.js
+++ b/www/js/config.js
@@ -22,6 +22,7 @@ angular.module("cesium.config", [])
 	"expertMode": false,
 	"decimalCount": 2,
 	"httpsMode": false,
+  "shareBaseUrl": "https://g1.duniter.fr",
 	"helptip": {
 		"enable": true,
 		"installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md"
@@ -70,4 +71,4 @@ angular.module("cesium.config", [])
 	"newIssueUrl": "https://github.com/duniter/cesium/issues/new?labels=bug"
 })
 
-;
\ No newline at end of file
+;
diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js
index 2058dd921..95a270c5f 100644
--- a/www/js/controllers/wallet-controllers.js
+++ b/www/js/controllers/wallet-controllers.js
@@ -59,7 +59,7 @@ angular.module('cesium.wallet.controllers', ['cesium.services', 'cesium.currency
 ;
 
 function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
-                          UIUtils, csWallet, $translate, $ionicPopover, Modals, csSettings) {
+                          UIUtils, csConfig, csWallet, $translate, $ionicPopover, Modals, csSettings) {
   'ngInject';
 
   $scope.loading = true;
@@ -514,8 +514,8 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
     $scope.hideActionsPopover();
 
     var title = $scope.formData.name || $scope.formData.uid || $scope.formData.pubkey;
-    // Use rootPath (fix #390)
-    var url = $rootScope.rootPath + $state.href('app.wot_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.name || $scope.formData.uid});
+    // Use shareBasePath (fix #530) or rootPath (fix #390)
+    var url = (csConfig.shareBaseUrl || $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 835e27d37..70a09f523 100644
--- a/www/js/controllers/wot-controllers.js
+++ b/www/js/controllers/wot-controllers.js
@@ -571,7 +571,7 @@ function WotLookupModalController($scope, $controller, $focus, parameters){
  * @param csWallet
  * @constructor
  */
-function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $ionicHistory, UIUtils, Modals, csCurrency, csWot, csWallet) {
+function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $ionicHistory, UIUtils, Modals, csConfig, csCurrency, csWot, csWallet) {
   'ngInject';
 
   $scope.formData = {
@@ -862,8 +862,8 @@ function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $
 
   $scope.showSharePopover = function(event) {
     var title = $scope.formData.name || $scope.formData.uid || $scope.formData.pubkey;
-    // Use rootPath (fix #390)
-    var url = $rootScope.rootPath + $state.href('app.wot_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.uid});
+    // Use shareBasePath (fix #530) or rootPath (fix #390)
+    var url = (csConfig.shareBaseUrl || $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/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js
index 16bda9654..a33ceef00 100644
--- a/www/plugins/es/js/controllers/registry-controllers.js
+++ b/www/plugins/es/js/controllers/registry-controllers.js
@@ -372,7 +372,7 @@ function ESRegistryLookupController($scope, $state, $focus, $timeout, esRegistry
 }
 
 function ESRegistryRecordViewController($scope, $state, $q, $timeout, $ionicPopover, $ionicHistory, $translate,
-                                        $anchorScroll,
+                                        $anchorScroll, csConfig,
                                         csWallet, esRegistry, UIUtils, esHttp) {
   'ngInject';
 
@@ -523,7 +523,8 @@ function ESRegistryRecordViewController($scope, $state, $q, $timeout, $ionicPopo
   $scope.showSharePopover = function(event) {
     $scope.hideActionsPopover();
     var title = $scope.formData.title;
-    var url = $rootScope.rootPath + $state.href('app.registry_view_record', {title: title, id: $scope.id});
+    // Use shareBasePath (fix #530) or rootPath (fix #390)
+    var url = (csConfig.shareBaseUrl || $rootScope.rootPath) + $state.href('app.registry_view_record', {title: title, id: $scope.id});
     UIUtils.popover.share(event, {
       bindings: {
         url: url,
-- 
GitLab