Commit c0ef55d7 authored by Leo Iannacone's avatar Leo Iannacone

Merge branch 'master' into portable

parents 9005a739 608897a5
# 0.4.0 (2014-06-12)
* [new] always show only max_lines in preview, also when new_content is recevied
* [new] get debomatic real status by reading pidfile in /var/run directory
* [new] add History file
# 0.3.0 (2014-06-09)
* [new] files can have a preview
# 0.2.4 (2014-06-09)
* [fix] bugs relative to jshint validation
# 0.2.3 (2014-06-06)
* [new] get all sources in one click
* [fix] code valdiatation via jshint
# 0.2.2 (2014-06-04)
* [fix] upgrade to express 4.x
# 0.2.1 (2014-04-13)
* [fix] some style bugs
# 0.2.0 (2014-04-08)
* [new] get all debs in one click
* [new] enaled glossy theme by default
* [new] window with has a rationale title
* [new] improved welcome messages
* [new] upgrade to express 3.x
* [new] handle with debomatic pre_chroot and post_chroot hooks
* [new] add options -c and -h to cli script
* [fix] back on tail module instead of tailfd
* [fix] sticky bar
* [fix] serve js and css with a version number
* [fix] add new content to file using append() - reduce cpu usage
* [fix] many other bugs fix
# 0.1.0 (2014-04-07)
* Initial release
......@@ -72,6 +72,7 @@ server.listen(config.port, config.host, null, function (err) {
client.start();
if (status.length > 0)
client.send_status(status);
client.send_status_debomatic();
});
console.log('Debomatic-webui listening on %s:%d in %s mode', server.address().address, server.address().port, app.settings.env);
......
......@@ -63,12 +63,29 @@ function __watch_distributions(socket) {
});
}
function __watch_pidfile(socket) {
fs.watchFile(config.debomatic.pidfile, {
persistent: false,
interval: 1007
},
function (curr, prev) {
var status_debomatic = {
"running": curr.ino !== 0 // if === 0 means pidfile does not exists
};
try {
socket.emit(socket.emit(config.events.broadcast.status_debomatic, status_debomatic));
} catch (err) {}
});
}
function Broadcaster(sockets, status) {
__watch_status(sockets, status);
__watch_distributions(sockets);
__watch_pidfile(sockets);
return {
};
......
......@@ -115,7 +115,7 @@ function __send_file(event_name, socket, data, last_lines) {
}
data.file.orig_name = file_path.split('/').pop();
if (last_lines > 0)
data.file.content = content.split('\n').slice(-25).join('\n');
data.file.content = content.split('\n').slice(-last_lines).join('\n');
else
data.file.content = content;
data.file.path = file_path.replace(config.debomatic.path, config.routes.debomatic);
......@@ -181,6 +181,14 @@ function Client(socket) {
this.send_status = function (status) {
socket.emit(_e.status, status);
};
this.send_status_debomatic = function () {
fs.exists(config.debomatic.pidfile, function (exists) {
socket.emit(config.events.broadcast.status_debomatic, {
'running': exists
});
});
};
}
module.exports = Client;
......@@ -67,7 +67,7 @@ config.web.preferences.debug = 0; // debug level - 0 means disabled
// DO NOT TOUCH these ones
config.version = '0.3.1';
config.version = '0.4.0';
// A simple function to quickly have
// get and set strings for client events
......@@ -78,11 +78,18 @@ function _event_get_set(event_name) {
};
}
config.debomatic.pidfile = "/var/run/debomatic-" +
require('crypto')
.createHash('sha256')
.update(config.debomatic.path)
.digest('hex');
config.events = {};
config.events.error = 'error';
config.events.broadcast = {};
config.events.broadcast.distributions = 'distributions';
config.events.broadcast.status_update = 'status_update';
config.events.broadcast.status_debomatic = 'status_debomatic';
config.events.client = {};
config.events.client.distribution_packages = _event_get_set('distribution_packages');
......
'use strict';
/* global debug: false */
/* global page_generic: false */
// function to get all files in on click
// event comes from HTML
function download_all(div_id) {
......@@ -65,7 +68,7 @@ function Page_Distrubion(socket) {
var _e = config.events.client;
var view = Utils.from_hash_to_view();
var sidebarOffset = 0;
var new_lines = [];
var current_file_in_preview = false;
function __check_hash_makes_sense() {
if (window.location.hash.indexOf('..') >= 0) {
......@@ -100,6 +103,7 @@ function Page_Distrubion(socket) {
label += ' <a class="btn btn-link btn-lg" title="Download" href="' + view.file.path + '"> ' +
'<span class="glyphicon glyphicon-download-alt"></span></a>';
if (config.file.preview.indexOf(view.file.name) >= 0) {
current_file_in_preview = true;
var view_all = $('<a id="get-whole-file" class="btn btn-link btn-lg" title="View the whole file"></a>');
view_all.html('<span class="glyphicon glyphicon-eye-open"></span>');
label += view_all.get(0).outerHTML;
......@@ -230,7 +234,7 @@ function Page_Distrubion(socket) {
// update html
socket_data.package.sources.forEach(function (f) {
$('#sources ul').append('<li><a title="' + f.orig_name + '" href="' + f.path + '">' + f.name + '</a></li>');
})
});
$('#sources').show();
}
files.show();
......@@ -284,7 +288,15 @@ function Page_Distrubion(socket) {
},
append: function (new_content) {
var content = $('#file pre');
content.append(new_content);
if (!current_file_in_preview) {
content.append(new_content);
} else {
// always show only config.file.num_lines lines in preview
content = content.html().replace(/\n$/, '').split('\n');
content = content.concat(new_content.replace(/\n$/, '').split('\n'));
content = content.slice(-config.file.num_lines).join('\n');
$('#file pre').html(content);
}
if (config.preferences.autoscroll) {
// scroll down if file is covering footer
......@@ -571,7 +583,7 @@ function Page_Distrubion(socket) {
socket.on(_e.file_newcontent, function (socket_data) {
debug_socket('received', _e.file_newcontent, socket_data);
new_lines.push(socket_data.file.new_content);
file.append(socket_data.file.new_content);
});
$(window).on('hashchange', function () {
......@@ -609,18 +621,6 @@ function Page_Distrubion(socket) {
// events. Sleep a while and call stiky.reset()
setTimeout(sticky.reset, 500);
// WORKAROUND:
// On incoming hundred of lines browser goes crazy.
// Append lines every 200 mills.
function watch_for_new_lines() {
if (new_lines.length > 0) {
file.append(new_lines.join(''));
new_lines = [];
}
setTimeout(watch_for_new_lines, 200);
}
watch_for_new_lines();
// Update html according with preferences
preferences();
......
......@@ -2,6 +2,7 @@
function Page_Generic() {
var _e = config.events;
var status_debomatic = {};
function __get_status_html_id(status_data) {
var result = 'status-' + status_data.status + '-' + status_data.distribution;
......@@ -73,11 +74,21 @@ function Page_Generic() {
var status = {
set: function (data_status) {
$('#status ul').html('');
if (data_status.length > 0) {
data_status.forEach(function (s) {
status.append(s);
});
if (!data_status) {
if (status_debomatic.running) {
$('#status .idle').show();
$('#status .norunning').hide();
} else {
$('#status .idle').hide();
$('#status .norunning').show();
}
} else {
$('#status ul').html('');
if (data_status.length > 0) {
data_status.forEach(function (s) {
status.append(s);
});
}
}
},
append: function (status_data) {
......@@ -107,8 +118,9 @@ function Page_Generic() {
// and show idle label if necessary.
setTimeout(function () {
li.remove();
if ($('#status li').length === 0)
$('#status .idle').show();
if ($('#status li').length === 0) {
status.set();
}
}, config.status.delay.remove + 2000); // more delay on remove html
}, config.status.delay.remove);
} else if (!status_data.hasOwnProperty('success')) {
......@@ -159,6 +171,12 @@ function Page_Generic() {
status.update(package_status);
});
socket.on(_e.broadcast.status_debomatic, function (socket_status_debomatic) {
debug_socket('received', _e.broadcast.status_debomatic, socket_status_debomatic);
status_debomatic = socket_status_debomatic;
status.set();
});
socket.on(_e.error, function (error) {
console.error('socket > ' + error);
});
......
......@@ -116,6 +116,10 @@ footer {
margin-right: 10px;
}
#status .debomatic {
display: none;
}
#status .packages {
display: inline;
}
......
</div> <!-- #wrapper -->
<footer class="container-fluid">
<small class="copyright pull-right text-muted">
Fork me on <a href="https://github.com/LeoIannacone/debomatic-webui">github</a>
</small>
<div id="status" class="clearfix">
<span class="label label-default">status:</span> <span class="idle text-muted">Idle</span>
<span class="label label-default">status:</span>
<span class="debomatic idle text-muted">Idle</span>
<span class="debomatic norunning text-danger">Not running</span>
<ul class="packages list-inline"></ul>
</div>
</footer>
......
'use strict';
/**
* Benchmark related modules.
*/
var benchmark = require('benchmark')
, microtime = require('microtime');
/**
* Logger
*/
var logger = new(require('devnull'))({ timestamp: false, namespacing: 0 });
/**
* Preparation code.
*/
var EventEmitter2 = require('eventemitter2').EventEmitter2
, EventEmitter3 = require('../../').EventEmitter
, EventEmitter1 = require('events').EventEmitter;
function foo() {
if (arguments.length > 100) console.log('damn');
return 1;
}
/**
* Instances.
*/
var ee2 = new EventEmitter2()
, ee3 = new EventEmitter3()
, ee1 = new EventEmitter1()
, j, i;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
ee1.on('event:' + i, foo);
}
}
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
ee2.on('event:' + i, foo);
}
}
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
ee3.on('event:' + i, foo);
}
}
(
new benchmark.Suite()
).add('EventEmitter 1', function test1() {
for (i = 0; i < 10; i++) {
ee1.emit('event:' + i);
}
}).add('EventEmitter 2', function test2() {
for (i = 0; i < 10; i++) {
ee2.emit('event:' + i);
}
}).add('EventEmitter 3', function test2() {
for (i = 0; i < 10; i++) {
ee3.emit('event:' + i);
}
}).on('cycle', function cycle(e) {
var details = e.target;
logger.log('Finished benchmarking: "%s"', details.name);
logger.metric('Count (%d), Cycles (%d), Elapsed (%d), Hz (%d)'
, details.count
, details.cycles
, details.times.elapsed
, details.hz
);
}).on('complete', function completed() {
logger.info('Benchmark: "%s" is was the fastest.'
, this.filter('fastest').pluck('name')
);
}).run();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment