Permalink
Browse files

add host info bar

  • Loading branch information...
1 parent f203b9c commit 7805a33264f04ea608feed8a602f41829ce1ea2b @Eyjafjallajokull committed Jan 22, 2013
View
@@ -10,7 +10,6 @@ http:
widgets:
- {id: ProcessorWidget }
- {id: MemoryWidget }
- - {id: UptimeWidget }
- id: NetworkWidget
config:
interface: eth0
@@ -34,5 +33,6 @@ widgets:
title: Aboco git history
command: git log -n 3 --shortstat
classes: doubleWidth doubleHeight
+ - {id: HostInfoWidget }
View
@@ -28,6 +28,9 @@
</script>
</head>
<body>
+ <ul id="hostInfo">
+ <li>Linux pawel-pc 3.2.0-35-generic</li>
+ </ul>
<div id="widgetsWrap"></div>
</body>
</html>
View
@@ -40,6 +40,19 @@ b { font-weight: bold; }
.statusOk { color: green; }
.statusFail { color: red; }
+#hostInfo {
+ background: #333333;
+ color: #aaa;
+ box-shadow: 0 0 8px 0 #666;
+ padding: 2px;
+ height: 15px;
+}
+#hostInfo li {
+ float: left;
+ list-style: none;
+ margin-right: 30px;
+}
+
/* WIDGETS */
#widgetsWrap {
View
@@ -13,7 +13,7 @@ var WidgetManager = {
* Render function is executed at constant intervals, to update measurements.
*/
registeredWidgets: {},
- installedWidgets: [],
+ installedWidgets: {},
init: function() {
this.renderWidgets();
@@ -68,14 +68,15 @@ var WidgetManager = {
}
}
+ if (Object.keys(Config.getNamespace('widgets')).length == Object.keys(WidgetManager.installedWidgets).length)
+ WidgetManager.allWidgetsLoaded();
},
allWidgetsLoaded: function() {
- $('#widgetsWrap').isotope({
- sortBy : 'configOrder',
- sortAscending : 'asc'});
- $('#widgetsWrap').isotope( 'reLayout' );
+ setTimeout(function(){
+ $('#widgetsWrap').isotope( 'reLayout' );
+ }, 100);
},
/**
@@ -168,7 +169,6 @@ var Config = {
};
-
var Widget = {
id: "BaseWidget",
instanceId: null,
@@ -192,13 +192,9 @@ var Widget = {
if (typeof this.mainTpl == 'string')
this.$('.widget').html(this.mainTpl);
else if (typeof this.mainTpl == 'function')
- this.$('.widget').html(this.mainTpl());
-
- if (Config.getNamespace('widgets').length == WidgetManager.installedWidgets.length)
- WidgetManager.allWidgetsLoaded();
-
+ this.$('.widget').html(this.mainTpl());
+
this.init();
- $('#widgetsWrap').isotope( 'reLayout');
},
init: function() {
File renamed without changes.
View
@@ -0,0 +1,39 @@
+(function(){
+ var w = $.extend({}, Widget);
+
+ w.init = function() {
+ this.hostInfoEl = $('#hostInfo');
+ }
+
+ w.render = function(data) {
+ this.$().remove();
+ var html = '';
+ html += '<li>'+data['uname']+'</li>';
+ html += '<li>'+data['date']+'</li>';
+ html += '<li>'+parseUptime(data['uptime'])+'</li>';
+ this.hostInfoEl.html(html);
+ };
+
+ function two(x) {return ((x>9)?"":"0")+x}
+ function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}
+ function parseUptime(ms) {
+ var out = '';
+ var seconds = parseFloat(ms.split(' ')[0]);
+ var days = Math.floor(seconds / 86400);
+ var hours = Math.floor((seconds % 86400) / 3600);
+ var minutes = Math.floor(((seconds % 86400) % 3600) / 60);
+
+ if (days === 1) {
+ out = '1 day ';
+ } else if (days > 1) {
+ out = days + ' days ';
+ }
+ out += two(hours) + ':' + two(minutes);
+
+ return 'up '+out;
+ };
+
+ $(function(){
+ WidgetManager.register('HostInfoWidget', 'HostInfo', w);
+ });
+})();
View
@@ -0,0 +1,9 @@
+from core.widget import BaseWidget
+
+class HostInfoWidget(BaseWidget):
+ def collectData(self):
+ return {
+ "uname": self.runSystemCommand('uname -snrmo'),
+ "date": self.runSystemCommand('date'),
+ "uptime": file('/proc/uptime', 'r').read()
+ }
View
@@ -1,2 +0,0 @@
-.widget.UptimeWidget table { margin-top: 10px; }
-.widget.UptimeWidget table tr:nth-child(2n+1) td { background: transparent; }
View
@@ -1,38 +0,0 @@
-(function(){
- var w = $.extend({}, Widget);
-
- w.mainTpl = '<table width="99%">'+
- '<tr style="font-size:30px"><td class="uptimeDays" align="right" width="40%"><td><td>days</td>'+
- '<tr style="font-size:25px"><td class="uptimeHours" align="right"><td><td>hours</td>'+
- '<tr style="font-size:20px"><td class="uptimeMinutes" align="right"><td><td>minutes</td>'+
- '<tr style="font-size:15px"><td class="uptimeSeconds" align="right"><td><td>seconds</td></table>';
-
- w.render = function(data) {
- duration(data*1000);
- };
-
- function two(x) {return ((x>9)?"":"0")+x}
- function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}
- function duration(ms) {
- var sec = Math.floor(ms/1000)
- ms = ms % 1000
- //t = three(ms)
-
- var min = Math.floor(sec/60)
- sec = sec % 60
- this.$('.uptimeSeconds').text(sec);
-
- var hr = Math.floor(min/60)
- min = min % 60
- this.$('.uptimeMinutes').text(min);
-
- var day = Math.floor(hr/60)
- hr = hr % 60
- this.$('.uptimeHours').text(hr);
- this.$('.uptimeDays').text(day);
- };
-
- $(function(){
- WidgetManager.register('UptimeWidget', 'Uptime', w);
- });
-})();
View
@@ -1,6 +0,0 @@
-from core.widget import BaseWidget
-
-class UptimeWidget(BaseWidget):
- def collectData(self):
- s = file('/proc/uptime', 'r').read()
- return s[0 : s.find(' ')]

0 comments on commit 7805a33

Please sign in to comment.