From 860b834eb7bbf76caabf117ebad2c0aaa69d3a3c Mon Sep 17 00:00:00 2001 From: ArnaudCerisier <arnaud.cerisier@gmail.com> Date: Mon, 29 May 2017 11:25:52 +0200 Subject: [PATCH] Before merge --- www/plugins/es/i18n/locale-fr-FR.json | 10 +-- .../js/controllers/blockchain-controllers.js | 85 ++++++------------- .../es/js/services/blockchain-services.js | 1 + .../es/templates/blockchain/lookup_form.html | 6 +- 4 files changed, 33 insertions(+), 69 deletions(-) diff --git a/www/plugins/es/i18n/locale-fr-FR.json b/www/plugins/es/i18n/locale-fr-FR.json index 13b009f83..3d2878f32 100644 --- a/www/plugins/es/i18n/locale-fr-FR.json +++ b/www/plugins/es/i18n/locale-fr-FR.json @@ -185,7 +185,11 @@ "HEADER_MEDIAN_TIME": "Date / Heure", "HEADER_BLOCK": "Bloc #", "HEADER_ISSUER": "Noeud émetteur", - "BTN_LAST": "Derniers blocs" + "BTN_LAST": "Derniers blocs", + "TX_SEARCH_FILTER": { + "PERIOD": "Transactions effectuées entre le {{params[1]|formatDate}} et le {{params[2]|formatDate}}", + "PUBKEY": "Clé publique : {{params[1]|formatPubkey}}" + } }, "ERROR": { "SEARCH_BLOCKS_FAILED": "Erreur de la recherche des blocs." @@ -294,10 +298,6 @@ "RECORD_REMOVED" : "Annonce supprimée" } }, - "TX_SEARCH": { - "PERIOD": "Transactions effectuées entre le {{date.startDate|formatDate}} et le {{date.endDate|formatDate}}", - "PUBKEY": "Clé publique : {{pubkey|formatPubkey}}" - }, "REGISTRY": { "CATEGORY": "Activité principale", "GENERAL_DIVIDER": "Informations générales", diff --git a/www/plugins/es/js/controllers/blockchain-controllers.js b/www/plugins/es/js/controllers/blockchain-controllers.js index 90356fb52..dbbb4fc32 100644 --- a/www/plugins/es/js/controllers/blockchain-controllers.js +++ b/www/plugins/es/js/controllers/blockchain-controllers.js @@ -53,6 +53,7 @@ function ESBlockLookupController($scope, $state, $controller, $ionicPopover, UIU } $scope.search.type = 'text'; + $scope.processSearchText($scope.search.text); $scope.doSearch(); $ionicHistory.nextViewOptions({ @@ -85,69 +86,39 @@ function ESBlockLookupController($scope, $state, $controller, $ionicPopover, UIU }; // Cancel search filter - $scope.itemRemove = function(itemType) { - if(itemType === $scope.dynamicSearchFilter[0][0]) - $scope.dynamicSearchFilter[0][3] = false; - else if(itemType === $scope.dynamicSearchFilter[1][0]) - $scope.dynamicSearchFilter[0][3] = false; - $scope.newQuery = $scope.query.replace(itemType, ''); + $scope.itemRemove = function(item) { + $scope.newQuery = $scope.query.replace(item.query, ''); $scope.newQuery = $scope.newQuery.replace(/^ AND /, ''); $scope.newQuery = $scope.newQuery.replace(/ AND $/, ''); + $scope.searchFilter.item = null; $scope.search.text = $scope.newQuery; $scope.doSearchText(); }; - $scope.filterConstructor = function() { + $scope.processSearchText = function(text) { - $scope.dynamicSearchFilter = new Array(2); - for (var i = 0; i < $scope.dynamicSearchFilter.length; i++) { - $scope.dynamicSearchFilter[i] = new Array(5) - } + //exports.block.parseSearchText = function(text) { + var filterRegexps = { + PERIOD: /_exists_:transactions AND medianTime:>=([0-9]+) AND medianTime:<([0-9]+)/, + PUBKEY: /issuer:([a-zA-Z0-9]+)/ + }; + + $scope.search.filters = _.keys(filterRegexps).reduce(function(res, filterType){ + var matches = filterRegexps[filterType].exec(text); + if (matches) { + console.log(filterType, matches); + var filter = { + type: filterType, + params: matches + }; + return res.concat(filter); + } + return res; + }, []); + //}; - /* - +-----------+--------+ - | period | pubkey | - +--------+-----------+--------+ - | regex | | | - +--------+-----------+--------+ - | query | | | - +--------+-----------+--------+ - | key | | | - +--------+-----------+--------+ - | params | startDate | pubkey | - +--------+-----------+--------+ - | | endDate | | - +--------+-----------+--------+ - */ - - //Period - $scope.dynamicSearchFilter[0][0] = /_exists_:transactions AND medianTime:>=([0-9]+) AND medianTime:<([0-9]+)/; - var matches = $scope.search.text.match($scope.dynamicSearchFilter[0][0]); - if (matches){ - $scope.dynamicSearchFilter[0][1] = matches[0]; - $scope.dynamicSearchFilter[0][2] = 'TX_SEARCH.PERIOD'; - $scope.dynamicSearchFilter[0][3] = true; - $scope.dynamicSearchFilter[0][4] = matches[1]; - $scope.dynamicSearchFilter[0][5] = matches[2]; - } - //Pubkey - $scope.dynamicSearchFilter[1][0] = /issuer:([a-zA-Z0-9]+)/; - var matches = $scope.search.text.match($scope.dynamicSearchFilter[1][0]); - if (matches){ - $scope.dynamicSearchFilter[1][1] = matches[0]; - $scope.dynamicSearchFilter[1][2] = 'TX_SEARCH.PUBKEY'; - $scope.dynamicSearchFilter[1][3] = true; - $scope.dynamicSearchFilter[1][4] = matches[1]; - } - $scope.params ={ - date : { - startDate : $scope.dynamicSearchFilter[0][4], - endDate : $scope.dynamicSearchFilter[0][5] - }, - pubkey: $scope.dynamicSearchFilter[1][4] - } }; // This method override the base class method @@ -175,11 +146,7 @@ function ESBlockLookupController($scope, $state, $controller, $ionicPopover, UIU } request.excludeCurrent = (from === 0); - $scope.filterConstructor(); - promise = esBlockchain.block.search($scope.currency, request); - $scope.query = $scope.search.text; - $scope.search.text = null; } // Full text search @@ -196,11 +163,7 @@ function ESBlockLookupController($scope, $state, $controller, $ionicPopover, UIU } request.excludeCurrent = true; - $scope.filterConstructor(); - promise = esBlockchain.block.searchText($scope.currency, $scope.search.text, request); - $scope.query = $scope.search.text; - $scope.search.text = null; } var time = new Date().getTime(); diff --git a/www/plugins/es/js/services/blockchain-services.js b/www/plugins/es/js/services/blockchain-services.js index 26ef53bbe..9bd185b96 100644 --- a/www/plugins/es/js/services/blockchain-services.js +++ b/www/plugins/es/js/services/blockchain-services.js @@ -119,6 +119,7 @@ angular.module('cesium.es.blockchain.services', ['cesium.services', 'cesium.es.h return exports; } + return EsBlockchain(); }) ; diff --git a/www/plugins/es/templates/blockchain/lookup_form.html b/www/plugins/es/templates/blockchain/lookup_form.html index 6671fff85..47358c0af 100644 --- a/www/plugins/es/templates/blockchain/lookup_form.html +++ b/www/plugins/es/templates/blockchain/lookup_form.html @@ -4,9 +4,9 @@ <div class="item no-padding"> <div class="gray double-padding-x padding-top item-text-wrap" - ng-repeat="items in dynamicSearchFilter" ng-if="items[3]"> - <span>{{items[2]|translate:params}}</span> - <a class="icon ion-close" ng-click="itemRemove(items[0])"></a> + ng-repeat="filter in search.filters" ng-if="filter"> + <span>{{'BLOCKCHAIN.LOOKUP.TX_SEARCH_FILTER.'+filter.type|translate:filter}}</span> + <a class="icon ion-close" ng-click="itemRemove(filter)"></a> </div> -- GitLab