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'; 'use strict';
angular.module('insight.search').controller('SearchController', 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.global = Global;
$scope.search = function() { $scope.search = function() {
@ -10,6 +10,11 @@ angular.module('insight.search').controller('SearchController',
$scope.badQuery = false; $scope.badQuery = false;
$scope.q = ''; $scope.q = '';
BlockByHeight.get({
blockHeight: q
}, function(hash) {
$location.path('/block/' + hash.blockHash);
}, function() { // block by height not found
Block.get({ Block.get({
blockHash: q blockHash: q
}, function() { }, function() {
@ -26,10 +31,14 @@ angular.module('insight.search').controller('SearchController',
$location.path('address/' + q); $location.path('address/' + q);
}, function () { //address not found, fail :( }, function () { //address not found, fail :(
$scope.badQuery = true; $scope.badQuery = true;
$timeout(function() {
$scope.badQuery = false;
}, 2000);
$scope.q = q; $scope.q = q;
}); });
}); });
}); });
});
}; };
}); });

View File

@ -11,17 +11,18 @@
</div> </div>
<div class="collapse navbar-collapse"> <div class="collapse navbar-collapse">
<ul class="nav navbar-nav"> <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> <a href="#!/{{item.link}}">{{item.title}}</a>
</li> </li>
</ul> </ul>
<div ng-controller="SearchController"> <div data-ng-controller="SearchController">
<form class="navbar-form navbar-left" role="search" ng-submit="search()"> <form class="navbar-form navbar-left" role="search" data-ng-submit="search()">
<div class="form-group" ng-class="{'has-error': badQuery}"> <div class="form-group" data-ng-class="{'has-error': badQuery}">
<input id="search" type="text" class="form-control" ng-model="q" placeholder="Search for block, transaction or address"> <input id="search" type="text" class="form-control" data-ng-model="q" placeholder="Search for block, transaction or address">
</div> </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> </form>
</div>
<div class="status" data-ng-controller="FooterController" data-ng-init="getFooter()"> <div class="status" data-ng-controller="FooterController" data-ng-init="getFooter()">
<i class="small" data-ng-show="info.blocks"> <i class="small" data-ng-show="info.blocks">
<strong>Status:</strong> On Sync <strong>Status:</strong> On Sync
@ -36,4 +37,3 @@
</div> </div>
</div> </div>
</div> </div>
</div>