Merge pull request #269 from colkito/bug/search-loading

Bug/search loading
This commit is contained in:
Gustavo Maximiliano Cortez 2014-02-12 14:16:38 -02:00
commit cae872e575
4 changed files with 23 additions and 8 deletions

BIN
public/img/loading.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -138,6 +138,13 @@ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
font-family: 'Ubuntu', sans-serif; font-family: 'Ubuntu', sans-serif;
} }
#search.loading {
background-image: url('/img/loading.gif');
background-position: 5px center;
background-repeat: no-repeat;
padding-left: 25px;
}
#search::-webkit-input-placeholder { #search::-webkit-input-placeholder {
color: #BCDF7E; color: #BCDF7E;
font-family: 'Ubuntu', sans-serif; font-family: 'Ubuntu', sans-serif;

View File

@ -3,6 +3,7 @@
angular.module('insight.search').controller('SearchController', angular.module('insight.search').controller('SearchController',
function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) { function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
$scope.global = Global; $scope.global = Global;
$scope.loading = false;
var _badQuery = function() { var _badQuery = function() {
$scope.badQuery = true; $scope.badQuery = true;
@ -12,39 +13,46 @@ angular.module('insight.search').controller('SearchController',
}, 2000); }, 2000);
}; };
var _resetSearch = function() {
$scope.q = '';
$scope.loading = false;
};
$scope.search = function() { $scope.search = function() {
var q = $scope.q; var q = $scope.q;
$scope.badQuery = false; $scope.badQuery = false;
$scope.loading = true;
Block.get({ Block.get({
blockHash: q blockHash: q
}, function() { }, function() {
$scope.q = ''; _resetSearch();
$location.path('block/' + q); $location.path('block/' + q);
}, function () { //block not found, search on TX }, function() { //block not found, search on TX
Transaction.get({ Transaction.get({
txId: q txId: q
}, function() { }, function() {
$scope.q = ''; _resetSearch();
$location.path('tx/' + q); $location.path('tx/' + q);
}, function () { //tx not found, search on Address }, function() { //tx not found, search on Address
Address.get({ Address.get({
addrStr: q addrStr: q
}, function() { }, function() {
$scope.q = ''; _resetSearch();
$location.path('address/' + q); $location.path('address/' + q);
}, function () { // block by height not found }, function() { // block by height not found
if (isFinite(q)) { // ensure that q is a finite number. A logical height value. if (isFinite(q)) { // ensure that q is a finite number. A logical height value.
BlockByHeight.get({ BlockByHeight.get({
blockHeight: q blockHeight: q
}, function(hash) { }, function(hash) {
$scope.q = ''; _resetSearch();
$location.path('/block/' + hash.blockHash); $location.path('/block/' + hash.blockHash);
}, function() { //not found, fail :( }, function() { //not found, fail :(
_badQuery(); _badQuery();
}); });
} }
else { else {
$scope.loading = false;
_badQuery(); _badQuery();
} }
}); });

View File

@ -17,7 +17,7 @@
</ul> </ul>
<form data-ng-controller="SearchController" class="navbar-form navbar-left" role="search" data-ng-submit="search()"> <form data-ng-controller="SearchController" class="navbar-form navbar-left" role="search" data-ng-submit="search()">
<div class="form-group" data-ng-class="{'has-error': badQuery}"> <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"> <input id="search" type="text" class="form-control" data-ng-model="q" data-ng-class="{'loading': loading}" placeholder="Search for block, transaction or address">
</div> </div>
<div class="no_matching text-danger" data-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>