From ef109e32516a573fce405993ea5ff4525c96f04e Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Tue, 21 Jan 2014 10:55:35 -0300 Subject: [PATCH] search by height of block --- public/js/controllers/search.js | 48 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/public/js/controllers/search.js b/public/js/controllers/search.js index 1dd2c58a..07af17be 100644 --- a/public/js/controllers/search.js +++ b/public/js/controllers/search.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.search').controller('SearchController', - function ($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address) { + function ($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) { $scope.global = Global; $scope.search = function() { @@ -10,28 +10,34 @@ angular.module('insight.search').controller('SearchController', $scope.badQuery = false; $scope.q = ''; - Block.get({ - blockHash: q - }, function() { - $location.path('block/' + q); - }, function () { //block not found, search on TX - Transaction.get({ - txId: q + BlockByHeight.get({ + blockHeight: q + }, function(hash) { + $location.path('/block/' + hash.blockHash); + }, function() { // block by height not found + Block.get({ + blockHash: q }, function() { - $location.path('tx/' + q); - }, function () { //tx not found, search on Address - Address.get({ - addrStr: q + $location.path('block/' + q); + }, function () { //block not found, search on TX + Transaction.get({ + txId: q }, function() { - $location.path('address/' + q); - }, function () { //address not found, fail :( - $scope.badQuery = true; - $timeout(function() { - $scope.badQuery = false; - }, 2000); - $scope.q = q; - }); - }); + $location.path('tx/' + q); + }, function () { //tx not found, search on Address + Address.get({ + addrStr: q + }, function() { + $location.path('address/' + q); + }, function () { //address not found, fail :( + $scope.badQuery = true; + $timeout(function() { + $scope.badQuery = false; + }, 2000); + $scope.q = q; + }); + }); + }); }); };