2014-01-14 09:46:26 -08:00
|
|
|
'use strict';
|
|
|
|
|
2014-01-20 13:09:18 -08:00
|
|
|
angular.module('insight.search').controller('SearchController',
|
2014-01-21 05:46:19 -08:00
|
|
|
function ($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address) {
|
2014-01-14 09:46:26 -08:00
|
|
|
$scope.global = Global;
|
|
|
|
|
|
|
|
$scope.search = function() {
|
|
|
|
var q = $scope.q;
|
|
|
|
|
|
|
|
$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
|
|
|
|
}, function() {
|
|
|
|
$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;
|
2014-01-21 05:46:19 -08:00
|
|
|
$timeout(function() {
|
|
|
|
$scope.badQuery = false;
|
|
|
|
}, 2000);
|
2014-01-14 09:46:26 -08:00
|
|
|
$scope.q = q;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-20 13:09:18 -08:00
|
|
|
});
|