bitcore-node-zcash/public/js/controllers/search.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

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:55:35 -08:00
function ($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
2014-01-14 09:46:26 -08:00
$scope.global = Global;
$scope.search = function() {
var q = $scope.q;
$scope.badQuery = false;
$scope.q = '';
2014-01-21 05:55:35 -08:00
BlockByHeight.get({
blockHeight: q
}, function(hash) {
$location.path('/block/' + hash.blockHash);
}, function() { // block by height not found
Block.get({
blockHash: q
2014-01-14 09:46:26 -08:00
}, function() {
2014-01-21 05:55:35 -08:00
$location.path('block/' + q);
}, function () { //block not found, search on TX
Transaction.get({
txId: q
2014-01-14 09:46:26 -08:00
}, function() {
2014-01-21 05:55:35 -08:00
$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;
});
});
});
2014-01-14 09:46:26 -08:00
});
};
2014-01-20 13:09:18 -08:00
});