Merge pull request #125 from cmgustavo/bug/02homepage-initial-values
Bug/02homepage initial values
This commit is contained in:
commit
42ee817a55
@ -3,9 +3,10 @@
|
|||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Block = mongoose.model('Block'),
|
Block = mongoose.model('Block'),
|
||||||
common = require('./common');
|
common = require('./common'),
|
||||||
|
async = require('async');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,6 +48,16 @@ exports.blockindex = function(req, res, next, height) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getBlock = function(blockhash, cb) {
|
||||||
|
Block.fromHashWithInfo(blockhash, function(err, block) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
return cb(err, block.info);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of blocks by date
|
* List of blocks by date
|
||||||
*/
|
*/
|
||||||
@ -89,13 +100,20 @@ exports.list = function(req, res) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
res.status(500).send(err);
|
res.status(500).send(err);
|
||||||
} else {
|
} else {
|
||||||
res.jsonp({
|
var blockshash = [];
|
||||||
blocks: blocks,
|
for(var i=0;i<blocks.length;i++) {
|
||||||
pagination: {
|
blockshash.push(blocks[i].hash);
|
||||||
next: next,
|
}
|
||||||
prev: prev,
|
async.mapSeries(blockshash, getBlock, function(err, allblocks) {
|
||||||
current: dateStr
|
res.jsonp({
|
||||||
}
|
blocks: allblocks,
|
||||||
|
length: allblocks.length,
|
||||||
|
pagination: {
|
||||||
|
next: next,
|
||||||
|
prev: prev,
|
||||||
|
current: dateStr
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -51,6 +51,7 @@ var getTransaction = function(txid, cb) {
|
|||||||
* List of transaction
|
* List of transaction
|
||||||
*/
|
*/
|
||||||
exports.list = function(req, res, next) {
|
exports.list = function(req, res, next) {
|
||||||
|
var limit = req.query.limit || 5;
|
||||||
var bId = req.query.block;
|
var bId = req.query.block;
|
||||||
var addrStr = req.query.address;
|
var addrStr = req.query.address;
|
||||||
var page = req.query.pageNum;
|
var page = req.query.pageNum;
|
||||||
@ -117,5 +118,28 @@ exports.list = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Transaction
|
||||||
|
.find()
|
||||||
|
.limit(limit)
|
||||||
|
.sort('-time')
|
||||||
|
.exec(function(err, txs) {
|
||||||
|
if (err) {
|
||||||
|
res.status(500).send(err);
|
||||||
|
} else {
|
||||||
|
var txids = [];
|
||||||
|
for(var i=0;i<txs.length;i++) {
|
||||||
|
txids.push(txs[i].txid);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.mapSeries(txids, getTransaction, function(err, alltxs) {
|
||||||
|
res.jsonp({
|
||||||
|
txs: alltxs,
|
||||||
|
length: alltxs.length
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('insight.system').controller('HeaderController',
|
angular.module('insight.system').controller('HeaderController',
|
||||||
function ($scope, Global) {
|
function ($scope, get_socket, Global, Block) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
$scope.menu = [
|
$scope.menu = [
|
||||||
@ -15,5 +15,23 @@ angular.module('insight.system').controller('HeaderController',
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var socket = get_socket($scope);
|
||||||
|
socket.emit('subscribe', 'inv');
|
||||||
|
|
||||||
|
var getBlock = function(hash) {
|
||||||
|
Block.get({
|
||||||
|
blockHash: hash
|
||||||
|
}, function(res) {
|
||||||
|
$scope.totalBlocks = res.height;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.on('block', function(block) {
|
||||||
|
var blockHash = block.hash.toString();
|
||||||
|
console.log('Update Height');
|
||||||
|
getBlock(blockHash);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$scope.isCollapsed = false;
|
$scope.isCollapsed = false;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,9 +3,25 @@
|
|||||||
var TRANSACTION_DISPLAYED = 5;
|
var TRANSACTION_DISPLAYED = 5;
|
||||||
var BLOCKS_DISPLAYED = 5;
|
var BLOCKS_DISPLAYED = 5;
|
||||||
angular.module('insight.system').controller('IndexController',
|
angular.module('insight.system').controller('IndexController',
|
||||||
function($scope, $rootScope, Global, get_socket, Blocks, Transactions) {
|
function($scope, $rootScope, Global, get_socket, Blocks, Block, Transactions, Transaction) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
|
var getTransaction = function(txid) {
|
||||||
|
Transaction.get({
|
||||||
|
txId: txid
|
||||||
|
}, function(res) {
|
||||||
|
$scope.txs.unshift(res);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var getBlock = function(hash) {
|
||||||
|
Block.get({
|
||||||
|
blockHash: hash
|
||||||
|
}, function(res) {
|
||||||
|
$scope.blocks.unshift(res);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var socket = get_socket($scope);
|
var socket = get_socket($scope);
|
||||||
socket.emit('subscribe', 'inv');
|
socket.emit('subscribe', 'inv');
|
||||||
|
|
||||||
@ -13,19 +29,21 @@ angular.module('insight.system').controller('IndexController',
|
|||||||
$scope.flashMessage = $rootScope.flashMessage || null;
|
$scope.flashMessage = $rootScope.flashMessage || null;
|
||||||
|
|
||||||
socket.on('tx', function(tx) {
|
socket.on('tx', function(tx) {
|
||||||
|
var txStr = tx.txid.toString();
|
||||||
console.log('Transaction received! ' + JSON.stringify(tx));
|
console.log('Transaction received! ' + JSON.stringify(tx));
|
||||||
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
|
if (parseInt($scope.txs.length) > parseInt(TRANSACTION_DISPLAYED) - 1) {
|
||||||
$scope.txs.pop();
|
$scope.txs.pop();
|
||||||
}
|
}
|
||||||
$scope.txs.unshift(tx);
|
getTransaction(txStr);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('block', function(block) {
|
socket.on('block', function(block) {
|
||||||
|
var blockHash = block.hash.toString();
|
||||||
console.log('Block received! ' + JSON.stringify(block));
|
console.log('Block received! ' + JSON.stringify(block));
|
||||||
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
|
if (parseInt($scope.blocks.length) > parseInt(BLOCKS_DISPLAYED) - 1) {
|
||||||
$scope.blocks.pop();
|
$scope.blocks.pop();
|
||||||
}
|
}
|
||||||
$scope.blocks.unshift(block);
|
getBlock(blockHash);
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.human_since = function(time) {
|
$scope.human_since = function(time) {
|
||||||
@ -38,12 +56,13 @@ angular.module('insight.system').controller('IndexController',
|
|||||||
limit: BLOCKS_DISPLAYED
|
limit: BLOCKS_DISPLAYED
|
||||||
}, function(res) {
|
}, function(res) {
|
||||||
$scope.blocks = res.blocks;
|
$scope.blocks = res.blocks;
|
||||||
|
$scope.blocksLength = res.lenght;
|
||||||
});
|
});
|
||||||
|
|
||||||
Transactions.query({
|
Transactions.get({
|
||||||
limit: TRANSACTION_DISPLAYED
|
limit: TRANSACTION_DISPLAYED
|
||||||
}, function(txs) {
|
}, function(res) {
|
||||||
$scope.txs = txs;
|
$scope.txs = res.txs;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11,33 +11,47 @@
|
|||||||
<p class="lead text-center m20v">{{pagination.current}}</p>
|
<p class="lead text-center m20v">{{pagination.current}}</p>
|
||||||
|
|
||||||
<div class="m50v">
|
<div class="m50v">
|
||||||
<a class="btn btn-default" href="#!/blocks-date/{{pagination.prev}}"><small>← {{pagination.prev}}</small></a>
|
<a class="btn btn-primary" href="#!/blocks-date/{{pagination.prev}}"><small>← {{pagination.prev}}</small></a>
|
||||||
<a class="btn btn-primary" href="#!/blocks-date/{{pagination.next}}"><small>{{pagination.next}} →</small></a>
|
<a class="btn btn-primary" href="#!/blocks-date/{{pagination.next}}"><small>{{pagination.next}} →</small></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-8">
|
<div class="col-md-9">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>
|
<h1>
|
||||||
Blocks
|
Blocks
|
||||||
<small>by date</small>
|
<small>by date</small>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<table class="table" data-ng-show="blocks || blocks.length">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Hash</th>
|
<th>Height</th>
|
||||||
<th>Solved at</th>
|
<th>Timestamp</th>
|
||||||
|
<th>Transactions</th>
|
||||||
|
<th>Size</th>
|
||||||
|
<th>Confirmations</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr data-ng-repeat="block in blocks">
|
<tr data-ng-show="!blocks.length"><td colspan="5">Waiting for blocks...</td></tr>
|
||||||
<td><a href="#!/block/{{block.hash}}">{{block.hash}}</a></td>
|
<tr class="fader" data-ng-repeat='b in blocks'>
|
||||||
<td>{{block.time * 1000 | date:'medium'}}</td>
|
<td>
|
||||||
|
<a href="/#!/block/{{b.hash}}">{{b.height}}</a>
|
||||||
|
</td>
|
||||||
|
<td>{{b.time * 1000 | date:'medium'}}</td>
|
||||||
|
<td>{{b.tx.length}}</td>
|
||||||
|
<td>{{b.size}}</td>
|
||||||
|
<td>{{b.confirmations}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<ul class="pager" data-ng-show="blocks.length">
|
||||||
|
<li class="previous"><a href="#!/blocks-date/{{pagination.prev}}">← {{pagination.prev}}</a></li>
|
||||||
|
<li class="disabled"><a href="#">{{pagination.current}}</a></li>
|
||||||
|
<li class="next"><a href="#!/blocks-date/{{pagination.next}}">{{pagination.next}} →</a></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h2 class="text-center text-muted" data-ng-hide="!blocks || blocks.length">No blocks yet.</h2>
|
<h2 class="text-center text-muted" data-ng-hide="!blocks || blocks.length">No blocks yet.</h2>
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
<strong> Conn: </strong> {{info.connections}}
|
<strong> Conn: </strong> {{info.connections}}
|
||||||
</i>
|
</i>
|
||||||
<i class="small">
|
<i class="small">
|
||||||
<strong>Height:</strong> {{info.blocks}}
|
<strong>Height:</strong> {{totalBlocks || info.blocks}}
|
||||||
</i>
|
</i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -4,21 +4,57 @@
|
|||||||
<section data-ng-controller="IndexController" data-ng-init="index()">
|
<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-7">
|
||||||
<h3> New transactions </h3>
|
<h2>Blocks</h2>
|
||||||
<div class="panel fader" ng-repeat='tx in txs'>
|
<table class="table table-hover">
|
||||||
<a class="abreviate" href="#!/tx/{{tx.txid}}">{{tx.txid}}
|
<thead>
|
||||||
<span class="badge badge-success">{{human_since(tx.time)}}</span>
|
<tr>
|
||||||
</a>
|
<th>Height</th>
|
||||||
</div>
|
<th>Age</th>
|
||||||
|
<th>Transactions</th>
|
||||||
|
<th>Size</th>
|
||||||
|
<th>Confirmations</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr data-ng-show="!blocks.length"><td colspan="5">Waiting for blocks...</td></tr>
|
||||||
|
<tr class="fader" data-ng-repeat='b in blocks'>
|
||||||
|
<td>
|
||||||
|
<a href="/#!/block/{{b.hash}}">{{b.height}}</a>
|
||||||
|
</td>
|
||||||
|
<td>{{human_since(b.time)}}</td>
|
||||||
|
<td>{{b.tx.length}}</td>
|
||||||
|
<td>{{b.size}}</td>
|
||||||
|
<td>{{b.confirmations}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
|
||||||
<h3> New blocks </h3>
|
<div class="col-md-5">
|
||||||
<div class="panel fader" ng-repeat='b in blocks'>
|
<h2>Transactions</h2>
|
||||||
<a href="#!/block/{{b.hash}}">{{b.hash}}
|
|
||||||
<span class="badge badge-success">{{human_since(b.time)}}</span>
|
<table class="table table-hover" style="table-layout: fixed">
|
||||||
</a>
|
<thead>
|
||||||
</div>
|
<tr>
|
||||||
|
<th>Hash</th>
|
||||||
|
<th>Age</th>
|
||||||
|
<th>Value Out</th>
|
||||||
|
<th>Size</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr data-ng-show="!txs.length"><td colspan="5">Waiting for transactions...</td></tr>
|
||||||
|
<tr class="fader" data-ng-repeat='tx in txs'>
|
||||||
|
<td>
|
||||||
|
<a class="ellipsis" href="/#!/tx/{{tx.txid}}">{{tx.txid}}</a>
|
||||||
|
</td>
|
||||||
|
<td><span class="ellipsis">{{human_since(tx.time)}}</span></td>
|
||||||
|
<td>{{tx.valueOut}}</td>
|
||||||
|
<td>{{tx.size}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user