Commit 697053ac authored by Leo Iannacone's avatar Leo Iannacone

refactored Page_Description code

parent 9a31568d
...@@ -19,42 +19,5 @@ socket.on('status-update', function(data) { ...@@ -19,42 +19,5 @@ socket.on('status-update', function(data) {
}) })
if (window.location.pathname == PATHS.distribution) { if (window.location.pathname == PATHS.distribution) {
new Page_Distrubion().init(socket)
function __check_hash_makes_sense() {
if (! window.location.hash)
window.location.pathname = '/'
info = window.location.hash.split('/')
if (info.length == 2)
window.location.hash = info[0]
}
var old_data = Utils.from_hash_to_data()
socket.on('distribution_packages', function(data){
Page_Distrubion.packages.set(data)
})
socket.on('package_files_list', function(data){
Page_Distrubion.files.set(data)
})
socket.on('file', function (data) {
Page_Distrubion.file.set(data)
})
socket.on('file_newcontent', function(data) {
Page_Distrubion.file.append(data)
})
$(window).on('hashchange', function() {
__check_hash_makes_sense()
data = Utils.from_hash_to_data()
Page_Distrubion.update(data, old_data)
old_data = data
});
$(window).on('load', function (){
__check_hash_makes_sense()
Page_Distrubion.update(old_data)
});
} }
var Page_Distrubion = { function Page_Distrubion()
{
var socket
var data = Utils.from_hash_to_data()
title: { function __check_hash_makes_sense() {
if (! window.location.hash)
window.location.pathname = '/'
info = window.location.hash.split('/')
if (info.length == 2)
window.location.hash = info[0]
}
var title = {
set: function(data) { set: function(data) {
if (! data) if (! data)
data = Utils.from_hash_to_data() data = Utils.from_hash_to_data()
...@@ -23,9 +34,9 @@ var Page_Distrubion = { ...@@ -23,9 +34,9 @@ var Page_Distrubion = {
clean: function() { clean: function() {
$('#title').html('') $('#title').html('')
} }
}, }
packages: { var packages = {
set: function (data) { set: function (data) {
$('#packages ul').html('') $('#packages ul').html('')
tmp = data tmp = data
...@@ -34,7 +45,7 @@ var Page_Distrubion = { ...@@ -34,7 +45,7 @@ var Page_Distrubion = {
tmp.package = p tmp.package = p
$('#packages ul').append('<li id="package-' + p.orig_name + '"><a href="' + Utils.from_data_to_hash(tmp) + '">'+ p.name + ' <span>'+p.version+'</span></a></li>') $('#packages ul').append('<li id="package-' + p.orig_name + '"><a href="' + Utils.from_data_to_hash(tmp) + '">'+ p.name + ' <span>'+p.version+'</span></a></li>')
}) })
Page_Distrubion.select(data) select(data)
}, },
clean: function () { clean: function () {
...@@ -50,7 +61,7 @@ var Page_Distrubion = { ...@@ -50,7 +61,7 @@ var Page_Distrubion = {
} }
}, },
select: function(data) { select: function(data) {
Page_Distrubion.packages.unselect() packages.unselect()
if (! data) if (! data)
data = Utils.from_hash_to_data() data = Utils.from_hash_to_data()
if (Utils.check_data_package(data)) { if (Utils.check_data_package(data)) {
...@@ -60,24 +71,24 @@ var Page_Distrubion = { ...@@ -60,24 +71,24 @@ var Page_Distrubion = {
unselect: function() { unselect: function() {
$('#packages li').removeClass('active') $('#packages li').removeClass('active')
} }
}, }
files: { var files = {
set: function (data) { set: function (data) {
Page_Distrubion.files.clean() files.clean()
tmp = data tmp = data
if (data.package.files && data.package.files.length > 0) { if (data.package.files && data.package.files.length > 0) {
selected_file = Utils.check_data_file(data) selected_file = Utils.check_data_file(data)
data.package.files.forEach(function(f){ data.package.files.forEach(function(f){
tmp.file = f tmp.file = f
file = $('<li id="file-'+ f.orig_name +'"><a title="'+ f.orig_name +'" href="'+ Utils.from_data_to_hash(tmp) + '">' + f.name + '</a></li>') current_file = $('<li id="file-'+ f.orig_name +'"><a title="'+ f.orig_name +'" href="'+ Utils.from_data_to_hash(tmp) + '">' + f.name + '</a></li>')
file.on("click", function(){ current_file.on("click", function(){
Page_Distrubion.files.select(this) files.select(this)
}) })
$('#logs ul').append(file) $('#logs ul').append(file)
}) })
$('#logs').show() $('#logs').show()
Page_Distrubion.select() select()
} }
if (data.package.debs && data.package.debs.length > 0) { if (data.package.debs && data.package.debs.length > 0) {
...@@ -115,7 +126,7 @@ var Page_Distrubion = { ...@@ -115,7 +126,7 @@ var Page_Distrubion = {
} }
}, },
select: function(data) { select: function(data) {
Page_Distrubion.files.unselect() files.unselect()
if (! data) if (! data)
data = Utils.from_hash_to_data() data = Utils.from_hash_to_data()
if (Utils.check_data_file(data)) { if (Utils.check_data_file(data)) {
...@@ -125,13 +136,13 @@ var Page_Distrubion = { ...@@ -125,13 +136,13 @@ var Page_Distrubion = {
unselect: function() { unselect: function() {
$('#logs li').removeClass('active'); $('#logs li').removeClass('active');
} }
}, }
file: { var file = {
set: function(data) { set: function(data) {
$("#file pre").html(data.file.content) $("#file pre").html(data.file.content)
$("#file").show() $("#file").show()
Page_Distrubion.select() select()
}, },
clean: function() { clean: function() {
$('#file pre').html('') $('#file pre').html('')
...@@ -156,9 +167,9 @@ var Page_Distrubion = { ...@@ -156,9 +167,9 @@ var Page_Distrubion = {
socket.emit("get_file", new_data) socket.emit("get_file", new_data)
} }
} }
}, }
breadcrumb: { var breadcrumb = {
update: function(hash) { update: function(hash) {
if (! hash ) if (! hash )
hash = window.location.hash hash = window.location.hash
...@@ -176,10 +187,10 @@ var Page_Distrubion = { ...@@ -176,10 +187,10 @@ var Page_Distrubion = {
} }
$('.breadcrumb').html(new_html) $('.breadcrumb').html(new_html)
} }
}, }
// stiky sidebar // stiky sidebar
sticky: function() { var sticky = function() {
// $(window).off("scroll") // $(window).off("scroll")
// // back on top // // back on top
//// $("html, body").animate({scrollTop: 0}, 0); //// $("html, body").animate({scrollTop: 0}, 0);
...@@ -190,40 +201,40 @@ var Page_Distrubion = { ...@@ -190,40 +201,40 @@ var Page_Distrubion = {
// else // else
// $("#sticky").stop().removeClass('fixed'); // $("#sticky").stop().removeClass('fixed');
// }) // })
}, }
select: function(data) { var select = function(data) {
Page_Distrubion.unselect() unselect()
if (! data) if (! data)
data = Utils.from_hash_to_data() data = Utils.from_hash_to_data()
if (Utils.check_data_distribution(data)) { if (Utils.check_data_distribution(data)) {
$("#distributions li[id='distribution-" + data.distribution.name + "']").addClass('active') $("#distributions li[id='distribution-" + data.distribution.name + "']").addClass('active')
} }
Page_Distrubion.packages.select(data) packages.select(data)
Page_Distrubion.files.select(data) files.select(data)
}, }
unselect: function() { var unselect = function() {
$('#distributions li').removeClass('active') $('#distributions li').removeClass('active')
Page_Distrubion.files.unselect() files.unselect()
Page_Distrubion.packages.unselect() packages.unselect()
}, }
clean: function() { var clean = function() {
Page_Distrubion.title.clean() title.clean()
Page_Distrubion.packages.clean() packages.clean()
Page_Distrubion.files.clean() files.clean()
Page_Distrubion.file.clean() file.clean()
Page_Distrubion.unselect() unselect()
Page_Distrubion.breadcrumb.update() breadcrumb.update()
}, }
update: function(data, old_data) { var update = function(data, old_data) {
if (! old_data ) { if (! old_data ) {
if (! data ) if (! data )
Page_Distrubion.populate() populate()
else else
Page_Distrubion.populate(data) populate(data)
return; return;
} }
else { else {
...@@ -231,17 +242,17 @@ var Page_Distrubion = { ...@@ -231,17 +242,17 @@ var Page_Distrubion = {
! Utils.check_data_distribution(data) || ! Utils.check_data_distribution(data) ||
data.distribution.name != old_data.distribution.name) data.distribution.name != old_data.distribution.name)
{ {
Page_Distrubion.clean() clean()
Page_Distrubion.populate(data) populate(data)
} }
else if ( else if (
! Utils.check_data_package(old_data) || ! Utils.check_data_package(old_data) ||
! Utils.check_data_package(data) || ! Utils.check_data_package(data) ||
data.package.orig_name != old_data.package.orig_name ) data.package.orig_name != old_data.package.orig_name )
{ {
Page_Distrubion.file.clean() file.clean()
Page_Distrubion.files.clean() files.clean()
Page_Distrubion.files.get(data) files.get(data)
if (Utils.check_data_package(data)) { if (Utils.check_data_package(data)) {
// I will always get dataestamp from package // I will always get dataestamp from package
window.location.hash += '/datestamp' window.location.hash += '/datestamp'
...@@ -253,25 +264,59 @@ var Page_Distrubion = { ...@@ -253,25 +264,59 @@ var Page_Distrubion = {
data.file.name != old_data.file.name data.file.name != old_data.file.name
) )
{ {
Page_Distrubion.file.get() file.get()
} }
Page_Distrubion.title.set(data) title.set(data)
Page_Distrubion.breadcrumb.update() breadcrumb.update()
Page_Distrubion.select(data) select(data)
Page_Distrubion.sticky() sticky()
} }
}, }
populate: function (data) { var populate = function (data) {
Page_Distrubion.clean() clean()
if (! data ) if (! data )
data = Utils.from_hash_to_data() data = Utils.from_hash_to_data()
Page_Distrubion.packages.get(data) packages.get(data)
Page_Distrubion.files.get(data) files.get(data)
Page_Distrubion.file.get(data) file.get(data)
Page_Distrubion.select(data) select(data)
Page_Distrubion.breadcrumb.update() breadcrumb.update()
Page_Distrubion.title.set(data) title.set(data)
Page_Distrubion.sticky() sticky()
} }
this.init = function (mysocket) {
socket = mysocket
socket.on('distribution_packages', function(data){
packages.set(data)
})
socket.on('package_files_list', function(data){
files.set(data)
})
socket.on('file', function (data) {
file.set(data)
})
socket.on('file_newcontent', function(data) {
file.append(data)
})
$(window).on('hashchange', function() {
__check_hash_makes_sense()
new_data = Utils.from_hash_to_data()
update(new_data, data)
data = new_data
});
$(window).on('load', function (){
__check_hash_makes_sense()
populate(data)
});
}
} }
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