some hacks for webui (was hack for ticket #2358)

Discussion of the Web Interface for Transmission, formerly known as Clutch. This applies to all version of Transmission
Post Reply
roger21
Posts: 3
Joined: Wed Oct 14, 2009 8:03 pm

some hacks for webui (was hack for ticket #2358)

Post by roger21 »

hi,

some modifications for webui:

1 - added information for downloads (based on uploads format which don't change) and keep the information in case of error:
before:
Image
Image
Image
after :
Image
Image
Image

2 - added sort by up speed, dl speed and ratio (yes, it's redondent with activity but still useful)
before :
Image
after :
Image (damn alpha chanel!)

3 - ticket #2358 : avoid the contextual menu to go outside the screen
(no picture it's clear enougth ;))

diff :

Code: Select all

diff -cr web_1.75/index.html web/index.html
*** web_1.75/index.html	2009-10-18 19:35:55.000000000 +0200
--- web/index.html	2009-10-18 13:09:44.000000000 +0200
***************
*** 337,342 ****
--- 337,345 ----
  						<li>Sort Transfers By
  							<ul id="footer_sort_menu">
  								<li id="sort_by_activity">Activity</li>
+ 								<li id="sort_by_download_speed">Download Speed</li>
+ 								<li id="sort_by_upload_speed">Upload Speed</li>
+ 								<li id="sort_by_ratio">Ratio</li>
  								<li id="sort_by_age">Age</li>
  								<li id="sort_by_name">Name</li>
  								<li id="sort_by_percent_completed">Progress</li>
diff -cr web_1.75/javascript/common.js web/javascript/common.js
*** web_1.75/javascript/common.js	2009-10-18 19:35:55.000000000 +0200
--- web/javascript/common.js	2009-10-18 19:34:04.000000000 +0200
***************
*** 281,286 ****
--- 281,289 ----
  Prefs._SortMethod         = 'sort_method';
  Prefs._SortByAge          = 'age';
  Prefs._SortByActivity     = 'activity';
+ Prefs._SortByDownloadSpeed= 'download_speed';
+ Prefs._SortByUploadSpeed  = 'upload_speed';
+ Prefs._SortByRatio        = 'ratio';
  Prefs._SortByQueue        = 'queue_order';
  Prefs._SortByName         = 'name';
  Prefs._SortByProgress     = 'percent_completed';
diff -cr web_1.75/javascript/jquery/jquery.contextmenu.min.js web/javascript/jquery/jquery.contextmenu.min.js
*** web_1.75/javascript/jquery/jquery.contextmenu.min.js	2009-10-18 19:35:55.000000000 +0200
--- web/javascript/jquery/jquery.contextmenu.min.js	2009-10-18 19:43:44.000000000 +0200
***************
*** 1,7 ****
  
  (function($){var menu,shadow,trigger,content,hash,currentTarget;var defaults={menuStyle:{listStyle:'none',padding:'1px',margin:'0px',backgroundColor:'#fff',border:'1px solid #999',width:'100px'},itemStyle:{margin:'0px',color:'#000',display:'block',cursor:'default',padding:'3px',border:'1px solid #fff',backgroundColor:'transparent'},itemHoverStyle:{border:'1px solid #0a246a',backgroundColor:'#b6bdd2'},eventPosX:'pageX',eventPosY:'pageY',shadow:true,onContextMenu:null,onShowMenu:null};$.fn.contextMenu=function(id,options){if(!menu){menu=$('<div id="jqContextMenu"></div>').hide().css({position:'absolute',zIndex:'500'}).appendTo('body').bind('click',function(e){e.stopPropagation();});}
  if(!shadow){shadow=$('<div></div>').css({backgroundColor:'#000',position:'absolute',opacity:0.2,zIndex:499}).appendTo('body').hide();}
! hash=hash||[];hash.push({id:id,menuStyle:$.extend({},defaults.menuStyle,options.menuStyle||{}),itemStyle:$.extend({},defaults.itemStyle,options.itemStyle||{}),itemHoverStyle:$.extend({},defaults.itemHoverStyle,options.itemHoverStyle||{}),bindings:options.bindings||{},shadow:options.shadow||options.shadow===false?options.shadow:defaults.shadow,onContextMenu:options.onContextMenu||defaults.onContextMenu,onShowMenu:options.onShowMenu||defaults.onShowMenu,eventPosX:options.eventPosX||defaults.eventPosX,eventPosY:options.eventPosY||defaults.eventPosY});var index=hash.length-1;$(this).bind('contextmenu',function(e){var bShowContext=(!!hash[index].onContextMenu)?hash[index].onContextMenu(e):true;if(bShowContext)display(index,this,e,options);return false;});return this;};function display(index,trigger,e,options){var cur=hash[index];content=$('#'+cur.id).find('ul:first').clone(true);content.css(cur.menuStyle).find('li').css(cur.itemStyle).hover(function(){$(this).css(cur.itemHoverStyle);},function(){$(this).css(cur.itemStyle);}).find('img').css({verticalAlign:'middle',paddingRight:'2px'});menu.html(content);if(!!cur.onShowMenu)menu=cur.onShowMenu(e,menu);$.each(cur.bindings,function(id,func){$('#'+id,menu).bind('click',function(e){hide();func(trigger,currentTarget);});});menu.css({'left':e[cur.eventPosX],'top':e[cur.eventPosY]}).show();if(cur.shadow)shadow.css({width:menu.width(),height:menu.height(),left:e.pageX+2,top:e.pageY+2}).show();$(document).one('click',hide);}
  function hide(){menu.hide();shadow.hide();}
  $.contextMenu={defaults:function(userDefaults){$.each(userDefaults,function(i,val){if(typeof val=='object'&&defaults[i]){$.extend(defaults[i],val);}
! else defaults[i]=val;});}};})(jQuery);$(function(){$('div.contextMenu').hide();});
\ No newline at end of file
--- 1,38 ----
  
  (function($){var menu,shadow,trigger,content,hash,currentTarget;var defaults={menuStyle:{listStyle:'none',padding:'1px',margin:'0px',backgroundColor:'#fff',border:'1px solid #999',width:'100px'},itemStyle:{margin:'0px',color:'#000',display:'block',cursor:'default',padding:'3px',border:'1px solid #fff',backgroundColor:'transparent'},itemHoverStyle:{border:'1px solid #0a246a',backgroundColor:'#b6bdd2'},eventPosX:'pageX',eventPosY:'pageY',shadow:true,onContextMenu:null,onShowMenu:null};$.fn.contextMenu=function(id,options){if(!menu){menu=$('<div id="jqContextMenu"></div>').hide().css({position:'absolute',zIndex:'500'}).appendTo('body').bind('click',function(e){e.stopPropagation();});}
  if(!shadow){shadow=$('<div></div>').css({backgroundColor:'#000',position:'absolute',opacity:0.2,zIndex:499}).appendTo('body').hide();}
! hash=hash||[];hash.push({id:id,menuStyle:$.extend({},defaults.menuStyle,options.menuStyle||{}),itemStyle:$.extend({},defaults.itemStyle,options.itemStyle||{}),itemHoverStyle:$.extend({},defaults.itemHoverStyle,options.itemHoverStyle||{}),bindings:options.bindings||{},shadow:options.shadow||options.shadow===false?options.shadow:defaults.shadow,onContextMenu:options.onContextMenu||defaults.onContextMenu,onShowMenu:options.onShowMenu||defaults.onShowMenu,eventPosX:options.eventPosX||defaults.eventPosX,eventPosY:options.eventPosY||defaults.eventPosY});var index=hash.length-1;$(this).bind('contextmenu',function(e){var bShowContext=(!!hash[index].onContextMenu)?hash[index].onContextMenu(e):true;if(bShowContext)display(index,this,e,options);return false;});return this;};function display(index,trigger,e,options){var cur=hash[index];content=$('#'+cur.id).find('ul:first').clone(true);content.css(cur.menuStyle).find('li').css(cur.itemStyle).hover(function(){$(this).css(cur.itemHoverStyle);},function(){$(this).css(cur.itemStyle);}).find('img').css({verticalAlign:'middle',paddingRight:'2px'});menu.html(content);if(!!cur.onShowMenu)menu=cur.onShowMenu(e,menu);$.each(cur.bindings,function(id,func){$('#'+id,menu).bind('click',function(e){hide();func(trigger,currentTarget);});});
! 
! var __posX;
! var __posY;
! 
! var __docW=document.documentElement.clientWidth;
! var __docH=document.documentElement.clientHeight;
! 
! var __menuW=menu.width() + 2; // 2 for border in regards of the css
! var __menuH=menu.height() + 2; // 2 for border in regards of the css
! 
! if (e[cur.eventPosX] + __menuW > __docW) {
!   if (__docW - __menuW > 0) {
!     __posX=__docW - __menuW;
!   } else {
!     __posX=0;
!   }
! } else {
!   __posX=e[cur.eventPosX];
! }
! 
! if (e[cur.eventPosY] + __menuH > __docH) {
!   if (__docH - __menuH > 0) {
!     __posY=__docH - __menuH;
!   } else {
!     __posY=0;
!   }
! } else {
!   __posY=e[cur.eventPosY];
! }
! 
! menu.css({'left':__posX,'top':__posY}).show();if(cur.shadow)shadow.css({width:menu.width(),height:menu.height(),left:e.pageX+2,top:e.pageY+2}).show();$(document).one('click',hide);}
  function hide(){menu.hide();shadow.hide();}
  $.contextMenu={defaults:function(userDefaults){$.each(userDefaults,function(i,val){if(typeof val=='object'&&defaults[i]){$.extend(defaults[i],val);}
! else defaults[i]=val;});}};})(jQuery);$(function(){$('div.contextMenu').hide();});
diff -cr web_1.75/javascript/torrent.js web/javascript/torrent.js
*** web_1.75/javascript/torrent.js	2009-10-18 19:35:55.000000000 +0200
--- web/javascript/torrent.js	2009-10-18 20:22:18.000000000 +0200
***************
*** 192,197 ****
--- 192,198 ----
  		return Math.floor(100 * Math.ratio( 100 * ( this._sizeWhenDone - this._leftUntilDone ),
  		                           this._sizeWhenDone )) / 100;
  	},
+ 	ratio: function() { return this._upload_ratio; },
  	size: function() { return this._size; },
  	state: function() { return this._state; },
  	stateStr: function() {
***************
*** 367,389 ****
  	{
  		var c;
  
! 		if(( c = this.getErrorMessage( )))
! 			return c;
  
  		var st = this.state( );
  		switch( st )
  		{
  			case Torrent._StatusPaused:
  			case Torrent._StatusWaitingToCheck:
! 				c = this.stateStr( );
  				break;
  
  			case Torrent._StatusDownloading:
! 				// 'Downloading from 36 of 40 peers - DL: 60.2 KB/s UL: 4.3 KB/s'
! 				c = 'Downloading from ';
  				c += this.peersSendingToUs();
  				c += ' of ';
  				c += this._peers_connected;
  				c += ' peers - DL: ';
  				c += Math.formatBytes(this._download_speed);
  				c += '/s UL: ';
--- 368,396 ----
  	{
  		var c;
  
! 		if((c = this.getErrorMessage( )))
! 			c += " - ";
! 		else
! 			c = "";
  
  		var st = this.state( );
  		switch( st )
  		{
  			case Torrent._StatusPaused:
  			case Torrent._StatusWaitingToCheck:
! 				c += this.stateStr( );
  				break;
  
  			case Torrent._StatusDownloading:
! 				// 'Downloading from 36 of 40 peers - Seeding to 13 of 22 peers - DL: 60.2 KB/s UL: 4.3 KB/s'
! 				c += 'Downloading from ';
  				c += this.peersSendingToUs();
  				c += ' of ';
  				c += this._peers_connected;
+ 				c += ' peers - Seeding to ';
+ 				c += this.peersGettingFromUs();
+ 				c += ' of ';
+ 				c += this._peers_connected;
  				c += ' peers - DL: ';
  				c += Math.formatBytes(this._download_speed);
  				c += '/s UL: ';
***************
*** 393,399 ****
  
  			case Torrent._StatusSeeding:
  				// 'Seeding to 13 of 22 peers - UL: 36.2 KB/s'
! 				c = 'Seeding to ';
  				c += this.peersGettingFromUs();
  				c += ' of ';
  				c += this._peers_connected;
--- 400,406 ----
  
  			case Torrent._StatusSeeding:
  				// 'Seeding to 13 of 22 peers - UL: 36.2 KB/s'
! 				c += 'Seeding to ';
  				c += this.peersGettingFromUs();
  				c += ' of ';
  				c += this._peers_connected;
***************
*** 404,410 ****
  
  			case Torrent._StatusChecking:
  				// 'Verifying local data (40% tested)'
! 				c = 'Verifying local data (';
  				c += Math.roundWithPrecision( 100.0 * this._recheckProgress, 0 );
  				c += '% tested)';
  				break;
--- 411,417 ----
  
  			case Torrent._StatusChecking:
  				// 'Verifying local data (40% tested)'
! 				c += 'Verifying local data (';
  				c += Math.roundWithPrecision( 100.0 * this._recheckProgress, 0 );
  				c += '% tested)';
  				break;
***************
*** 443,452 ****
  			}
  			
  			// Create the 'progress details' label
! 			// Eg: '101 MB of 631 MB (16.02%) - 2 hr remaining'
! 			c = Math.formatBytes( this._sizeWhenDone - this._leftUntilDone );
! 			c += ' of ';
! 			c += Math.formatBytes( this._sizeWhenDone );
  			c += ' (';
  			c += this.getPercentDoneStr();
  			c += '%)';
--- 450,463 ----
  			}
  			
  			// Create the 'progress details' label
! 			// Eg: '698.05 MB, uploaded 8.59 GB (Ratio: 12.3), downloaded 101 MB (16.02%) - 2 hr remaining'
! 			c = Math.formatBytes( this._sizeWhenDone );
! 			c += ', uploaded ';
! 			c += Math.formatBytes( this._upload_total );
! 			c += ' (Ratio ';
! 			c += Math.round(this._upload_ratio*100)/100;
! 			c += '), downloaded ';
! 			c += Math.formatBytes( this._sizeWhenDone - this._leftUntilDone );
  			c += ' (';
  			c += this.getPercentDoneStr();
  			c += '%)';
***************
*** 633,638 ****
--- 644,664 ----
  };
  
  /** Helper function for sortTorrents(). */
+ Torrent.compareByDownloadSpeed = function( a, b ) {
+ 	return a.downloadSpeed() - b.downloadSpeed();
+ };
+ 
+ /** Helper function for sortTorrents(). */
+ Torrent.compareByUploadSpeed = function( a, b ) {
+ 	return a.uploadSpeed() - b.uploadSpeed();
+ };
+ 
+ /** Helper function for sortTorrents(). */
+ Torrent.compareByRatio = function( a, b ) {
+ 	return a.ratio() - b.ratio();
+ };
+ 
+ /** Helper function for sortTorrents(). */
  Torrent.compareByProgress = function( a, b ) {
  	if( a.getPercentDone() !== b.getPercentDone() )
  		return a.getPercentDone() - b.getPercentDone();
***************
*** 653,658 ****
--- 679,693 ----
  		case Prefs._SortByActivity:
  			torrents.sort( this.compareByActivity );
  			break;
+ 		case Prefs._SortByDownloadSpeed:
+ 			torrents.sort( this.compareByDownloadSpeed );
+ 			break;
+ 		case Prefs._SortByUploadSpeed:
+ 			torrents.sort( this.compareByUploadSpeed );
+ 			break;
+ 		case Prefs._SortByRatio:
+ 			torrents.sort( this.compareByRatio );
+ 			break;
  		case Prefs._SortByAge:
  			torrents.sort( this.compareByAge );
  			break;
Post Reply