Commit c1643db6 authored by Leo Iannacone's avatar Leo Iannacone

better select functions and update split in update.page and update.view

parent 05352521
...@@ -45,7 +45,7 @@ function Page_Distrubion() ...@@ -45,7 +45,7 @@ function 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>')
}) })
select(data) select()
}, },
clean: function () { clean: function () {
...@@ -60,10 +60,8 @@ function Page_Distrubion() ...@@ -60,10 +60,8 @@ function Page_Distrubion()
socket.emit("get_distribution_packages", new_data) socket.emit("get_distribution_packages", new_data)
} }
}, },
select: function(data) { select: function() {
packages.unselect() packages.unselect()
if (! data)
data = Utils.from_hash_to_data()
if (Utils.check_data_package(data)) { if (Utils.check_data_package(data)) {
$("#packages li[id='package-"+ data.package.orig_name + "']").addClass('active') $("#packages li[id='package-"+ data.package.orig_name + "']").addClass('active')
} }
...@@ -125,10 +123,8 @@ function Page_Distrubion() ...@@ -125,10 +123,8 @@ function Page_Distrubion()
socket.emit("get_package_files_list", new_data) socket.emit("get_package_files_list", new_data)
} }
}, },
select: function(data) { select: function() {
files.unselect() files.unselect()
if (! data)
data = Utils.from_hash_to_data()
if (Utils.check_data_file(data)) { if (Utils.check_data_file(data)) {
$("#logs li[id='file-" + data.file.orig_name + "']").addClass('active') $("#logs li[id='file-" + data.file.orig_name + "']").addClass('active')
} }
...@@ -203,15 +199,13 @@ function Page_Distrubion() ...@@ -203,15 +199,13 @@ function Page_Distrubion()
// }) // })
} }
var select = function(data) { var select = function() {
unselect() unselect()
if (! 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')
} }
packages.select(data) packages.select()
files.select(data) files.select()
} }
var unselect = function() { var unselect = function() {
...@@ -228,51 +222,59 @@ function Page_Distrubion() ...@@ -228,51 +222,59 @@ function Page_Distrubion()
unselect() unselect()
breadcrumb.update() breadcrumb.update()
} }
var update = function(data, old_data) { var update = {
if (! old_data ) { page: function(data, old_data) {
if (! data ) if (! old_data ) {
populate() if (! data )
else populate()
populate(data) else
return; populate(data)
} return;
else {
if (! Utils.check_data_distribution(old_data) ||
! Utils.check_data_distribution(data) ||
data.distribution.name != old_data.distribution.name)
{
clean()
populate(data)
} }
else if ( else {
! Utils.check_data_package(old_data) || if (! Utils.check_data_distribution(old_data) ||
! Utils.check_data_package(data) || ! Utils.check_data_distribution(data) ||
data.package.orig_name != old_data.package.orig_name ) data.distribution.name != old_data.distribution.name)
{ {
file.clean() clean()
files.clean() populate(data)
files.get(data) return
if (Utils.check_data_package(data)) {
// I will always get dataestamp from package
window.location.hash += '/datestamp'
} }
else if (
! Utils.check_data_package(old_data) ||
! Utils.check_data_package(data) ||
data.package.orig_name != old_data.package.orig_name )
{
file.clean()
files.clean()
files.get(data)
if (Utils.check_data_package(data)) {
// I will always get dataestamp from package
window.location.hash += '/datestamp'
}
}
else if (
! Utils.check_data_file(old_data) ||
! Utils.check_data_file(data) ||
data.file.name != old_data.file.name
)
{
file.get()
}
update.view(data)
} }
else if ( },
! Utils.check_data_file(old_data) || view : function(data) {
! Utils.check_data_file(data) || if (! data )
data.file.name != old_data.file.name data = Utils.from_hash_to_data()
)
{
file.get()
}
title.set(data) title.set(data)
breadcrumb.update() breadcrumb.update()
select(data) select()
sticky() sticky()
} }
} }
var populate = function (data) { var populate = function (data) {
clean() clean()
if (! data ) if (! data )
...@@ -280,37 +282,34 @@ function Page_Distrubion() ...@@ -280,37 +282,34 @@ function Page_Distrubion()
packages.get(data) packages.get(data)
files.get(data) files.get(data)
file.get(data) file.get(data)
select(data) update.view(data)
breadcrumb.update()
title.set(data)
sticky()
} }
this.init = function (mysocket) { this.init = function (mysocket) {
socket = mysocket socket = mysocket
socket.on('distribution_packages', function(data){ socket.on('distribution_packages', function(socket_data){
packages.set(data) packages.set(socket_data)
}) })
socket.on('package_files_list', function(data){ socket.on('package_files_list', function(socket_data){
files.set(data) files.set(socket_data)
}) })
socket.on('file', function (data) { socket.on('file', function (socket_data) {
file.set(data) file.set(socket_data)
}) })
socket.on('file_newcontent', function(data) { socket.on('file_newcontent', function(socket_data) {
file.append(data) file.append(socket_data)
}) })
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
__check_hash_makes_sense() __check_hash_makes_sense()
new_data = Utils.from_hash_to_data() var old_data = data
update(new_data, data) data = Utils.from_hash_to_data()
data = new_data update.page(data, old_data)
}); });
$(window).on('load', function (){ $(window).on('load', function (){
......
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