diff --git a/app/views/includes/foot.jade b/app/views/includes/foot.jade index ab3e4936..52b6e0f1 100755 --- a/app/views/includes/foot.jade +++ b/app/views/includes/foot.jade @@ -37,4 +37,5 @@ script(type='text/javascript', src='/js/controllers/header.js') script(type='text/javascript', src='/js/controllers/blocks.js') script(type='text/javascript', src='/js/controllers/transactions.js') script(type='text/javascript', src='/js/controllers/address.js') +script(type='text/javascript', src='/js/controllers/search.js') script(type='text/javascript', src='/js/init.js') diff --git a/public/css/common.css b/public/css/common.css index 396601a7..73068675 100644 --- a/public/css/common.css +++ b/public/css/common.css @@ -48,3 +48,4 @@ body { font-size: 10px; } +#search { width: 400px; } diff --git a/public/js/app.js b/public/js/app.js index cfc1f8cf..cea93635 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,9 +1,10 @@ 'use strict'; -angular.module('mystery', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mystery.system', 'mystery.index', 'mystery.blocks', 'mystery.transactions', 'monospaced.qrcode', 'mystery.address']); +angular.module('mystery', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mystery.system', 'mystery.index', 'mystery.blocks', 'mystery.transactions', 'monospaced.qrcode', 'mystery.address', 'mystery.search']); angular.module('mystery.system', []); angular.module('mystery.index', []); angular.module('mystery.blocks', []); angular.module('mystery.transactions', []); angular.module('mystery.address', []); +angular.module('mystery.search', []); diff --git a/public/js/controllers/search.js b/public/js/controllers/search.js new file mode 100644 index 00000000..878e713a --- /dev/null +++ b/public/js/controllers/search.js @@ -0,0 +1,35 @@ +'use strict'; + +angular.module('mystery.search').controller('SearchController', ['$scope', '$routeParams', '$location', 'Global', 'Block', 'Transaction', 'Address', function ($scope, $routeParams, $location, Global, Block, Transaction, Address) { + $scope.global = Global; + + $scope.search = function() { + var q = $scope.q; + var path; + + $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; + $scope.q = q; + }); + }); + }); + }; + +}]); diff --git a/public/js/services/address.js b/public/js/services/address.js index 820f5370..1151fb78 100644 --- a/public/js/services/address.js +++ b/public/js/services/address.js @@ -3,6 +3,20 @@ angular.module('mystery.address').factory('Address', ['$resource', function($resource) { return $resource('/api/addr/:addrStr', { addrStr: '@addStr' + }, { + get: { + method: 'GET', + interceptor: { + response: function (res) { + return res.data; + }, + responseError: function (res) { + if (res.status === 404) { + return res; + } + } + } + } }); }]); diff --git a/public/js/services/blocks.js b/public/js/services/blocks.js index 7747ff32..6bdd578e 100644 --- a/public/js/services/blocks.js +++ b/public/js/services/blocks.js @@ -3,6 +3,20 @@ angular.module('mystery.blocks').factory('Block', ['$resource', function($resource) { return $resource('/api/block/:blockHash', { blockHash: '@blockHash' + }, { + get: { + method: 'GET', + interceptor: { + response: function (res) { + return res.data; + }, + responseError: function (res) { + if (res.status === 404) { + return res; + } + } + } + } }); }]); diff --git a/public/js/services/transactions.js b/public/js/services/transactions.js index 9edfacaf..bc7ee29d 100644 --- a/public/js/services/transactions.js +++ b/public/js/services/transactions.js @@ -3,6 +3,20 @@ angular.module('mystery.transactions').factory('Transaction', ['$resource', function($resource) { return $resource('/api/tx/:txId', { txId: '@txId' + }, { + get: { + method: 'GET', + interceptor: { + response: function (res) { + return res.data; + }, + responseError: function (res) { + if (res.status === 404) { + return res; + } + } + } + } }); }]); diff --git a/public/views/header.html b/public/views/header.html index fb034edb..5e4f49b7 100755 --- a/public/views/header.html +++ b/public/views/header.html @@ -14,5 +14,13 @@ {{item.title}} +
+ +