From ed6f429c300de360dfd62386a9fc527ac51a2819 Mon Sep 17 00:00:00 2001 From: Mario Colque Date: Tue, 14 Jan 2014 14:46:26 -0300 Subject: [PATCH] added new service search --- app/views/includes/foot.jade | 1 + public/js/app.js | 3 ++- public/js/controllers/search.js | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 public/js/controllers/search.js diff --git a/app/views/includes/foot.jade b/app/views/includes/foot.jade index ab3e493..52b6e0f 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/js/app.js b/public/js/app.js index cfc1f8c..cea9363 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 0000000..878e713 --- /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; + }); + }); + }); + }; + +}]);