From 8e755eaae271af620d0d4e74249c0ace78ee8be0 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Tue, 27 Sep 2016 17:53:24 +0200
Subject: [PATCH]  - Disable cache on network peers BMA  - Fix tabs padding on
 smal screens

---
 www/js/services/bma-services.js            | 30 +++++++++++++++-------
 www/js/services/network-services.js        | 13 +++++++---
 www/templates/currency/view_currency.html  | 20 ++++++++-------
 www/templates/wot/view_certifications.html | 30 ++++++++++++----------
 4 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js
index 5ee895ceb..38c667271 100644
--- a/www/js/services/bma-services.js
+++ b/www/js/services/bma-services.js
@@ -5,7 +5,7 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
 .factory('BMA', function($q, csSettings, csHttp, $rootScope) {
   'ngInject';
 
-  function factory(host, port) {
+  function factory(host, port, cacheEnable) {
 
     var
     errorCodes = {
@@ -48,7 +48,9 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
       return host2 == host && ((!port && !port2) ||(port == port2));
     }
 
-    var getMembers = csHttp.getWithCache(host, port, '/wot/members');
+    var getMembers = cacheEnable ?
+      csHttp.getWithCache(host, port, '/wot/members') :
+      csHttp.get(host, port, '/wot/members');
 
     function getMemberUidsByPubkey() {
       return getMembers()
@@ -71,8 +73,12 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
         });
     }
 
-    var getBlockchainWithUd = csHttp.getWithCache(host, port, '/blockchain/with/ud', csHttp.cache.SHORT);
-    var getBlockchainBlock = csHttp.getWithCache(host, port, '/blockchain/block/:block', csHttp.cache.SHORT);
+    var getBlockchainWithUd = cacheEnable ?
+      csHttp.getWithCache(host, port, '/blockchain/with/ud', csHttp.cache.SHORT) :
+      csHttp.get(host, port, '/blockchain/with/ud');
+    var getBlockchainBlock = cacheEnable ?
+      csHttp.getWithCache(host, port, '/blockchain/block/:block', csHttp.cache.SHORT) :
+      csHttp.get(host, port, '/blockchain/block/:block');
 
     function getBlockchainLastUd() {
       return getBlockchainWithUd()
@@ -220,7 +226,9 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
         peers: csHttp.get(host, port, '/network/peers')
       },
       blockchain: {
-        parameters: csHttp.getWithCache(host, port, '/blockchain/parameters', csHttp.cache.LONG),
+        parameters: cacheEnable ?
+          csHttp.getWithCache(host, port, '/blockchain/parameters', csHttp.cache.LONG) :
+          csHttp.get(host, port, '/blockchain/parameters'),
         current: csHttp.get(host, port, '/blockchain/current'),
         block: getBlockchainBlock,
         membership: csHttp.post(host, port, '/blockchain/membership'),
@@ -236,9 +244,13 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
         process: csHttp.post(host, port, '/tx/process'),
         history: {
           all: csHttp.get(host, port, '/tx/history/:pubkey'),
-          times: csHttp.getWithCache(host, port, '/tx/history/:pubkey/times/:from/:to'),
+          times: cacheEnable ?
+            csHttp.getWithCache(host, port, '/tx/history/:pubkey/times/:from/:to') :
+            csHttp.get(host, port, '/tx/history/:pubkey/times/:from/:to'),
           timesNoCache: csHttp.get(host, port, '/tx/history/:pubkey/times/:from/:to'),
-          blocks: csHttp.getWithCache(host, port, '/tx/history/:pubkey/blocks/:from/:to'),
+          blocks: cacheEnable ?
+            csHttp.getWithCache(host, port, '/tx/history/:pubkey/blocks/:from/:to') :
+            csHttp.get(host, port, '/tx/history/:pubkey/blocks/:from/:to'),
           pending: csHttp.get(host, port, '/tx/history/:pubkey/pending')
         }
       },
@@ -269,7 +281,7 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
     };
   }
 
-  var service = factory(csSettings.data.node.host, csSettings.data.node.port);
+  var service = factory(csSettings.data.node.host, csSettings.data.node.port, true /*cache*/);
   service.instance = factory;
 
   // Listen settings changes
@@ -277,7 +289,7 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce
 
     var nodeServer = csHttp.getServer(settings.node.host, settings.node.port);
     if (nodeServer != service.node.server) {
-      var newService = factory(settings.node.host, settings.node.port);
+      var newService = factory(settings.node.host, settings.node.port, true /*cache*/);
       service.copy(newService); // reload service
     }
 
diff --git a/www/js/services/network-services.js b/www/js/services/network-services.js
index bc67f6e68..c768c06f7 100644
--- a/www/js/services/network-services.js
+++ b/www/js/services/network-services.js
@@ -99,7 +99,7 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
             peer.server = server;
             peer.blockNumber = peer.block.replace(/-.+$/, '');
             data.newPeers.push(peer);
-            var node = BMA.instance(peer.getHost(), peer.getPort());
+            var node = BMA.instance(peer.getHost(), peer.getPort(), false);
             return node.blockchain.current()
               .then(function(block){
                 peer.current = block;
@@ -130,18 +130,25 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
           var resolved = false;
 
           interval = $interval(function() {
+            console.debug('[network] check if finish...');
             if (data.newPeers.length) {
               data.peers = data.peers.concat(data.newPeers.splice(0));
+              console.debug('[network] New peers found: sort and ad them to result...');
               sortPeers();
               if (!waitAllPeers) {
-                resolved = true;
-                resolve(data.peers);
+                console.debug('[network] Returning to main process (peers will continue to be updating in background)');
+                if (!resolved) {
+                  resolved = true;
+                  resolve(data.peers);
+                }
               }
             } else if (data.updatingPeers && !data.searchingPeersOnNetwork) {
+              console.debug('[network] Finish : all peers found. Stopping new peers check.');
               // The peer lookup end, we can make a clean final report
               sortPeers();
               data.updatingPeers = false;
               if (!resolved) {
+                console.debug('[network] refresh peer finished');
                 resolve(data.peers);
               }
               $interval.cancel(interval);
diff --git a/www/templates/currency/view_currency.html b/www/templates/currency/view_currency.html
index 5288c7d71..c27347d78 100644
--- a/www/templates/currency/view_currency.html
+++ b/www/templates/currency/view_currency.html
@@ -12,20 +12,22 @@
     </ion-nav-buttons>
 
     <ion-content scroll="false">
-        <ion-tabs class="tabs-icon-top tabs-positive has-header">
+        <ion-tabs class="tabs-icon-top tabs-positive">
 
             <ion-tab title="{{'CURRENCY.VIEW.TAB_CURRENCY'|translate}}" icon="ion-stats-bars">
-                <ion-nav-view name="currency-tab"/>
-                <ion-content>
-                        <ng-include src="'templates/currency/tabs/view_parameters.html'"/>
-                 </ion-content>
+                <ion-nav-view name="currency-tab">
+                  <ion-content>
+                    <ng-include src="'templates/currency/tabs/view_parameters.html'"/>
+                  </ion-content>
+                </ion-nav-view>
             </ion-tab>
 
             <ion-tab title="{{'CURRENCY.VIEW.TAB_NETWORK'|translate}}" icon="ion-network" >
-                <ion-nav-view name="network-tab"/>
-                <ion-content class="padding no-padding-xs">
-                    <ng-include src="'templates/currency/tabs/view_network.html'"/>
-                </ion-content>
+                <ion-nav-view name="network-tab">
+                  <ion-content>
+                      <ng-include src="'templates/currency/tabs/view_network.html'"/>
+                  </ion-content>
+                </ion-nav-view>
             </ion-tab>
 
             </ion-tab>
diff --git a/www/templates/wot/view_certifications.html b/www/templates/wot/view_certifications.html
index 7dea18bf1..7a1b228a7 100644
--- a/www/templates/wot/view_certifications.html
+++ b/www/templates/wot/view_certifications.html
@@ -16,25 +16,27 @@
       <ion-tab title="{{'WOT.CERTIFICATIONS.SUMMARY'|translate}}" icon="ion-ribbon-b"
                on-select="setShowCertifications(true)"
                on-deselect="setShowCertifications(false)">
-        <ion-nav-view name="currency-tab"/>
-        <ion-content>
-          <div class="center padding" ng-if="loading">
-            <ion-spinner icon="android"></ion-spinner>
-          </div>
-          <ng-include src="'templates/wot/tabs/view_certifications.html'"/>
-        </ion-content>
+        <ion-nav-view name="currency-tab">
+          <ion-content>
+            <div class="center padding" ng-if="loading">
+              <ion-spinner icon="android"></ion-spinner>
+            </div>
+            <ng-include src="'templates/wot/tabs/view_certifications.html'"/>
+          </ion-content>
+        </ion-nav-view>
       </ion-tab>
 
       <ion-tab title="{{'WOT.GIVEN_CERTIFICATIONS.SUMMARY'|translate}}" icon="ion-ribbon-a"
                on-select="setShowGivenCertifications(true)"
                on-deselect="setShowGivenCertifications(false)">
-        <ion-nav-view name="network-tab"/>
-        <ion-content class="padding no-padding-xs">
-          <div class="center padding" ng-if="loading">
-            <ion-spinner icon="android"></ion-spinner>
-          </div>
-          <ng-include src="'templates/wot/tabs/view_given_certifications.html'"/>
-        </ion-content>
+        <ion-nav-view name="network-tab">
+          <ion-content>
+            <div class="center padding" ng-if="loading">
+              <ion-spinner icon="android"></ion-spinner>
+            </div>
+            <ng-include src="'templates/wot/tabs/view_given_certifications.html'"/>
+          </ion-content>
+        </ion-nav-view>
       </ion-tab>
 
       </ion-tab>
-- 
GitLab