search by height of block

This commit is contained in:
Gustavo Cortez 2014-01-21 10:55:35 -03:00
parent 56dc130b4f
commit ef109e3251
1 changed files with 27 additions and 21 deletions

View File

@ -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;
});
});
});
});
};