Merge pull request #101 from cmgustavo/feature/01search-by-height

Feature/01search by height
This commit is contained in:
Mario Colque 2014-01-21 05:58:12 -08:00
commit e7292ba0c0
2 changed files with 34 additions and 25 deletions

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('insight.search').controller('SearchController',
function ($scope, $routeParams, $location, Global, Block, Transaction, Address) {
function ($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
$scope.global = Global;
$scope.search = function() {
@ -10,25 +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;
$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;
});
});
});
});
};

View File

@ -11,17 +11,18 @@
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li data-ng-repeat="item in menu" ui-route="/{{item.link}}" ng-class="{active: $uiRoute}">
<li data-ng-repeat="item in menu" ui-route="/{{item.link}}" data-ng-class="{active: $uiRoute}">
<a href="#!/{{item.link}}">{{item.title}}</a>
</li>
</ul>
<div ng-controller="SearchController">
<form class="navbar-form navbar-left" role="search" ng-submit="search()">
<div class="form-group" ng-class="{'has-error': badQuery}">
<input id="search" type="text" class="form-control" ng-model="q" placeholder="Search for block, transaction or address">
<div data-ng-controller="SearchController">
<form class="navbar-form navbar-left" role="search" data-ng-submit="search()">
<div class="form-group" data-ng-class="{'has-error': badQuery}">
<input id="search" type="text" class="form-control" data-ng-model="q" placeholder="Search for block, transaction or address">
</div>
<div class="no_matching text-danger" ng-show="badQuery">No matching records found!</div>
<div class="no_matching text-danger" data-ng-show="badQuery">No matching records found!</div>
</form>
</div>
<div class="status" data-ng-controller="FooterController" data-ng-init="getFooter()">
<i class="small" data-ng-show="info.blocks">
<strong>Status:</strong> On Sync
@ -33,7 +34,6 @@
<strong>Height:</strong> {{info.blocks}}
</i>
</div>
</div>
</div>
</div>
</div>