Commit 3fb306f7 authored by Leo Iannacone's avatar Leo Iannacone

renamed variable data to view - refactored utils as well

parent d25f6fb6
...@@ -2,7 +2,7 @@ function Page_Distrubion(socket) ...@@ -2,7 +2,7 @@ function Page_Distrubion(socket)
{ {
var socket = socket var socket = socket
var events = config.events.client var events = config.events.client
var data = Utils.from_hash_to_data() var view = Utils.from_hash_to_view()
var sidebarOffset = 0 var sidebarOffset = 0
var new_lines = [] var new_lines = []
...@@ -17,19 +17,19 @@ function Page_Distrubion(socket) ...@@ -17,19 +17,19 @@ function Page_Distrubion(socket)
var title = { var title = {
set: function() { set: function() {
var label = '' var label = ''
if (Utils.check_data_file(data)) { if (Utils.check_view_file(view)) {
var complete_name = data.package.orig_name + '.' + data.file.name var complete_name = view.package.orig_name + '.' + view.file.name
if (! data.file.path) if (! view.file.path)
data.file.path = config.paths.debomatic + '/' + data.distribution.name + '/pool/' + data.package.orig_name + '/' + complete_name view.file.path = config.paths.debomatic + '/' + view.distribution.name + '/pool/' + view.package.orig_name + '/' + complete_name
label = complete_name + ' \ label = complete_name + ' \
<a class="btn btn-link btn-lg" title="Download" href="' + data.file.path + '">\ <a class="btn btn-link btn-lg" title="Download" href="' + view.file.path + '">\
<span class="glyphicon glyphicon-download-alt"></span>\ <span class="glyphicon glyphicon-download-alt"></span>\
</a>' </a>'
} }
else if (Utils.check_data_package(data)) else if (Utils.check_view_package(view))
label = data.package.orig_name label = view.package.orig_name
else if (Utils.check_data_distribution(data)) else if (Utils.check_view_distribution(view))
label = data.distribution.name label = view.distribution.name
$('#title').html(label) $('#title').html(label)
}, },
clean: function() { clean: function() {
...@@ -45,8 +45,8 @@ function Page_Distrubion(socket) ...@@ -45,8 +45,8 @@ function Page_Distrubion(socket)
socket_data.distribution.packages.forEach(function(p){ socket_data.distribution.packages.forEach(function(p){
tmp.package = p tmp.package = p
// get datestamp if package is clicked // get datestamp if package is clicked
$('#packages ul').append('<li id="package-' + p.orig_name + '"><a href="' + Utils.from_data_to_hash(tmp) + '/datestamp">'+ p.name + ' <span>'+p.version+'</span></a></li>') $('#packages ul').append('<li id="package-' + p.orig_name + '"><a href="' + Utils.from_view_to_hash(tmp) + '/datestamp">'+ p.name + ' <span>'+p.version+'</span></a></li>')
data.packages view.packages
}) })
packages.select() packages.select()
}, },
...@@ -55,16 +55,16 @@ function Page_Distrubion(socket) ...@@ -55,16 +55,16 @@ function Page_Distrubion(socket)
$('#packages ul').html('') $('#packages ul').html('')
}, },
get: function () { get: function () {
if (Utils.check_data_distribution(data)) { if (Utils.check_view_distribution(view)) {
var new_data = {} var query_data = {}
new_data.distribution = data.distribution query_data.distribution = view.distribution
socket.emit(events.distribution_packages.get, new_data) socket.emit(events.distribution_packages.get, query_data)
} }
}, },
select: function() { select: function() {
packages.unselect() packages.unselect()
if (Utils.check_data_package(data)) { if (Utils.check_view_package(view)) {
$("#packages li[id='package-"+ data.package.orig_name + "']").addClass('active') $("#packages li[id='package-"+ view.package.orig_name + "']").addClass('active')
} }
}, },
unselect: function() { unselect: function() {
...@@ -74,12 +74,12 @@ function Page_Distrubion(socket) ...@@ -74,12 +74,12 @@ function Page_Distrubion(socket)
var p_html = $("#packages li[id='package-"+ status_data.package + "'] a") var p_html = $("#packages li[id='package-"+ status_data.package + "'] a")
p_html.find('span.icon').remove() p_html.find('span.icon').remove()
p_html.html(p_html.html() + ' ' + Utils.get_status_icon_html(status_data)) p_html.html(p_html.html() + ' ' + Utils.get_status_icon_html(status_data))
if (Utils.check_data_package(data) if (Utils.check_view_package(view)
&& data.package.orig_name == status_data.package && view.package.orig_name == status_data.package
&& data.distribution.name == status_data.distribution) && view.distribution.name == status_data.distribution)
{ {
console.log(status_data) console.log(status_data)
data.package.status = status_data.status view.package.status = status_data.status
} }
} }
} }
...@@ -89,10 +89,10 @@ function Page_Distrubion(socket) ...@@ -89,10 +89,10 @@ function Page_Distrubion(socket)
files.clean() files.clean()
var tmp = socket_data var tmp = socket_data
if (socket_data.package.files && socket_data.package.files.length > 0) { if (socket_data.package.files && socket_data.package.files.length > 0) {
selected_file = Utils.check_data_file(socket_data) selected_file = Utils.check_view_file(socket_data)
socket_data.package.files.forEach(function(f){ socket_data.package.files.forEach(function(f){
tmp.file = f tmp.file = f
var html_file = $('<li id="file-'+ f.orig_name +'"><a title="'+ f.orig_name +'" href="'+ Utils.from_data_to_hash(tmp) + '">' + f.name + '</a></li>') var html_file = $('<li id="file-'+ f.orig_name +'"><a title="'+ f.orig_name +'" href="'+ Utils.from_view_to_hash(tmp) + '">' + f.name + '</a></li>')
html_file.on("click", function(){ html_file.on("click", function(){
files.select(this) files.select(this)
}) })
...@@ -127,17 +127,17 @@ function Page_Distrubion(socket) ...@@ -127,17 +127,17 @@ function Page_Distrubion(socket)
$('#files').hide() $('#files').hide()
}, },
get: function () { get: function () {
if (Utils.check_data_package(data)) { if (Utils.check_view_package(view)) {
var new_data = {} var query_data = {}
new_data.distribution = data.distribution query_data.distribution = view.distribution
new_data.package = data.package query_data.package = view.package
socket.emit(events.package_files_list.get, new_data) socket.emit(events.package_files_list.get, query_data)
} }
}, },
select: function() { select: function() {
files.unselect() files.unselect()
if (Utils.check_data_file(data)) { if (Utils.check_view_file(view)) {
$("#logs li[id='file-" + data.file.orig_name + "']").addClass('active') $("#logs li[id='file-" + view.file.orig_name + "']").addClass('active')
} }
}, },
unselect: function() { unselect: function() {
...@@ -169,13 +169,13 @@ function Page_Distrubion(socket) ...@@ -169,13 +169,13 @@ function Page_Distrubion(socket)
} }
}, },
get: function() { get: function() {
if (Utils.check_data_file(data)) { if (Utils.check_view_file(view)) {
var new_data = {} var query_data = {}
new_data.distribution = data.distribution query_data.distribution = view.distribution
new_data.package = data.package query_data.package = view.package
new_data.file = data.file query_data.file = view.file
new_data.file.content = null query_data.file.content = null
socket.emit(events.file.get, new_data) socket.emit(events.file.get, query_data)
} }
} }
} }
...@@ -234,22 +234,22 @@ function Page_Distrubion(socket) ...@@ -234,22 +234,22 @@ function Page_Distrubion(socket)
update: function() { update: function() {
var sidebar = $("#files") var sidebar = $("#files")
sidebarOffset = sidebar.offset().top sidebarOffset = sidebar.offset().top
if (Utils.check_data_distribution(data)) if (Utils.check_view_distribution(view))
$("#sticky-view .distribution").html(data.distribution.name) $("#sticky-view .distribution").html(view.distribution.name)
if (Utils.check_data_package(data)) { if (Utils.check_view_package(view)) {
$("#sticky-view .name").html(data.package.name) $("#sticky-view .name").html(view.package.name)
$("#sticky-view .version").html(data.package.version) $("#sticky-view .version").html(view.package.version)
var status_data = {} var status_data = {}
status_data.distribution = data.distribution.name status_data.distribution = view.distribution.name
status_data.package = data.package.orig_name status_data.package = view.package.orig_name
status_data.status = data.package.status status_data.status = view.package.status
sticky.set_status(status_data) sticky.set_status(status_data)
} }
}, },
set_status: function(status_data) { set_status: function(status_data) {
if ( Utils.check_data_package(data) if ( Utils.check_view_package(view)
&& status_data.distribution == data.distribution.name && status_data.distribution == view.distribution.name
&& status_data.package == data.package.orig_name) && status_data.package == view.package.orig_name)
{ {
var info = Utils.get_status_icon_and_class(status_data) var info = Utils.get_status_icon_and_class(status_data)
var panel = $("#sticky-view") var panel = $("#sticky-view")
...@@ -264,8 +264,8 @@ function Page_Distrubion(socket) ...@@ -264,8 +264,8 @@ function Page_Distrubion(socket)
var select = function() { var select = function() {
unselect() unselect()
if (Utils.check_data_distribution(data)) { if (Utils.check_view_distribution(view)) {
$("#distributions li[id='distribution-" + data.distribution.name + "']").addClass('active') $("#distributions li[id='distribution-" + view.distribution.name + "']").addClass('active')
} }
packages.select() packages.select()
files.select() files.select()
...@@ -287,19 +287,19 @@ function Page_Distrubion(socket) ...@@ -287,19 +287,19 @@ function Page_Distrubion(socket)
} }
var update = { var update = {
page: function(old_data) { page: function(old_view) {
if ( ! old_data if ( ! old_view
|| ! Utils.check_data_distribution(old_data) || ! Utils.check_view_distribution(old_view)
|| ! Utils.check_data_distribution(data) || ! Utils.check_view_distribution(view)
|| data.distribution.name != old_data.distribution.name || view.distribution.name != old_view.distribution.name
) )
{ // new distribution view { // new distribution view
populate() populate()
return return
} }
else if ( ! Utils.check_data_package(old_data) else if ( ! Utils.check_view_package(old_view)
|| ! Utils.check_data_package(data) || ! Utils.check_view_package(view)
|| data.package.orig_name != old_data.package.orig_name || view.package.orig_name != old_view.package.orig_name
) )
{ // new pacakge view { // new pacakge view
files.get() files.get()
...@@ -307,14 +307,14 @@ function Page_Distrubion(socket) ...@@ -307,14 +307,14 @@ function Page_Distrubion(socket)
file.clean() file.clean()
file.get() file.get()
} }
else if ( ! Utils.check_data_file(old_data) else if ( ! Utils.check_view_file(old_view)
|| ! Utils.check_data_file(data) || ! Utils.check_view_file(view)
|| data.file.name != old_data.file.name || view.file.name != old_view.file.name
) )
{ // new file view { // new file view
file.get() file.get()
} }
update.view(data) update.view(view)
}, },
view : function() { view : function() {
title.set() title.set()
...@@ -341,7 +341,7 @@ function Page_Distrubion(socket) ...@@ -341,7 +341,7 @@ function Page_Distrubion(socket)
socket.on(events.distribution_packages.status, function (socket_data){ socket.on(events.distribution_packages.status, function (socket_data){
packages.set_status(socket_data) packages.set_status(socket_data)
// FIX_ME - qui ricevo tutti gli stati mentre sto sempre sulla stessa view!! // FIX_ME - qui ricevo tutti gli stati mentre sto sempre sulla stessa view!!
// refactory rename data -> view // refactory rename view -> view
// view.packages = {} -> key = package.orig_name // view.packages = {} -> key = package.orig_name
// view.file // view.file
// ...... // ......
...@@ -368,9 +368,9 @@ function Page_Distrubion(socket) ...@@ -368,9 +368,9 @@ function Page_Distrubion(socket)
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
__check_hash_makes_sense() __check_hash_makes_sense()
var old_data = data var old_view = view
data = Utils.from_hash_to_data() view = Utils.from_hash_to_view()
update.page(old_data) update.page(old_view)
$('html').animate({scrollTop: 0}, 0); $('html').animate({scrollTop: 0}, 0);
}); });
......
...@@ -33,8 +33,8 @@ function Page_Generic() ...@@ -33,8 +33,8 @@ function Page_Generic()
$('#distributions ul').append('<li id="distribution-' + name +'"><a href="'+ config.paths.distribution + '#'+ name + '">' + name + '</li>'); $('#distributions ul').append('<li id="distribution-' + name +'"><a href="'+ config.paths.distribution + '#'+ name + '">' + name + '</li>');
}); });
if (window.location.pathname == config.paths.distribution) { if (window.location.pathname == config.paths.distribution) {
data = Utils.from_hash_to_data() var data = Utils.from_hash_to_view()
if (Utils.check_data_distribution(data)) { if (Utils.check_view_distribution(data)) {
$("#distributions li[id='distribution-" + data.distribution.name + "']").addClass('active') $("#distributions li[id='distribution-" + data.distribution.name + "']").addClass('active')
} }
} }
...@@ -98,7 +98,7 @@ function Page_Generic() ...@@ -98,7 +98,7 @@ function Page_Generic()
distributions.set(socket_distributions) distributions.set(socket_distributions)
}); });
socket.on('error', function(data) { consol_e.error(data) }); socket.on('error', function(socket_data_error) { console.error(socket_data_error) });
socket.on(_e.client.status, function(packages_status) { socket.on(_e.client.status, function(packages_status) {
status.set(packages_status) status.set(packages_status)
......
var Utils = { var Utils = {
from_hash_to_data: function (hash) { from_hash_to_view: function (hash) {
if (! hash ) if (! hash )
hash = window.location.hash hash = window.location.hash
hash = hash.replace('#', '') hash = hash.replace('#', '')
info = hash.split('/'); info = hash.split('/');
data = {} var view = {}
if (info.length >= 1) { if (info.length >= 1) {
data.distribution = {} view.distribution = {}
data.distribution.name = info[0]; view.distribution.name = info[0];
} }
if (info.length >= 3){ if (info.length >= 3){
data.package = {} view.package = {}
data.package.name = info[1]; view.package.name = info[1];
data.package.version = info[2]; view.package.version = info[2];
data.package.orig_name = data.package.name + '_' + data.package.version view.package.orig_name = view.package.name + '_' + view.package.version
} }
if (info.length >= 4) { if (info.length >= 4) {
data.file = {} view.file = {}
data.file.name = info[3] view.file.name = info[3]
data.file.orig_name = data.package.orig_name + '.' + data.file.name view.file.orig_name = view.package.orig_name + '.' + view.file.name
} }
return data return view
}, },
from_data_to_hash: function (data) { from_view_to_hash: function (view) {
hash = "#" hash = "#"
if (Utils.check_data_distribution(data)) { if (Utils.check_view_distribution(view)) {
hash = hash + data.distribution.name hash = hash + view.distribution.name
if (Utils.check_data_package(data)) { if (Utils.check_view_package(view)) {
hash = hash + '/' + data.package.name + "/" + data.package.version hash = hash + '/' + view.package.name + "/" + view.package.version
if (Utils.check_data_file(data)) if (Utils.check_view_file(view))
hash = hash + '/' + data.file.name hash = hash + '/' + view.file.name
} }
} }
return hash return hash
}, },
check_data_distribution: function(data) { check_view_distribution: function(view) {
return data && data.distribution && data.distribution.name return view && view.distribution && view.distribution.name
}, },
check_data_package: function(data) { check_view_package: function(view) {
return Utils.check_data_distribution(data) && data.package && data.package.name && data.package.version && data.package.orig_name return Utils.check_view_distribution(view) && view.package && view.package.name && view.package.version && view.package.orig_name
}, },
check_data_file: function(data) { check_view_file: function(view) {
return Utils.check_data_package(data) && data.file && data.file.name return Utils.check_view_package(view) && view.file && view.file.name
}, },
get_status_icon_and_class: function (status_data) { get_status_icon_and_class: function (status_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