Commit 300f0309 authored by Leo Iannacone's avatar Leo Iannacone

get packages history via socket

parent 9dfd472d
...@@ -2,6 +2,7 @@ fs = require("fs") ...@@ -2,6 +2,7 @@ fs = require("fs")
path = require("path") path = require("path")
config = require("./config") config = require("./config")
utils = require("./utils") utils = require("./utils")
stats = require("./stats")
e = config.events.client e = config.events.client
get_files_list_from_package = (data, callback) -> get_files_list_from_package = (data, callback) ->
...@@ -138,6 +139,10 @@ class Client ...@@ -138,6 +139,10 @@ class Client
read_package_status data, (content) => read_package_status data, (content) =>
@socket.emit e.package_info, content @socket.emit e.package_info, content
@socket.on e.history, () =>
stats.get_all_packages (packages) =>
@socket.emit e.history, packages
# on client disconnection close all watchers # on client disconnection close all watchers
@socket.on "disconnect", => @socket.on "disconnect", =>
socket_watchers = @socket.watchers socket_watchers = @socket.watchers
......
...@@ -117,6 +117,7 @@ config.events.client.package_info = "c.package_info" ...@@ -117,6 +117,7 @@ config.events.client.package_info = "c.package_info"
config.events.client.file = "c.file" config.events.client.file = "c.file"
config.events.client.file_newcontent = "c.file_newcontent" config.events.client.file_newcontent = "c.file_newcontent"
config.events.client.status = "c.status" config.events.client.status = "c.status"
config.events.client.history = "c.history"
### ###
The status according with JSONLogger.py module The status according with JSONLogger.py module
......
fs = require('fs')
glob = require('glob')
config = require('./config')
utils = require('./utils')
get_all_packages = (cb) ->
compare = (a,b) ->
if a.start < b.start
return -1
if a.start > b.start
return 1
return 0
glob "#{config.debomatic.path}/*/pool/*/*.json", {}, (err, files) ->
if err?
utils.errors_handler "history:get_all_packages", err
return
packages = []
for f in files
fs.readFile f, (readerr, data) ->
if readerr?
utils.errors_handler "history:get_all_packages:readFile", readerr
json = ''
else
json = JSON.parse(data)
delete json.files
packages.push(json)
if packages.length == files.length
packages.sort(compare)
cb(packages)
module.exports.get_all_packages = get_all_packages
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
/* global Chartist: false */ /* global Chartist: false */
/* global debug: false */ /* global debug: false */
/* global debug_socket: false */ /* global debug_socket: false */
/* global dom_history: false */ /* global socket: false */
function Page_History() { function Page_History() {
...@@ -234,12 +234,17 @@ function Page_History() { ...@@ -234,12 +234,17 @@ function Page_History() {
socket.on(config.events.broadcast.status_update, function (socket_data) { socket.on(config.events.broadcast.status_update, function (socket_data) {
// TODO - implements _update_table // TODO - implements _update_table
}); });
};
socket.on(config.events.client.history, function (socket_data) {
debug_socket('received', config.events.client.history, socket_data);
distributions_counter = {};
days_counter = {};
all_distributions = [];
all_days = [];
$('#history .tbody').html('');
// init table and some objects // init table and some objects
for (var i = 0; i < dom_history.length; i++) { for (var i = 0; i < socket_data.length; i++) {
var p = dom_history[i]; var p = socket_data[i];
_add_row(p); _add_row(p);
// count stats // count stats
_count_distributions(p); _count_distributions(p);
...@@ -249,6 +254,11 @@ function Page_History() { ...@@ -249,6 +254,11 @@ function Page_History() {
_sort_table(); _sort_table();
_create_graph_distributions(); _create_graph_distributions();
_create_graph_days(); _create_graph_days();
});
debug_socket('emit', config.events.client.history, '');
socket.emit(config.events.client.history);
};
$('#download').on('click', function () { $('#download').on('click', function () {
_exportTableToCSV.apply(this, [$('#history'), 'history.csv']); _exportTableToCSV.apply(this, [$('#history'), 'history.csv']);
......
...@@ -19,18 +19,5 @@ exports.commands = (req, res) -> ...@@ -19,18 +19,5 @@ exports.commands = (req, res) ->
return return
exports.history = (req, res) -> exports.history = (req, res) ->
glob "#{config.debomatic.path}/*/pool/*/*.json", {}, (err, files) ->
get_info = (json_path) ->
json = JSON.parse(fs.readFileSync(json_path, 'utf8'))
delete json.files
return json
compare = (a,b) ->
if a.start < b.start
return -1
if a.start > b.start
return 1
return 0
config.history = (get_info(f) for f in files)
config.history.sort(compare)
res.render "history", config res.render "history", config
return
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<p class="lead text-muted"> <p class="lead text-muted">
The log of packages The log of packages
</p> </p>
<script> var dom_history = <%- JSON.stringify(history) %> </script>
<div id="charts"> <div id="charts">
<div id="days-chart" class="ct-chart"></div> <div id="days-chart" class="ct-chart"></div>
<div id="distributions-chart" class="ct-chart"></div> <div id="distributions-chart" class="ct-chart"></div>
......
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