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); ...@@ -40,12 +40,7 @@ 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.on('get-view', function(data) {
if (! data.package) { send.view(socket, data);
send.packages_list(socket, data);
}
else {
send.package(socket, data);
}
}); });
}); });
......
...@@ -28,6 +28,34 @@ function get_files_list(dir, onlyDirectories, callback) { ...@@ -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 = { debomatic_sender = {
distributions: function(socket) { distributions: function(socket) {
...@@ -36,48 +64,35 @@ debomatic_sender = { ...@@ -36,48 +64,35 @@ debomatic_sender = {
}); });
}, },
packages_list: function(socket, data) { view: function (socket, data) {
distro_path = path.join(BASE_DIR, data.distribution, 'pool'); distro_path = path.join(BASE_DIR, data.distribution.name, 'pool');
get_files_list(distro_path, true, function (packages) { get_files_list(distro_path, true, function (packages) {
result = {} data.distribution.packages = []
result.distribution = data.distribution;
result.packages = []
packages.forEach( function (p) { packages.forEach( function (p) {
pack = {} pack = {}
info = p.split('_') info = p.split('_')
pack.name = info[0] pack.name = info[0]
pack.version = info[1] pack.version = info[1]
result.packages.push(pack) if(data.package &&
}); pack.name == data.package.name &&
socket.emit('packages', result); pack.version == data.package.version ) {
}); pack.selected = true;
},
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)
} }
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 @@ ...@@ -10,11 +10,13 @@
info = path.split('/'); info = path.split('/');
data = {} data = {}
if (info.length >= 1) { if (info.length >= 1) {
data.distribution = info[0]; data.distribution = {}
data.distribution.name = info[0];
} }
if (info.length >= 3){ if (info.length >= 3){
data.package = info[1]; data.package = {}
data.version = info[2]; data.package.name = info[1];
data.package.version = info[2];
} }
socket.emit('get-view', data); socket.emit('get-view', data);
} }
...@@ -26,23 +28,9 @@ ...@@ -26,23 +28,9 @@
$('#distributions').append('<li><a href="#' + name + '">' + name + '</li>'); $('#distributions').append('<li><a href="#' + name + '">' + name + '</li>');
}); });
}); });
socket.on('packages', function(data) { socket.on('view', function(data){
$('#packages').html(''); console.log(data)
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('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