From 93d8d1b5480afe09afd73b3fa0f06ef7c7912012 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Thu, 8 Jun 2017 08:19:22 +0200
Subject: [PATCH] [enh] better dependencies management in modules

---
 config.xml                                 |  3 +-
 package.json                               | 44 ++++++++++++++++++++--
 www/js/app.js                              |  6 +--
 www/js/controllers/currency-controllers.js |  2 +-
 www/js/filters.js                          |  9 +++--
 www/js/platform.js                         |  8 ++--
 www/js/services/bma-services.js            |  2 +-
 www/js/services/utils-services.js          |  2 +-
 www/js/services/wallet-services.js         |  2 +-
 www/plugins/rml9/plugin-03-file_export.js  |  2 +-
 www/plugins/rml9/plugin-final.js           |  2 +-
 11 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/config.xml b/config.xml
index f6edef751..8a8418722 100644
--- a/config.xml
+++ b/config.xml
@@ -93,10 +93,10 @@
     <plugin name="cordova-plugin-device" spec="~1.1.2" />
     <plugin name="cordova-plugin-dialogs" spec="~1.2.1" />
     <plugin name="cordova-plugin-inappbrowser" spec="~1.6.1" />
+    <plugin name="cordova-plugin-minisodium" spec="~1.0.0" />
     <plugin name="cordova-plugin-secure-storage" spec="~2.6.3" />
     <plugin name="cordova-plugin-splashscreen" spec="~3.2.2" />
     <plugin name="cordova-plugin-statusbar" spec="~2.1.3" />
-    <plugin name="cordova-plugin-vibration" spec="~2.1.1" />
     <plugin name="cordova-plugin-websocket" spec="~0.12.0" />
     <plugin name="cordova-plugin-whitelist" spec="~1.2.2" />
     <plugin name="cordova-plugin-x-toast" spec="~2.6.0" />
@@ -104,5 +104,4 @@
     <plugin name="phonegap-plugin-barcodescanner" spec="git+https://github.com/phonegap/phonegap-plugin-barcodescanner.git">
         <variable name="CAMERA_USAGE_DESCRIPTION" value=" " />
     </plugin>
-    <plugin name="cordova-plugin-minisodium" spec="~1.0.0" />
 </widget>
diff --git a/package.json b/package.json
index e18273030..c1558667e 100644
--- a/package.json
+++ b/package.json
@@ -27,15 +27,30 @@
     "new": "https://github.com/duniter/cesium/issues/new?labels=bug"
   },
   "dependencies": {
+    "bower": "^1.8.0",
+    "cordova-plugin-camera": "~2.2.0",
+    "cordova-plugin-console": "~1.0.3",
+    "cordova-plugin-device": "~1.1.2",
+    "cordova-plugin-dialogs": "~1.2.1",
+    "cordova-plugin-inappbrowser": "~1.6.1",
+    "cordova-plugin-minisodium": "~1.0.0",
+    "cordova-plugin-secure-storage": "~2.6.3",
+    "cordova-plugin-splashscreen": "~3.2.2",
+    "cordova-plugin-statusbar": "~2.1.3",
+    "cordova-plugin-vibration": "~2.1.1",
+    "cordova-plugin-websocket": "~0.12.0",
+    "cordova-plugin-whitelist": "~1.2.2",
+    "cordova-plugin-x-toast": "~2.6.0",
     "delete-empty": "^0.1.3",
     "gulp": "^3.9.1",
-    "bower": "^1.7.3",
-    "ionic": "^1.7.16",
     "gulp-bump": "^2.1.0",
     "gulp-concat": "^2.2.0",
     "gulp-rename": "^1.2.0",
     "gulp-sass": "^2.2.0",
-    "node-sass": "^3.3.3"
+    "ionic": "^1.7.16",
+    "ionic-plugin-keyboard": "~2.2.1",
+    "node-sass": "^3.3.3",
+    "phonegap-plugin-barcodescanner": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner.git"
   },
   "devDependencies": {
     "cordova-uglify": "^0.2.3",
@@ -96,5 +111,26 @@
     "ios",
     "android",
     "firefoxos"
-  ]
+  ],
+  "cordova": {
+    "plugins": {
+      "cordova-plugin-camera": {},
+      "cordova-plugin-console": {},
+      "cordova-plugin-device": {},
+      "cordova-plugin-dialogs": {},
+      "cordova-plugin-inappbrowser": {},
+      "cordova-plugin-minisodium": {},
+      "cordova-plugin-secure-storage": {},
+      "cordova-plugin-splashscreen": {},
+      "cordova-plugin-statusbar": {},
+      "cordova-plugin-vibration": {},
+      "cordova-plugin-websocket": {},
+      "cordova-plugin-whitelist": {},
+      "cordova-plugin-x-toast": {},
+      "ionic-plugin-keyboard": {},
+      "phonegap-plugin-barcodescanner": {
+        "CAMERA_USAGE_DESCRIPTION": " "
+      }
+    }
+  }
 }
diff --git a/www/js/app.js b/www/js/app.js
index 15bcf40a7..f9b47fede 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -5,7 +5,7 @@
 // the 2nd parameter is an array of 'requires'
 // 'starter.controllers' is found in controllers.js
 angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht.translate',
-  'ngApi', 'angular-cache', 'angular.screenmatch', 'angular.bind.notifier', 'ImageCropper', 'ngFileSaver',
+  'ngApi', 'angular-cache', 'angular.screenmatch', 'angular.bind.notifier', 'ImageCropper',
   // removeIf(no-device)
   'ngCordova',
   // endRemoveIf(no-device)
@@ -85,11 +85,11 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
     IdleProvider.timeout(csConfig.logoutTimeout||15); // display warning during 15s
   })
 
-  .factory('$exceptionHandler', function($log) {
+  .factory('$exceptionHandler', function() {
     'ngInject';
 
     return function(exception, cause) {
-      $log.error(exception, cause);
+      console.error(exception, cause);
     };
   })
 
diff --git a/www/js/controllers/currency-controllers.js b/www/js/controllers/currency-controllers.js
index 1a23d5254..9a1b537e7 100644
--- a/www/js/controllers/currency-controllers.js
+++ b/www/js/controllers/currency-controllers.js
@@ -1,5 +1,5 @@
 
-angular.module('cesium.currency.controllers', ['cesium.services'])
+angular.module('cesium.currency.controllers', ['ngFileSaver', 'cesium.services'])
 
 .config(function($stateProvider) {
   'ngInject';
diff --git a/www/js/filters.js b/www/js/filters.js
index eddc66acf..202a0d749 100644
--- a/www/js/filters.js
+++ b/www/js/filters.js
@@ -1,8 +1,8 @@
 // Cesium filters
-angular.module('cesium.filters', ['cesium.config', 'cesium.settings.services', 'pascalprecht.translate', 'cesium.translations'
+angular.module('cesium.filters', ['cesium.config', 'cesium.platform', 'pascalprecht.translate', 'cesium.translations'
 ])
 
-  .service('filterTranslations', function($rootScope, csSettings, $translate) {
+  .service('filterTranslations', function($rootScope, csPlatform, csSettings, $translate) {
     'ngInject';
 
     var
@@ -34,7 +34,6 @@ angular.module('cesium.filters', ['cesium.config', 'cesium.settings.services', '
           }
         });
     }
-    csSettings.api.locale.on.changed($rootScope, onLocaleChange, this);
 
     that.ready = function() {
       if (started) return $q.when(data);
@@ -42,10 +41,12 @@ angular.module('cesium.filters', ['cesium.config', 'cesium.settings.services', '
     };
 
     that.start = function() {
-      startPromise = csSettings.ready()
+      startPromise = csPlatform.ready()
         .then(onLocaleChange)
         .then(function() {
           started = true;
+
+          csSettings.api.locale.on.changed($rootScope, onLocaleChange, this);
         });
       return startPromise;
     };
diff --git a/www/js/platform.js b/www/js/platform.js
index 9ea3fb1db..5c7b07425 100644
--- a/www/js/platform.js
+++ b/www/js/platform.js
@@ -110,19 +110,19 @@ angular.module('cesium.platform', ['cesium.config', 'cesium.services'])
           Device.ready(),
 
           // Start settings
-          csSettings.start()
+          csSettings.ready()
         ]))
 
         // Load BMA
         .then(function(){
-          return BMA.start().then(checkBmaNodeAlive);
+          return BMA.ready().then(checkBmaNodeAlive);
         })
 
         // Load currency
-        .then(csCurrency.start)
+        .then(csCurrency.ready)
 
         // Trying to restore wallet
-        .then(csWallet.start)
+        .then(csWallet.ready)
 
         .then(function(){
           enableChangeState();
diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js
index a413fef9d..032124c57 100644
--- a/www/js/services/bma-services.js
+++ b/www/js/services/bma-services.js
@@ -72,7 +72,7 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
       that.cache = _emptyCache();
 
       // Allow to force SSL connection with port different from 443
-      var forceUseSsl = (csConfig.httpsMode == true || csConfig.httpsMode === 'force') ||
+      var forceUseSsl = (csConfig.httpsMode === 'true' || csConfig.httpsMode === true || csConfig.httpsMode === 'force') ||
         ($window.location && $window.location.protocol === 'https:') ? true : false;
       if (forceUseSsl) {
         console.debug('[BMA] Enable SSL (forced by config or detected in URL)');
diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js
index d8a60d4c9..56509fbfd 100644
--- a/www/js/services/utils-services.js
+++ b/www/js/services/utils-services.js
@@ -1,4 +1,4 @@
-angular.module('cesium.utils.services', ['ngResource'])
+angular.module('cesium.utils.services', [])
 
 // Replace the '$ionicPlatform.ready()', to enable multiple calls
 // See http://stealthcode.co/multiple-calls-to-ionicplatform-ready/
diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js
index ff4a3f2c6..b9051f7a2 100644
--- a/www/js/services/wallet-services.js
+++ b/www/js/services/wallet-services.js
@@ -1,5 +1,5 @@
 
-angular.module('cesium.wallet.services', ['ngApi', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services',
+angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services',
   'cesium.settings.services'])
 
 
diff --git a/www/plugins/rml9/plugin-03-file_export.js b/www/plugins/rml9/plugin-03-file_export.js
index a701642a7..d8c52a6a7 100644
--- a/www/plugins/rml9/plugin-03-file_export.js
+++ b/www/plugins/rml9/plugin-03-file_export.js
@@ -1,5 +1,5 @@
 
-angular.module('cesium.rml9.plugin', ['cesium.services'])
+angular.module('cesium.rml9.plugin', ['ngFileSaver', 'cesium.services'])
 
   .config(function($stateProvider, PluginServiceProvider, csConfig) {
     'ngInject';
diff --git a/www/plugins/rml9/plugin-final.js b/www/plugins/rml9/plugin-final.js
index 1efc71ae0..dc79cc6b0 100644
--- a/www/plugins/rml9/plugin-final.js
+++ b/www/plugins/rml9/plugin-final.js
@@ -1,5 +1,5 @@
 
-angular.module('cesium.rml9.plugin', ['cesium.services'])
+angular.module('cesium.rml9.plugin', ['ngFileSaver', 'cesium.services'])
 
   .config(function($stateProvider, PluginServiceProvider, csConfig) {
     'ngInject';
-- 
GitLab