Commit fa1dac59 authored by Leo Iannacone's avatar Leo Iannacone

split single event get view in three different ones

parent 6baf925a
...@@ -40,44 +40,53 @@ app.get('/', routes.index); ...@@ -40,44 +40,53 @@ app.get('/', routes.index);
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
send.distributions(socket); send.distributions(socket);
socket.on('get-view', function(data) {
socket.get('view', function(err, view) { // send distribution packages
if (!view || view != data) { socket.on('get_distribution_packages', function (data) {
socket.get('watchers', function(err, watchers) { if (!data)
if (watchers) watchers.forEach(function(w){ return
w.close() socket.get("watcher-distribution-packages", function(err, watcher){
}); if (watcher)
watchers = [] watcher.close()
socket.set('view', data, function() { if (!data.distribution || !data.distribution.name)
packages_path = path.join(config.debomatic_path, data.distribution.name, 'pool') return
// watch on incoming packages packages_path = path.join(config.debomatic_path, data.distribution.name, 'pool')
try { // watch for incoming packages
watchIncomingPackages = fs.watch(packages_path, { persistent: true}, function(event, fileName) { try {
if (event == 'rename') watcher = fs.watch(packages_path, { persistent: true}, function(event, fileName) {
send.view(socket, data); if (event == 'rename')
}); send.distribution_packages(socket, data);
watchers.push(watchIncomingPackages);
} catch (err) {}
// if user is viewing a package, watch package dir
if (data.package && data.package.name && data.package.version) {
pack_path = path.join(packages_path, data.package.name + '_' + data.package.version);
try {
watchPackageFiles = fs.watch(pack_path, {persistent: true}, function (event, filename) {
if (event == 'rename')
send.view(socket, data);
});
watchers.push(watchPackageFiles)
} catch (err) {}
}
socket.set('watchers', watchers);
});
}); });
send.view(socket, data); socket.set('watcher-distribution-packages', watcher);
}; } catch (err) {}
}); })
}); send.distribution_packages(socket, data);
})
socket.on('get_package_file_list', function(data) {
if (!data)
return
socket.get('wather-package-files-list', function (err, watcher) {
if (watcher)
watcher.close()
if (!data.distribution || !data.distribution.name ||
! data.package ||
! data.package.name || ! data.package.version)
return
package_path = path.join(config.debomatic_path, data.distribution.name, 'pool', data.package.name + "_" + data.package.version)
try {
watcher = fs.watch(package_path, { persistent: true}, function(event, fileName) {
if (event == 'rename')
send.package_file_list(socket, data);
});
socket.set('watcher-package-files-list', watcher);
} catch (err) {}
})
send.package_file_list(socket, data);
})
}); });
io.sockets.on('disconnect', function(socket){ io.sockets.on('disconnect', function(socket){
socket.get('watchers', function(err, watchers) { socket.get('watchers', function(err, watchers) {
if (watchers) watchers.forEach(function(w){ if (watchers) watchers.forEach(function(w){
......
...@@ -4,7 +4,7 @@ var fs = require('fs') ...@@ -4,7 +4,7 @@ var fs = require('fs')
var BASE_DIR = config.debomatic_path; var BASE_DIR = config.debomatic_path;
function get_files_list(dir, onlyDirectories, callback) { function __get_files_list(dir, onlyDirectories, callback) {
fs.readdir(dir, function(err, files){ fs.readdir(dir, function(err, files){
result = []; result = [];
if (err) { if (err) {
...@@ -28,15 +28,15 @@ function get_files_list(dir, onlyDirectories, callback) { ...@@ -28,15 +28,15 @@ function get_files_list(dir, onlyDirectories, callback) {
}); });
} }
function get_files_list_from_pacakge(package_path, callback) { function __get_files_list_from_pacakge(package_path, callback) {
package_info = {} package_info = {}
get_files_list(package_path, false, function(files) { __get_files_list(package_path, false, function(files) {
package_info.files = [] package_info.files = []
package_info.debs = [] package_info.debs = []
package_info.archives = [] package_info.archives = []
files.forEach(function (f) { files.forEach(function (f) {
file = {} file = {}
file.path = path.join(pack_path, f).replace(config.debomatic_path, config.debomatic_webpath) file.path = path.join(package_path, f).replace(config.debomatic_path, config.debomatic_webpath)
file.orig_name = f file.orig_name = f
file.name = f.split('_')[0] file.name = f.split('_')[0]
file.label = f.replace(file.name + '_', '') file.label = f.replace(file.name + '_', '')
...@@ -55,44 +55,56 @@ function get_files_list_from_pacakge(package_path, callback) { ...@@ -55,44 +55,56 @@ function get_files_list_from_pacakge(package_path, callback) {
}); });
} }
function __send_package_files_list (socket, data) {
if (!data.package || ! data.distribution)
return
distro_path = path.join(BASE_DIR, data.distribution.name, 'pool');
p = data.package.name + "_" + data.package.version
package_path = path.join(distro_path, p)
__get_files_list_from_pacakge(package_path, function(package_files){
data.package.files = package_files.files
data.package.debs = package_files.debs
data.package.archives = package_files.archives
socket.emit('package_file_list', data)
});
}
function __send_distribution_packages (socket, data) {
if (!data.distribution || ! data.distribution.name)
return;
distro_path = path.join(BASE_DIR, data.distribution.name, 'pool');
__get_files_list(distro_path, true, function (packages) {
data.distribution.packages = []
packages.forEach( function (p) {
pack = {}
info = p.split('_')
pack.name = info[0]
pack.version = info[1]
if(data.package &&
pack.name == data.package.name &&
pack.version == data.package.version ) {
pack.selected = true;
}
data.distribution.packages.push(pack)
});
socket.emit("distribution_packages", data)
});
}
debomatic_sender = { debomatic_sender = {
distributions: function(socket) { distributions: function(socket) {
get_files_list(BASE_DIR, true, function(distros){ __get_files_list(BASE_DIR, true, function(distros){
socket.emit('distributions', distros); socket.emit('distributions', distros);
}); });
}, },
view: function (socket, data) { package_file_list: function(socket, data) {
distro_path = path.join(BASE_DIR, data.distribution.name, 'pool'); __send_package_files_list(socket, data)
get_files_list(distro_path, true, function (packages) { },
data.distribution.packages = []
packages.forEach( function (p) { distribution_packages: function(socket, data) {
pack = {} __send_distribution_packages(socket, data)
info = p.split('_')
pack.name = info[0]
pack.version = info[1]
if(data.package &&
pack.name == data.package.name &&
pack.version == data.package.version ) {
pack.selected = true;
}
data.distribution.packages.push(pack)
});
if (data.package) {
p = data.package.name + "_" + data.package.version
package_path = path.join(distro_path, p)
get_files_list_from_pacakge(package_path, function(package_files){
data.package.files = package_files.files
data.package.debs = package_files.debs
data.package.archives = package_files.archives
socket.emit('view', data)
});
}
else {
socket.emit('view', data)
}
});
} }
} }
......
...@@ -12,39 +12,20 @@ ...@@ -12,39 +12,20 @@
if (info.length >= 1) { if (info.length >= 1) {
data.distribution = {} data.distribution = {}
data.distribution.name = info[0]; data.distribution.name = info[0];
socket.emit("get_distribution_packages", data)
} }
if (info.length >= 3){ if (info.length >= 3){
data.package = {} data.package = {}
data.package.name = info[1]; data.package.name = info[1];
data.package.version = info[2]; data.package.version = info[2];
socket.emit("get_package_file_list", data)
} }
if (info.length == 4) { if (info.length >= 4) {
data.file = info[3] data.file = info[3]
socket.emit('get-file', data) socket.emit("get_file", data)
} }
else
socket.emit('get-view', data);
} }
function set_up_view(data) {
if (data) {
if (data.distribution) {
if (data.distribution.name && data.distribution.packages) {
$('#packages').html('')
data.distribution.packages.forEach(function(p){
div = $('#packages').append('<li><a href="#' + data.distribution.name + '/' + p.name + '/'+ p.version + '">'+ p.name + ' <span>'+p.version+'</span></a></li>')
})
}
if (data.package) {
$('#files').html('');
data.package.files.forEach(function(f){
p = data.package
$('#files').append('<li><a href="#' + data.distribution.name + '/' + p.name + '/'+ p.version + '/' + f.name + '">' + f.name + '</a></li>')
})
}
}
}
}
var socket = io.connect('//localhost:3000'); var socket = io.connect('//localhost:3000');
socket.on('distributions', function(distributions) { socket.on('distributions', function(distributions) {
...@@ -54,10 +35,20 @@ ...@@ -54,10 +35,20 @@
}); });
}); });
socket.on('view', function(data){ socket.on('distribution_packages', function(data){
console.log(data) $('#packages').html('')
set_up_view(data) data.distribution.packages.forEach(function(p){
}); div = $('#packages').append('<li><a href="#' + data.distribution.name + '/' + p.name + '/'+ p.version + '">'+ p.name + ' <span>'+p.version+'</span></a></li>')
})
})
socket.on('package_file_list', function(data){
$('#files').html('');
data.package.files.forEach(function(f){
p = data.package
$('#files').append('<li><a href="#' + data.distribution.name + '/' + p.name + '/'+ p.version + '/' + f.name + '">' + f.name + '</a></li>')
})
})
socket.on('error', function() { console.error(arguments) }); socket.on('error', function() { console.error(arguments) });
......
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