Merge pull request #153 from colkito/bug/search-by-height

fixed search when put a txid
This commit is contained in:
Gustavo Maximiliano Cortez 2014-01-24 11:46:51 -08:00
commit b2d0ef6c60
1 changed files with 34 additions and 26 deletions

View File

@ -4,17 +4,18 @@ angular.module('insight.search').controller('SearchController',
function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) { function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
$scope.global = Global; $scope.global = Global;
var _badQuery = function() {
$scope.badQuery = true;
$timeout(function() {
$scope.badQuery = false;
}, 2000);
};
$scope.search = function() { $scope.search = function() {
var q = $scope.q; var q = $scope.q;
$scope.badQuery = false; $scope.badQuery = false;
BlockByHeight.get({
blockHeight: q
}, function(hash) {
$scope.q = '';
$location.path('/block/' + hash.blockHash);
}, function() { // block by height not found
Block.get({ Block.get({
blockHash: q blockHash: q
}, function() { }, function() {
@ -32,13 +33,20 @@ angular.module('insight.search').controller('SearchController',
}, function() { }, function() {
$scope.q = ''; $scope.q = '';
$location.path('address/' + q); $location.path('address/' + q);
}, function () { //address not found, fail :( }, function () { // block by height not found
$scope.badQuery = true; if (isFinite(q)) { // ensure that q is a finite number. A logical height value.
$timeout(function() { BlockByHeight.get({
$scope.badQuery = false; blockHeight: q
}, 2000); }, function(hash) {
$scope.q = q; $scope.q = '';
$location.path('/block/' + hash.blockHash);
}, function() { //not found, fail :(
_badQuery();
}); });
}
else {
_badQuery();
}
}); });
}); });
}); });