fixes and added angular moment

This commit is contained in:
Marian Oancea 2015-01-29 01:41:52 +02:00
parent 8427f59ca7
commit 5114d05c32
9 changed files with 46 additions and 21 deletions

View File

@ -1,4 +1,22 @@
var nodes = [
{
name: 'instance 1',
type: 'C++',
rpcHost: '54.173.252.182',
rpcPort: '8080'
},
{
name: 'instance 2',
type: 'C++',
rpcHost: '54.209.133.248',
rpcPort: '8080'
},
{
name: 'instance 3',
type: 'C++',
rpcHost: '54.174.67.126',
rpcPort: '8080'
},
{
name: 'local',
type: 'C++',

View File

@ -2,8 +2,6 @@ var geoip = require('geoip-lite');
require('es6-promise').polyfill();
var self;
var Node = function Node(options, id)
{
this.info = options;
@ -27,21 +25,19 @@ var Node = function Node(options, id)
Node.prototype.update = function()
{
if( ! this.web3.haveProvider()) {
var sock = new this.web3.providers.HttpSyncProvider('http://' + this.info.rpcHost + ':' + this.info.rpcPort);
this.web3.setProvider(sock);
}
var sock = new this.web3.providers.HttpSyncProvider('http://' + this.info.rpcHost + ':' + this.info.rpcPort);
this.web3.setProvider(sock);
var eth = this.web3.eth;
try {
this.info.stats.peers = parseInt(eth.peerCount);
this.info.stats.peers = eth.peerCount;
}
catch (err) {
this.info.stats.peers = 0;
this.info.stats.peers = null;
}
if(this.info.stats.peers > 0) {
if(this.info.stats.peers != null) {
this.info.stats.block.height = eth.number;
var block = eth.block(this.info.stats.block.height)
this.info.stats.block.hash = block.hash;

View File

@ -1,3 +1,3 @@
'use strict';
var app = angular.module('netStatsApp', ['underscore', 'netStatsApp.filters', 'netStatsApp.directives']);
var app = angular.module('netStatsApp', ['underscore', 'angularMoment', 'netStatsApp.directives']);

View File

@ -12,5 +12,6 @@ function StatsCtrl($scope, socket, _) {
$scope.nodesTotal = $scope.nodes.length;
$scope.nodesActive = _.filter($scope.nodes, function(node){ return node.stats.active == true; }).length;
$scope.bestBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.height); }).stats.block.height;
$scope.lastBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.timestamp); }).stats.block.timestamp;
});
}

View File

@ -2,9 +2,8 @@
/* Filters */
angular.module('netStatsApp.filters', []).
filter('interpolate', ['version', function(version) {
return function(text) {
return String(text).replace(/\%VERSION\%/mg, version);
}
}]);
// angular.module('netStatsApp').filter('fromNow', function() {
// return function(time) {
// return moment.unix(time).fromNow();
// }
// });

2
public/js/lib/angular-moment.min.js vendored Normal file
View File

@ -0,0 +1,2 @@
"format global";"deps angular";"deps moment";!function(){"use strict";function a(a,b){return a.module("angularMoment",[]).constant("angularMomentConfig",{preprocess:null,timezone:"",format:null,statefulFilters:!0}).constant("moment",b).constant("amTimeAgoConfig",{withoutSuffix:!1,serverTime:null,titleFormat:null}).directive("amTimeAgo",["$window","moment","amMoment","amTimeAgoConfig","angularMomentConfig",function(b,c,d,e,f){return function(g,h,i){function j(){var a;if(e.serverTime){var b=(new Date).getTime(),d=b-u+e.serverTime;a=c(d)}else a=c();return a}function k(){q&&(b.clearTimeout(q),q=null)}function l(a){if(h.text(a.from(j(),s)),t&&!h.attr("title")&&h.attr("title",a.local().format(t)),!x){var c=Math.abs(j().diff(a,"minute")),d=3600;1>c?d=1:60>c?d=30:180>c&&(d=300),q=b.setTimeout(function(){l(a)},1e3*d)}}function m(a){y&&h.attr("datetime",a)}function n(){if(k(),o){var a=d.preprocessDate(o,v,r);l(a),m(a.toISOString())}}var o,p,q=null,r=f.format,s=e.withoutSuffix,t=e.titleFormat,u=(new Date).getTime(),v=f.preprocess,w=i.amTimeAgo.replace(/^::/,""),x=0===i.amTimeAgo.indexOf("::"),y="TIME"===h[0].nodeName.toUpperCase();p=g.$watch(w,function(a){return"undefined"==typeof a||null===a||""===a?(k(),void(o&&(h.text(""),m(""),o=null))):(o=a,n(),void(void 0!==a&&x&&p()))}),a.isDefined(i.amWithoutSuffix)&&g.$watch(i.amWithoutSuffix,function(a){"boolean"==typeof a?(s=a,n()):s=e.withoutSuffix}),i.$observe("amFormat",function(a){"undefined"!=typeof a&&(r=a,n())}),i.$observe("amPreprocess",function(a){v=a,n()}),g.$on("$destroy",function(){k()}),g.$on("amMoment:localeChanged",function(){n()})}}]).service("amMoment",["moment","$rootScope","$log","angularMomentConfig",function(b,c,d,e){this.preprocessors={utc:b.utc,unix:b.unix},this.changeLocale=function(d,e){var f=b.locale(d,e);return a.isDefined(d)&&c.$broadcast("amMoment:localeChanged"),f},this.changeTimezone=function(a){e.timezone=a,c.$broadcast("amMoment:timezoneChanged")},this.preprocessDate=function(c,f,g){return a.isUndefined(f)&&(f=e.preprocess),this.preprocessors[f]?this.preprocessors[f](c,g):(f&&d.warn("angular-moment: Ignoring unsupported value for preprocess: "+f),!isNaN(parseFloat(c))&&isFinite(c)?b(parseInt(c,10)):b(c,g))},this.applyTimezone=function(a){var b=e.timezone;return a&&b&&(a.tz?a=a.tz(b):d.warn("angular-moment: timezone specified but moment.tz() is undefined. Did you forget to include moment-timezone.js?")),a}}]).filter("amCalendar",["moment","amMoment","angularMomentConfig",function(a,b,c){function d(c,d){if("undefined"==typeof c||null===c)return"";c=b.preprocessDate(c,d);var e=a(c);return e.isValid()?b.applyTimezone(e).calendar():""}return d.$stateful=c.statefulFilters,d}]).filter("amDateFormat",["moment","amMoment","angularMomentConfig",function(a,b,c){function d(c,d,e){if("undefined"==typeof c||null===c)return"";c=b.preprocessDate(c,e);var f=a(c);return f.isValid()?b.applyTimezone(f).format(d):""}return d.$stateful=c.statefulFilters,d}]).filter("amDurationFormat",["moment","angularMomentConfig",function(a,b){function c(b,c,d){return"undefined"==typeof b||null===b?"":a.duration(b,c).humanize(d)}return c.$stateful=b.statefulFilters,c}]).filter("amTimeAgo",["moment","amMoment","angularMomentConfig",function(a,b,c){function d(c,d,e){if("undefined"==typeof c||null===c)return"";c=b.preprocessDate(c,d);var f=a(c);return f.isValid()?b.applyTimezone(f).fromNow(e):""}return d.$stateful=c.statefulFilters,d}])}"function"==typeof define&&define.amd?define("angular-moment",["angular","moment"],a):"undefined"!=typeof module&&module&&module.exports?a(angular,require("moment")):a(angular,window.moment)}();
//# sourceMappingURL=angular-moment.min.js.map

7
public/js/lib/moment.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -31,8 +31,8 @@ block content
div.pull-left.icon-full-width
i.icon-time
div.pull-left
span.small-title block time
span.big-details 12 sec
span.small-title last block
span.big-details(am-time-ago="lastBlock", am-preprocess="unix")
div.clearfix
div.col-xs-6.stat-holder
div.row.big-info.uptime.text-info
@ -40,7 +40,7 @@ block content
i.icon-clock
div.pull-left
span.small-title up-time
span.big-details 100.00%
span.big-details 100%
div.clearfix
div.clearfix
@ -83,8 +83,8 @@ block content
td {{'#' + node.stats.block.height}}
td.hidden-sm.hidden-xs
span.small {{node.stats.block.hash}}
td 16 sec
td 98.3%
td(am-time-ago="node.stats.block.timestamp", am-preprocess="unix")
td 100%
//- tr.text-success
//- td poc-7.ethdev.com
//- td C++

View File

@ -18,6 +18,8 @@ html(ng-app="netStatsApp")
script(src="/js/lib/d3.v3.min.js")
script(src="/js/lib/topojson.v1.min.js")
script(src="/js/lib/datamaps.min.js")
script(src="/js/lib/moment.min.js")
script(src="/js/lib/angular-moment.min.js")
script(src="/js/app.js")
script(src="/js/services.js")
script(src="/js/controllers.js")