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);
io.sockets.on('connection', function(socket) {
send.distributions(socket);
socket.on('get-view', function(data) {
socket.get('view', function(err, view) {
if (!view || view != data) {
socket.get('watchers', function(err, watchers) {
if (watchers) watchers.forEach(function(w){
w.close()
});
watchers = []
socket.set('view', data, function() {
// send distribution packages
socket.on('get_distribution_packages', function (data) {
if (!data)
return
socket.get("watcher-distribution-packages", function(err, watcher){
if (watcher)
watcher.close()
if (!data.distribution || !data.distribution.name)
return
packages_path = path.join(config.debomatic_path, data.distribution.name, 'pool')
// watch on incoming packages
// watch for incoming packages
try {
watchIncomingPackages = fs.watch(packages_path, { persistent: true}, function(event, fileName) {
watcher = fs.watch(packages_path, { persistent: true}, function(event, fileName) {
if (event == 'rename')
send.view(socket, data);
send.distribution_packages(socket, data);
});
watchers.push(watchIncomingPackages);
socket.set('watcher-distribution-packages', watcher);
} 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);
})
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 {
watchPackageFiles = fs.watch(pack_path, {persistent: true}, function (event, filename) {
watcher = fs.watch(package_path, { persistent: true}, function(event, fileName) {
if (event == 'rename')
send.view(socket, data);
send.package_file_list(socket, data);
});
watchers.push(watchPackageFiles)
socket.set('watcher-package-files-list', watcher);
} catch (err) {}
}
socket.set('watchers', watchers);
});
});
send.view(socket, data);
};
});
});
})
send.package_file_list(socket, data);
})
});
io.sockets.on('disconnect', function(socket){
socket.get('watchers', function(err, watchers) {
if (watchers) watchers.forEach(function(w){
......
......@@ -4,7 +4,7 @@ var fs = require('fs')
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){
result = [];
if (err) {
......@@ -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 = {}
get_files_list(package_path, false, function(files) {
__get_files_list(package_path, false, function(files) {
package_info.files = []
package_info.debs = []
package_info.archives = []
files.forEach(function (f) {
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.name = f.split('_')[0]
file.label = f.replace(file.name + '_', '')
......@@ -55,17 +55,25 @@ function get_files_list_from_pacakge(package_path, callback) {
});
}
debomatic_sender = {
distributions: function(socket) {
get_files_list(BASE_DIR, true, function(distros){
socket.emit('distributions', distros);
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)
});
},
}
view: function (socket, 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) {
__get_files_list(distro_path, true, function (packages) {
data.distribution.packages = []
packages.forEach( function (p) {
pack = {}
......@@ -79,20 +87,24 @@ debomatic_sender = {
}
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)
socket.emit("distribution_packages", data)
});
}
else {
socket.emit('view', data)
}
}
debomatic_sender = {
distributions: function(socket) {
__get_files_list(BASE_DIR, true, function(distros){
socket.emit('distributions', distros);
});
},
package_file_list: function(socket, data) {
__send_package_files_list(socket, data)
},
distribution_packages: function(socket, data) {
__send_distribution_packages(socket, data)
}
}
......
......@@ -12,39 +12,20 @@
if (info.length >= 1) {
data.distribution = {}
data.distribution.name = info[0];
socket.emit("get_distribution_packages", data)
}
if (info.length >= 3){
data.package = {}
data.package.name = info[1];
data.package.version = info[2];
socket.emit("get_package_file_list", data)
}
if (info.length == 4) {
if (info.length >= 4) {
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');
socket.on('distributions', function(distributions) {
......@@ -54,10 +35,20 @@
});
});
socket.on('view', function(data){
console.log(data)
set_up_view(data)
});
socket.on('distribution_packages', function(data){
$('#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>')
})
})
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) });
......
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