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,33 +28,8 @@ function get_files_list(dir, onlyDirectories, callback) {
});
}
debomatic_sender = {
distributions: function(socket) {
get_files_list(BASE_DIR, true, function(distros){
socket.emit('distributions', distros);
});
},
packages_list: function(socket, data) {
distro_path = path.join(BASE_DIR, data.distribution, 'pool');
get_files_list(distro_path, true, function (packages) {
result = {}
result.distribution = data.distribution;
result.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);
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 = []
......@@ -77,7 +52,47 @@ debomatic_sender = {
package_info.files.push(file)
}
});
socket.emit('package-files', package_info);
callback(package_info);
});
}
debomatic_sender = {
distributions: function(socket) {
get_files_list(BASE_DIR, true, function(distros){
socket.emit('distributions', distros);
});
},
view: function (socket, data) {
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)
});
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);
}
......@@ -27,22 +29,8 @@
});
});
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