From 3532f7314198781a2b3fe904f4507a18cb33554f Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Sat, 11 Feb 2017 17:11:21 +0100
Subject: [PATCH] - Blockchain search : Add missing buttons (small device) -
 Block list: avoid duplicate add, when new block appears

---
 www/js/controllers/blockchain-controllers.js  | 30 ++++++++++--------
 www/js/controllers/settings-controllers.js    |  2 +-
 www/js/controllers/wallet-controllers.js      |  4 +--
 .../js/controllers/blockchain-controllers.js  | 31 ++++++++++++++++++-
 .../es/js/controllers/message-controllers.js  |  2 +-
 .../es/templates/blockchain/items_blocks.html | 18 ++++++++---
 .../es/templates/blockchain/lookup.html       | 17 ++++++++++
 .../blockchain/lookup_popover_actions.html    | 13 ++++----
 8 files changed, 88 insertions(+), 29 deletions(-)

diff --git a/www/js/controllers/blockchain-controllers.js b/www/js/controllers/blockchain-controllers.js
index 95a09c85e..9974631e2 100644
--- a/www/js/controllers/blockchain-controllers.js
+++ b/www/js/controllers/blockchain-controllers.js
@@ -332,7 +332,7 @@ function BlockLookupController($scope, $timeout, $focus, $filter, $state, $ancho
         UIUtils.ink({
           selector: '#block-'+block.number
         });
-      }, 100);
+      });
     };
 
     $scope.wsBlock.on(function(json) {
@@ -347,12 +347,14 @@ function BlockLookupController($scope, $timeout, $focus, $filter, $state, $ancho
       $scope.search.results = $scope.search.results || [];
 
       if (!$scope.search.results.length) {
-        // Prepare the new block, then add it to result
+        console.debug('[ES] [blockchain] new block #{0} received (by websocket)'.format(block.number));
+        // add it to result
+        $scope.search.total++;
+        $scope.search.results.push(block);
+
+        // Prepare the new block, then show it
         $scope.doPrepareResult([block])
           .then(function() {
-            console.debug('[ES] [blockchain] new block #{0} received (by websocket)'.format(block.number));
-            $scope.search.total++;
-            $scope.search.results.push(block);
             return showBlock(block);
           });
       }
@@ -364,22 +366,24 @@ function BlockLookupController($scope, $timeout, $focus, $filter, $state, $ancho
         if (existingBlock) {
           if (existingBlock.hash != block.hash) {
             console.debug('[ES] [blockchain] block #{0} updated (by websocket)'.format(block.number));
-            // Prepare the new block, and refresh the previous latest block (could be compacted)
-            $scope.doPrepareResult([block, $scope.search.results[0]])
+            // Replace existing content
+            angular.copy(block, existingBlock);
+            // Prepare the new block, then show it
+            $scope.doPrepareResult([block, $scope.search.results[1]])
               .then(function() {
-                angular.copy(block, existingBlock);
                 return showBlock(existingBlock);
               });
           }
         }
         else {
           console.debug('[ES] [blockchain] new block #{0} received (by websocket)'.format(block.number));
-          // Prepare the new block, and refresh the previous latest block (could be compacted)
-          $scope.doPrepareResult([block, $scope.search.results[0]])
+          // Insert at index 0
+          $scope.search.total++;
+          $scope.search.results.splice(0, 0, block);
+
+          // Prepare the new block, then show it
+          $scope.doPrepareResult([block, $scope.search.results[1]])
             .then(function() {
-              // Insert at index 0
-              $scope.search.total++;
-              $scope.search.results.splice(0, 0, block);
               return showBlock(block);
             });
         }
diff --git a/www/js/controllers/settings-controllers.js b/www/js/controllers/settings-controllers.js
index 38178382d..ae54eec88 100644
--- a/www/js/controllers/settings-controllers.js
+++ b/www/js/controllers/settings-controllers.js
@@ -201,7 +201,7 @@ function SettingsController($scope, $q, $ionicPopup, $timeout, $translate, csHtt
 
   $scope.showActionsPopover = function(event) {
     if (!$scope.actionsPopover) {
-      $ionicPopover.fromTemplateUrl('templates/settings/popover_actions.html', {
+      $ionicPopover.fromTemplateUrl('templates/settings/lookup_popover_actions.html', {
         scope: $scope
       }).then(function(popover) {
         $scope.actionsPopover = popover;
diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js
index 70f9427d9..b6716baff 100644
--- a/www/js/controllers/wallet-controllers.js
+++ b/www/js/controllers/wallet-controllers.js
@@ -60,7 +60,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
       });
   });
 
-  $ionicPopover.fromTemplateUrl('templates/wallet/popover_actions.html', {
+  $ionicPopover.fromTemplateUrl('templates/wallet/lookup_popover_actions.html', {
     scope: $scope
   }).then(function(popover) {
     $scope.actionsPopover = popover;
@@ -532,7 +532,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
 
   $scope.showActionsPopover = function(event) {
     if (!$scope.actionsPopover) {
-      $ionicPopover.fromTemplateUrl('templates/wallet/popover_actions.html', {
+      $ionicPopover.fromTemplateUrl('templates/wallet/lookup_popover_actions.html', {
         scope: $scope
       }).then(function(popover) {
         $scope.actionsPopover = popover;
diff --git a/www/plugins/es/js/controllers/blockchain-controllers.js b/www/plugins/es/js/controllers/blockchain-controllers.js
index f7f3fd9dc..dc8ff9357 100644
--- a/www/plugins/es/js/controllers/blockchain-controllers.js
+++ b/www/plugins/es/js/controllers/blockchain-controllers.js
@@ -51,7 +51,7 @@ angular.module('cesium.es.blockchain.controllers', ['cesium.es.services'])
 ;
 
 
-function ESBlockLookupController($scope, $state, $controller, UIUtils, esBlockchain, $ionicHistory) {
+function ESBlockLookupController($scope, $state, $controller, $ionicPopover, UIUtils, esBlockchain, $ionicHistory) {
   'ngInject';
 
   // Initialize the super class and extend it.
@@ -85,7 +85,10 @@ function ESBlockLookupController($scope, $state, $controller, UIUtils, esBlockch
   };
 
   $scope.doSearchLast = function() {
+    $scope.hideActionsPopover();
+
     $scope.search.type = 'last';
+    $scope.search.sort = undefined;
     $scope.doSearch();
 
     $ionicHistory.nextViewOptions({
@@ -177,6 +180,32 @@ function ESBlockLookupController($scope, $state, $controller, UIUtils, esBlockch
   $scope.showHelpTip = function() {
 
   };
+
+  /* -- popups -- */
+
+  $scope.showActionsPopover = function(event) {
+    if (!$scope.actionsPopover) {
+      $ionicPopover.fromTemplateUrl('plugins/es/templates/blockchain/lookup_popover_actions.html', {
+        scope: $scope
+      }).then(function(popover) {
+        $scope.actionsPopover = popover;
+        //Cleanup the popover when we're done with it!
+        $scope.$on('$destroy', function() {
+          $scope.actionsPopover.remove();
+        });
+        $scope.actionsPopover.show(event);
+      });
+    }
+    else {
+      $scope.actionsPopover.show(event);
+    }
+  };
+
+  $scope.hideActionsPopover = function() {
+    if ($scope.actionsPopover) {
+      $scope.actionsPopover.hide();
+    }
+  };
 }
 
 function ESNetworkViewExtendController($scope, PluginService, csSettings) {
diff --git a/www/plugins/es/js/controllers/message-controllers.js b/www/plugins/es/js/controllers/message-controllers.js
index b83b7f0c7..4e512248e 100644
--- a/www/plugins/es/js/controllers/message-controllers.js
+++ b/www/plugins/es/js/controllers/message-controllers.js
@@ -209,7 +209,7 @@ function ESMessageListController($scope, $rootScope, $state, $timeout, $translat
 
   $scope.showActionsPopover = function(event) {
     if (!$scope.actionsPopover) {
-      $ionicPopover.fromTemplateUrl('plugins/es/templates/message/popover_actions.html', {
+      $ionicPopover.fromTemplateUrl('plugins/es/templates/message/lookup_popover_actions.html', {
         scope: $scope
       }).then(function(popover) {
         $scope.actionsPopover = popover;
diff --git a/www/plugins/es/templates/blockchain/items_blocks.html b/www/plugins/es/templates/blockchain/items_blocks.html
index 9456a19ff..8cfa50f7e 100644
--- a/www/plugins/es/templates/blockchain/items_blocks.html
+++ b/www/plugins/es/templates/blockchain/items_blocks.html
@@ -30,11 +30,19 @@
   </a>
 </div>
 
-<div class="padding gray" ng-if="!search.loading && !search.results.length" translate>
+<div class="padding gray" ng-if=":rebind:!search.loading && !search.results.length" translate>
   COMMON.SEARCH_NO_RESULT
 </div>
 
-<!-- blocks -->
-<ng-repeat ng-repeat="block in search.results"
-           ng-include="!block.empty ? 'templates/blockchain/item_block_lg.html' : 'templates/blockchain/item_block_empty_lg.html'">
-</ng-repeat>
+<!-- blocks (large view) -->
+<ng-if ng-if=":rebind:!smallscreen">
+  <ng-repeat ng-repeat="block in :rebind:search.results track by block.number"
+             ng-include="!block.empty ? 'templates/blockchain/item_block_lg.html' : 'templates/blockchain/item_block_empty_lg.html'">
+  </ng-repeat>
+</ng-if>
+<!-- blocks (small screens) -->
+<ng-if ng-if=":rebind:smallscreen">
+  <ng-repeat ng-repeat="block in :rebind:search.results track by block.number"
+             ng-include="'templates/blockchain/item_block.html'">
+  </ng-repeat>
+</ng-if>
diff --git a/www/plugins/es/templates/blockchain/lookup.html b/www/plugins/es/templates/blockchain/lookup.html
index 287044b64..e9df93b22 100644
--- a/www/plugins/es/templates/blockchain/lookup.html
+++ b/www/plugins/es/templates/blockchain/lookup.html
@@ -3,6 +3,23 @@
     <span translate>BLOCKCHAIN.LOOKUP.TITLE</span>
   </ion-nav-title>
 
+  <ion-nav-buttons side="secondary">
+
+    <button class="button button-icon button-clear icon ion-navicon visible-xs visible-sm"
+            ng-click="toggleCompactMode()">
+      <b class="icon-secondary"
+         ng-class="{'ion-arrow-down-b': !compactMode, 'ion-arrow-up-b': compactMode}"
+         style="top: -12px; left: 11px; font-size: 10px;"></b>
+      <b class="icon-secondary"
+         ng-class="{'ion-arrow-up-b': !compactMode,'ion-arrow-down-b': compactMode}"
+         style="top: 12px; left: 11px; font-size: 10px;"></b>
+    </button>
+
+    <button class="button button-icon button-clear icon ion-android-more-vertical visible-xs visible-sm" ng-click="showActionsPopover($event)">
+    </button>
+
+  </ion-nav-buttons>
+
   <ion-content class="padding no-padding-xs" scroll="true">
     <ng-include src="'plugins/es/templates/blockchain/lookup_form.html'"></ng-include>
   </ion-content>
diff --git a/www/plugins/es/templates/blockchain/lookup_popover_actions.html b/www/plugins/es/templates/blockchain/lookup_popover_actions.html
index f2a4ae562..82872b754 100644
--- a/www/plugins/es/templates/blockchain/lookup_popover_actions.html
+++ b/www/plugins/es/templates/blockchain/lookup_popover_actions.html
@@ -5,14 +5,15 @@
   <ion-content scroll="false">
     <div class="list item-text-wrap">
 
-      <a class="item item-icon-left item-icon-right ink"
-         ng-click="toggleSearchType('XXX')">
-        <i class="icon ion-android-people"></i>
-        {{'BLOCKCHAIN.LOOKUP.XXX' | translate}}
-        <i class="icon ion-ios-checkmark-empty" ng-show="search.type=='XXX'"></i>
+      <!-- last blocks -->
+      <a ng-if="enableFilter"
+         class="item item-icon-left item-icon-right ink"
+         ng-click="doSearchLast()">
+        <i class="icon ion-clock"></i>
+        {{'BLOCKCHAIN.LOOKUP.BTN_LAST' | translate}}
+        <i class="icon ion-ios-checkmark-empty" ng-show="search.type=='last'"></i>
       </a>
 
-
     </div>
   </ion-content>
 </ion-popover-view>
-- 
GitLab