Merge pull request #51 from colkito/feature/homepage-default-data
Feature/homepage default data
This commit is contained in:
commit
ea141f7120
@ -3,10 +3,8 @@
|
|||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Block = mongoose.model('Block');
|
Block = mongoose.model('Block');
|
||||||
//, _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,10 +33,13 @@ exports.show = function(req, res) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of blocks by date
|
* List of blocks by date
|
||||||
*/
|
*/
|
||||||
exports.list = function(req, res) {
|
exports.list = function(req, res) {
|
||||||
|
var limit = req.query.limit || 0;
|
||||||
|
|
||||||
//helper to convert timestamps to yyyy-mm-dd format
|
//helper to convert timestamps to yyyy-mm-dd format
|
||||||
var formatTimestamp = function (date) {
|
var formatTimestamp = function (date) {
|
||||||
var yyyy = date.getUTCFullYear().toString();
|
var yyyy = date.getUTCFullYear().toString();
|
||||||
@ -69,11 +70,11 @@ exports.list = function(req, res) {
|
|||||||
'$lte': lte
|
'$lte': lte
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.limit(limit)
|
||||||
|
.sort('-time')
|
||||||
.exec(function(err, blocks) {
|
.exec(function(err, blocks) {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.render('error', {
|
res.status(500).send(err);
|
||||||
status: 500
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
res.jsonp({
|
res.jsonp({
|
||||||
blocks: blocks,
|
blocks: blocks,
|
||||||
@ -86,5 +87,3 @@ exports.list = function(req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var Transaction = require('../models/Transaction');
|
|
||||||
var Block = require('../models/Block');
|
|
||||||
var Address = require('../models/Address');
|
|
||||||
var async = require('async');
|
|
||||||
//, _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
var Transaction = require('../models/Transaction');
|
||||||
|
var Block = require('../models/Block');
|
||||||
|
var Address = require('../models/Address');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,6 +28,7 @@ exports.transaction = function(req, res, next, txid) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Show transaction
|
||||||
*/
|
*/
|
||||||
exports.show = function(req, res) {
|
exports.show = function(req, res) {
|
||||||
|
|
||||||
@ -41,6 +37,7 @@ exports.show = function(req, res) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var getTransaction = function(txid, cb) {
|
var getTransaction = function(txid, cb) {
|
||||||
Transaction.fromIdWithInfo(txid, function(err, tx) {
|
Transaction.fromIdWithInfo(txid, function(err, tx) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -51,9 +48,14 @@ var getTransaction = function(txid, cb) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.transactions = function(req, res, next) {
|
|
||||||
|
/**
|
||||||
|
* List of transaction
|
||||||
|
*/
|
||||||
|
exports.list = function(req, res, next) {
|
||||||
var bId = req.query.block;
|
var bId = req.query.block;
|
||||||
var aId = req.query.address;
|
var aId = req.query.address;
|
||||||
|
var limit = req.query.limit || 1000;
|
||||||
|
|
||||||
if (bId) {
|
if (bId) {
|
||||||
Block.fromHashWithInfo(bId, function(err, block) {
|
Block.fromHashWithInfo(bId, function(err, block) {
|
||||||
@ -69,7 +71,7 @@ exports.transactions = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else if (aId) {
|
||||||
var a = Address.new(aId);
|
var a = Address.new(aId);
|
||||||
|
|
||||||
a.update(function(err) {
|
a.update(function(err) {
|
||||||
@ -84,7 +86,18 @@ exports.transactions = function(req, res, next) {
|
|||||||
res.jsonp(results);
|
res.jsonp(results);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Transaction
|
||||||
|
.find()
|
||||||
|
.limit(limit)
|
||||||
|
.sort('-time')
|
||||||
|
.exec(function(err, txs) {
|
||||||
|
if (err) {
|
||||||
|
res.status(500).send(err);
|
||||||
|
} else {
|
||||||
|
res.jsonp(txs);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -18,8 +18,7 @@ module.exports = function(app) {
|
|||||||
var transactions = require('../app/controllers/transactions');
|
var transactions = require('../app/controllers/transactions');
|
||||||
app.get('/api/tx/:txid', transactions.show);
|
app.get('/api/tx/:txid', transactions.show);
|
||||||
app.param('txid', transactions.transaction);
|
app.param('txid', transactions.transaction);
|
||||||
|
app.get('/api/txs', transactions.list);
|
||||||
app.get('/api/txs', transactions.transactions);
|
|
||||||
|
|
||||||
// Address routes
|
// Address routes
|
||||||
var addresses = require('../app/controllers/addresses');
|
var addresses = require('../app/controllers/addresses');
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
var TRANSACTION_DISPLAYED = 5;
|
var TRANSACTION_DISPLAYED = 5;
|
||||||
var BLOCKS_DISPLAYED = 5;
|
var BLOCKS_DISPLAYED = 5;
|
||||||
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', function($scope, Global, socket) {
|
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', 'Blocks', 'Transactions', function($scope, Global, socket, Blocks, Transactions) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
socket.on('tx', function(data) {
|
|
||||||
var tx = data;
|
socket.on('tx', function(tx) {
|
||||||
console.log('Transaction received! ' + JSON.stringify(tx));
|
console.log('Transaction received! ' + JSON.stringify(tx));
|
||||||
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
|
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
|
||||||
$scope.txs.pop();
|
$scope.txs.pop();
|
||||||
@ -13,8 +13,7 @@ angular.module('mystery.system').controller('IndexController', ['$scope', 'Globa
|
|||||||
$scope.txs.unshift(tx);
|
$scope.txs.unshift(tx);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('block', function(data) {
|
socket.on('block', function(block) {
|
||||||
var block = data;
|
|
||||||
console.log('Block received! ' + JSON.stringify(block));
|
console.log('Block received! ' + JSON.stringify(block));
|
||||||
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
|
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
|
||||||
$scope.blocks.pop();
|
$scope.blocks.pop();
|
||||||
@ -22,8 +21,21 @@ angular.module('mystery.system').controller('IndexController', ['$scope', 'Globa
|
|||||||
$scope.blocks.unshift(block);
|
$scope.blocks.unshift(block);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.index = function() {
|
||||||
|
Blocks.get({
|
||||||
|
limit: BLOCKS_DISPLAYED
|
||||||
|
}, function(res) {
|
||||||
|
$scope.blocks = res.blocks;
|
||||||
|
});
|
||||||
|
|
||||||
|
Transactions.query({
|
||||||
|
limit: TRANSACTION_DISPLAYED
|
||||||
|
}, function(txs) {
|
||||||
|
$scope.txs = txs;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.txs = [];
|
$scope.txs = [];
|
||||||
$scope.blocks = [];
|
$scope.blocks = [];
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ angular.module('mystery.search').controller('SearchController', ['$scope', '$rou
|
|||||||
|
|
||||||
$scope.search = function() {
|
$scope.search = function() {
|
||||||
var q = $scope.q;
|
var q = $scope.q;
|
||||||
var path;
|
|
||||||
|
|
||||||
$scope.badQuery = false;
|
$scope.badQuery = false;
|
||||||
$scope.q = '';
|
$scope.q = '';
|
||||||
|
|||||||
@ -32,3 +32,6 @@ angular.module('mystery.transactions').factory('TransactionsByAddress', ['$resou
|
|||||||
});
|
});
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
angular.module('mystery.transactions').factory('Transactions', ['$resource', function($resource) {
|
||||||
|
return $resource('/api/txs');
|
||||||
|
}]);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<section data-ng-controller="IndexController" data-ng-init="">
|
<section data-ng-controller="IndexController" data-ng-init="index()">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user