Commit b40680d0 authored by Leo Iannacone's avatar Leo Iannacone

work only on a single view event

parent 0154eeef
......@@ -40,12 +40,7 @@ app.get('/', routes.index);
io.sockets.on('connection', function(socket) {
send.distributions(socket);
socket.on('get-view', function(data) {
if (! data.package) {
send.packages_list(socket, data);
}
else {
send.package(socket, data);
}
send.view(socket, data);
});
});
......
......@@ -28,6 +28,34 @@ function get_files_list(dir, onlyDirectories, callback) {
});
}
function get_files_list_from_pacakge(package_path, callback) {
package_info = {}
get_files_list(package_path, false, function(files) {
package_info.files = []
package_info.debs = []
package_info.archives = []
files.forEach(function (f) {
extension = f.split('.').pop();
if (extension == "deb" || extension == "ddeb")
package_info.debs.push(f);
else if (f.indexOf('.tar') >= 0) {
archive = {}
archive.name = f
archive.path = path.join(package_path, f)
package_info.archives.push(archive)
}
else {
file = {}
file.name = f
file.path = path.join(package_path, f)
file.label = extension
package_info.files.push(file)
}
});
callback(package_info);
});
}
debomatic_sender = {
distributions: function(socket) {
......@@ -36,48 +64,35 @@ debomatic_sender = {
});
},
packages_list: function(socket, data) {
distro_path = path.join(BASE_DIR, data.distribution, 'pool');
view: function (socket, data) {
distro_path = path.join(BASE_DIR, data.distribution.name, 'pool');
get_files_list(distro_path, true, function (packages) {
result = {}
result.distribution = data.distribution;
result.packages = []
data.distribution.packages = []
packages.forEach( function (p) {
pack = {}
info = p.split('_')
pack.name = info[0]
pack.version = info[1]
result.packages.push(pack)
});
socket.emit('packages', result);
});
},
package: function (socket, package_info) {
package_path = path.join(BASE_DIR, package_info.distribution, 'pool', package_info.package + "_" + package_info.version);
get_files_list(package_path, false, function(files) {
package_info.files = []
package_info.debs = []
package_info.archives = []
files.forEach(function (f) {
extension = f.split('.').pop();
if (extension == "deb" || extension == "ddeb")
package_info.debs.push(f);
else if (f.indexOf('.tar') >= 0) {
archive = {}
archive.name = f
archive.path = path.join(package_path, f)
package_info.archives.push(archive)
}
else {
file = {}
file.name = f
file.path = path.join(package_path, f)
file.label = extension
package_info.files.push(file)
if(data.package &&
pack.name == data.package.name &&
pack.version == data.package.version ) {
pack.selected = true;
}
data.distribution.packages.push(pack)
});
socket.emit('package-files', package_info);
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(data)
}
});
}
}
......
......@@ -10,11 +10,13 @@
info = path.split('/');
data = {}
if (info.length >= 1) {
data.distribution = info[0];
data.distribution = {}
data.distribution.name = info[0];
}
if (info.length >= 3){
data.package = info[1];
data.version = info[2];
data.package = {}
data.package.name = info[1];
data.package.version = info[2];
}
socket.emit('get-view', data);
}
......@@ -26,23 +28,9 @@
$('#distributions').append('<li><a href="#' + name + '">' + name + '</li>');
});
});
socket.on('packages', function(data) {
$('#packages').html('');
distro = data.distribution
data.packages.forEach(function (p){
$('#packages').append('<li><a href="#' + distro + "/" + p.name + "/" + p.version +'">' + p.name + " [" + p.version + "]" + '</li>');
});
});
socket.on('package-files', function(data) {
$('#files').html('');
distro = data.distribution
package = data.package
version = data.version
data.files.forEach(function (f){
$('#files').append('<li><a href="#' + distro + "/" + package + "/" +version +'/'+ f.name +'">'+ f.label + '</li>');
});
socket.on('view', function(data){
console.log(data)
});
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