From d257c974a8acea9d7309b63c829fefcbfb47d831 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 20 Aug 2009 15:55:48 +0200 Subject: dynamic status bar --- module/web/WebServer.py | 36 +++++++++++++- module/web/static/default/home.js | 2 +- module/web/static/default/status.js | 93 +++++++++++++++++++++++++------------ module/web/templates/default.tpl | 14 ++++-- module/web/templates/window.tpl | 2 +- 5 files changed, 108 insertions(+), 39 deletions(-) (limited to 'module/web') diff --git a/module/web/WebServer.py b/module/web/WebServer.py index 5885ab2de..074ab4242 100644 --- a/module/web/WebServer.py +++ b/module/web/WebServer.py @@ -146,8 +146,6 @@ def get_links(): downloads = core.get_downloads() - - for dl in downloads: json += '{' json += '"id": "%s", "name": "%s", "speed": "%s", "eta": "%s", "kbleft": "%s", "size": "%s", "percent": "%s", "wait": "%s", "status": "%s"'\ @@ -160,6 +158,40 @@ def get_links(): json += "] }" return json +@route('/json/status') +def get_status(): + response.header['Cache-Control'] = 'no-cache, must-revalidate' + response.content_type = 'application/json' + + if not check_auth(request): + abort(404, "No Access") + + data = core.server_status() + + if data['pause']: + status = "paused" + else: + status = "running" + + json = '{ "status": "%s", "speed": "%s", "queue": "%s" }' % (status, str(int(data['speed'])), str(data['queue'])) + + return json + +@route('/json/addlinks', method='POST') +def add_links(): + response.header['Cache-Control'] = 'no-cache, must-revalidate' + response.content_type = 'application/json' + + if not check_auth(request): + abort(404, "No Access") + + links = request.POST['links'].split('\n') + + core.add_links(links) + + return "{}" + + @route('/favicon.ico') def favicon(): diff --git a/module/web/static/default/home.js b/module/web/static/default/home.js index 9f8902458..065a6d6eb 100644 --- a/module/web/static/default/home.js +++ b/module/web/static/default/home.js @@ -88,7 +88,7 @@ pb = new dwProgressBar({ }); */ -req.startTimer(); + req.startTimer(); }); diff --git a/module/web/static/default/status.js b/module/web/static/default/status.js index c211fc669..f3d521e45 100644 --- a/module/web/static/default/status.js +++ b/module/web/static/default/status.js @@ -1,51 +1,84 @@ /* hover! */ Element.implement({ - 'hover': function(fn1,fn2) { - return this.addEvents({ - 'mouseenter': function(e) { - fn1.attempt(e,this); - }, - 'mouseleave': function(e) { - fn2.attempt(e,this); - } - }) - } + 'hover': function(fn1,fn2) { + return this.addEvents({ + 'mouseenter': function(e) { + fn1.attempt(e,this); + }, + 'mouseleave': function(e) { + fn2.attempt(e,this); + } + }) + } }); +function updateStatus(data){ + + document.id("status").textContent = "Status: "+ data.status; + document.id("speed").textContent = "Speed: "+ data.speed +" kb/s"; + document.id("queue").textContent = "Files in queue: "+ data.queue; + +} + + +status_req = new Request.JSON({ + onSuccess: updateStatus, + method: 'get', + url: '/json/status', + initialDelay: 0, + delay: 2000, + limit: 20000 +}); window.addEvent('domready', function(){ -$$('.statusbutton').each(function(item){ + status_req.startTimer(); - item.hover(function(e){ - this.tween('opacity',1) - },function(e){ - this.tween('opacity',0.01) - } -) -}) -fx_reveal = new Fx.Reveal($('addlinks')); -//fx_reveal.dissolve() + document.id("btAdd").addEvent("click", function(e){ + new Request({ + method: 'post', + url: '/json/addlinks', + onSuccess: function(){ + document.id('linkarea').value = "" + } + }).send('links='+document.id('linkarea').value) -$$('#addlinks .closeSticky').each(function(el){ -el.addEvent('click',function(e){ + }) -fx_reveal.dissolve(); + $$('.statusbutton').each(function(item){ -}); + item.hover(function(e){ + this.tween('opacity',1) + },function(e){ + this.tween('opacity',0.01) + } + ) + }) -}); + fx_reveal = new Fx.Reveal($('addlinks')); + //fx_reveal.dissolve() -$$('.statusbutton')[2].addEvent('click',function(e){ -$('addlinks').setStyle('top', e.page.y + 5) -$('addlinks').setStyle('left', e.page.x + 5) + $$('#addlinks .closeSticky').each(function(el){ -fx_reveal.reveal() + el.addEvent('click',function(e){ -}); + fx_reveal.dissolve(); + + }); + + }); + + $$('.statusbutton')[2].addEvent('click',function(e){ + + $('addlinks').setStyle('top', e.page.y + 5) + $('addlinks').setStyle('left', e.page.x + 5) + + fx_reveal.reveal() + + }); }); \ No newline at end of file diff --git a/module/web/templates/default.tpl b/module/web/templates/default.tpl index fe617bfe6..2508455cb 100644 --- a/module/web/templates/default.tpl +++ b/module/web/templates/default.tpl @@ -11,7 +11,7 @@ %include header title=header, use_js=js, use_css=['default.css','window.css'], redirect=red -%include window id="addlinks", width=400, caption="Add links", body="", button="Add" +%include window id="addlinks", width=400, caption="Add links", body="", button="Add" @@ -76,11 +76,15 @@ %if page != "loggedin" and page != "login":
-
-Status: running +
+Status:
-
-Speed: 500 kb/s   +
+Speed:  +
+ +
+Files in queue: 
diff --git a/module/web/templates/window.tpl b/module/web/templates/window.tpl index fce3cb86f..f756c4352 100644 --- a/module/web/templates/window.tpl +++ b/module/web/templates/window.tpl @@ -12,7 +12,7 @@ -- cgit v1.2.3