Skip to content

Commit

Permalink
Merge remote branch 'rtnpro/master'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	features/step_definitions/torrent_info_steps.rb
	features/support/testapp.rb
	features/torrent_info.feature
	index.html
	js/controllers/settings.js
	js/controllers/torrents.js
	js/helpers/filter_torrents_helpers.js
	js/helpers/link_helpers.js
	js/helpers/setting_helpers.js
	js/helpers/store_helpers.js
	js/models/torrent.js
	js/rpc.js
	js/transmission.js
	js/views/torrent.js
	spec/sort_torrents_helpers_spec.js
	spec/torrent_view_spec.js
	templates/torrents/show_info.mustache
  • Loading branch information
endor committed Mar 30, 2010
2 parents 8ff04fe + c4dfae5 commit 5d3a64c
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -50,4 +50,4 @@ There are [culerity](http://github.com/langalex/culerity) tests in `features`. Y
* maybe statistics, preferences not as sidebar
* maybe show ratio goal in torrent list (if so, it should be changeable in the settings)
* maybe be able to select multiple torrents and pause/activate them
* maybe actually request if turtle mode is enabled to set correct value
* maybe actually request if turtle mode is enabled to set correct value
3 changes: 2 additions & 1 deletion index.html
Expand Up @@ -60,6 +60,7 @@
<a href="#/torrents?filter=downloading" class="downloading">Downloading</a>
<a href="#/torrents?filter=seeding" class="seeding">Seeding</a>
<a href="#/torrents?filter=paused" class="paused">Paused</a>
<a href="#/torrents?filter=active" class="active">Activity</a>
</span>
<span id="sorts">
<a href="#/torrents?sort=activity" class="activity">Activity</a>
Expand All @@ -72,7 +73,7 @@
</div>
</div>
</header>

<div id="container" class="container showgri">
<div class="main info">
<div class="torrents_container">
Expand Down
26 changes: 18 additions & 8 deletions js/helpers/filter_torrents_helpers.js
Expand Up @@ -3,14 +3,24 @@ var FilterTorrentsHelpers = {
var filtered_torrents = [];
var stati = Torrent({}).stati;

if(filter_mode == 'all') {
filtered_torrents = torrents;
} else {
$.each(torrents, function() {
if(this.status == stati[filter_mode]) {
filtered_torrents.push(this);
}
});
switch(filter_mode) {
case 'all':
filtered_torrents = torrents;
break;
case 'active':
$.each(torrents, function() {
if(this.activity()) {
filtered_torrents.push(this)
}
});
break;
default:
$.each(torrents, function() {
if(this.status == stati[filter_mode]) {
filtered_torrents.push(this);
}
});
break;
}

return filtered_torrents;
Expand Down
98 changes: 98 additions & 0 deletions js/helpers/link_helpers.js~
@@ -0,0 +1,98 @@
var LinkHelpers = {
activateLinks: function() {
this.activateAddTorrentLink();
this.activateSettingsLink();
this.activateStatisticsLink();
this.activateTurtleModeLink();
this.activateCompactViewLink();
this.activateFilterAndSortLink();
},

activateAddTorrentLink: function() {
var context = this;
$('#add_a_torrent').click(function() {
if(context.infoIsOpen()) {
context.closeInfo();
} else {
window.location.hash = '/torrents/new';
}
return false;
});
},

activateFilterAndSortLink: function() {
var context = this;
$('#activate_filters').click(function() {
$('#filters').show();
$('#sorts').hide();
});
$('#activate_sorts').click(function() {
$('#filters').hide();
$('#sorts').show();
});
},

activateTurtleModeLink: function() {
var context = this, redirect_path = '';
$('#turtle_mode').click(function() {
var form = $('#turtle_mode_form');
form.submit();
if($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).text('Enable Turtle Mode');
form.find('input:first').attr('value', 'true');
} else {
$(this).addClass('active');
$(this).text('Disable Turtle Mode');
form.find('input:first').attr('value', 'false');
}
/*if activateComapactViewLink.hasClass('active') {
redirect_path = '#/torrents?view=compact';
}*/
redirect_path = '#/torrents?view=compact';
context.redirect(redirect_path)
return false;
});
},

activateCompactViewLink: function() {
var context = this, redirect_path = '';
$('#compact_view').click(function() {
if($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).text('Enable Compact View');
redirect_path = '#/torrents?view=normal';
} else {
$(this).addClass('active');
$(this).text('Disable Compact View');
redirect_path = '#/torrents?view=compact';
}
context.redirect(redirect_path);
return false;
});
},

activateSettingsLink: function() {
var context = this;
$('#settings').click(function() {
if(context.infoIsOpen()) {
context.closeInfo();
} else {
context.redirect('#/settings');
}
return false;
});
},

activateStatisticsLink: function() {
var context = this;
$('#statistics').click(function() {
if(context.infoIsOpen()) {
context.closeInfo();
} else {
context.redirect('#/statistics');
}
return false;
});
}
}
143 changes: 143 additions & 0 deletions js/models/torrent.js~
@@ -0,0 +1,143 @@
Torrent = function(attributes) {
var torrent = {};

torrent['fields'] = [
'id', 'name', 'status', 'totalSize', 'sizeWhenDone', 'haveValid', 'leftUntilDone',
'eta', 'uploadedEver', 'uploadRatio', 'rateDownload', 'rateUpload', 'metadataPercentComplete',
'addedDate'
];
torrent['info_fields'] = [
'downloadDir', 'creator', 'hashString', 'comment', 'isPrivate', 'downloadedEver',
'haveString', 'errorString', 'peersGettingFromUs', 'peersSendingToUs', 'files',
'pieceCount', 'pieceSize', 'trackerStats', 'peers'
];
$.each(torrent.fields, function() {
torrent[this] = attributes[this];
});
$.each(torrent.info_fields, function() {
torrent[this] = attributes[this];
});

$.each(['totalSize', 'downloadedEver', 'uploadedEver', 'pieceSize'], function() {
var attr = this;
torrent[attr + 'String'] = function() {
return Math.formatBytes(torrent[attr]);
}
});

torrent.secure = function() {
return (torrent.isPrivate) ? 'Private Torrent' : 'Public Torrent';
};
torrent.isActive = function() {
return (torrent.status & (torrent.stati['downloading'] | torrent.stati['seeding'])) > 0;
};
torrent.isDoneDownloading = function() {
return torrent.status === torrent.stati['seeding'] || torrent.leftUntilDone === 0;
};
torrent.needsMetaData = function() {
return torrent.metadataPercentComplete < 1
};
torrent.percentDone = function() {
return Math.formatPercent(torrent.sizeWhenDone, torrent.leftUntilDone);
};
torrent.progressDetails = function() {
var progressDetails;
if(torrent.needsMetaData()) {
progressDetails = torrent.metaDataProgress();
} else if(!torrent.isDoneDownloading()) {
progressDetails = torrent.downloadingProgress();
if(torrent.isActive()) {
progressDetails += ' - ' + torrent.etaString();
}
} else {
progressDetails = torrent.uploadingProgress();
}

return progressDetails;
};
torrent.downloadingProgress = function() {
var formattedSizeDownloaded = Math.formatBytes(torrent.sizeWhenDone - torrent.leftUntilDone);
var formattedSizeWhenDone = Math.formatBytes(torrent.sizeWhenDone);

return (formattedSizeDownloaded + " of " + formattedSizeWhenDone + " (" + torrent.percentDone() + "%)");
};
torrent.uploadingProgress = function() {
var formattedSizeWhenDone = Math.formatBytes(torrent.sizeWhenDone);
var formattedUploadedEver = Math.formatBytes(torrent.uploadedEver);

var uploadingProgress = formattedSizeWhenDone + ", uploaded " + formattedUploadedEver;
return uploadingProgress + " (Ratio: " + torrent.uploadRatio + ")";
};
torrent.metaDataProgress = function() {
var percentRetrieved = (Math.floor(torrent.metadataPercentComplete * 10000) / 100).toFixed(1);
return "Magnetized transfer - retrieving metadata (" + percentRetrieved + "%)";
};
torrent.progressBar = function() {
var status, progressBar;

if(torrent.isActive() && torrent.needsMetaData()) {
status = 'meta';
progressBar = $("<div></div>").progressbar({value: 100}).html();
} else if(torrent.isActive() && !torrent.isDoneDownloading()) {
status = 'downloading';
progressBar = $("<div></div>").progressbar({value: torrent.percentDone()}).html();
} else if(torrent.isActive() && torrent.isDoneDownloading()) {
status = 'uploading';
progressBar = $("<div></div>").progressbar({value: torrent.percentDone()}).html();
} else {
status = 'paused';
progressBar = $("<div></div>").progressbar({value: torrent.percentDone()}).html();
}

return progressBar.replace(/ui-widget-header/, 'ui-widget-header-' + status);
};
torrent.etaString = function() {
if(torrent.eta < 0) {
return "remaining time unknown";
} else {
return Math.formatSeconds(torrent.eta) + ' ' + 'remaining';
}
};
torrent.statusStringLocalized = function(status) {
var localized_stati = {};

localized_stati[torrent.stati['waiting_to_check']] = 'Waiting to verify';
localized_stati[torrent.stati['checking']] = 'Verifying local data';
localized_stati[torrent.stati['downloading']] = 'Downloading';
localized_stati[torrent.stati['seeding']] = 'Seeding';
localized_stati[torrent.stati['paused']] = 'Paused';
localized_stati[torrent.stati['active']] = 'Activity';

return localized_stati[this['status']] ? localized_stati[this['status']] : 'error';
};
torrent.statusString = function() {
var currentStatus = torrent.statusStringLocalized(torrent.status);
if(torrent.isActive()) {
currentStatus += ' - ' + torrent.downAndUploadRateString(torrent.rateDownload, torrent.rateUpload);
}
return currentStatus;
};
torrent.statusWord = function() {
for(var i in torrent.stati) {
if(torrent.stati[i] == torrent.status) {
return i;
}
}
};
torrent.downAndUploadRateString = function(downloadRate, uploadRate) {
return 'DL: ' + (downloadRate / 1000).toFixed(1) + ' KB/s, UL: ' + (uploadRate / 1000).toFixed(1) + ' KB/s';
};
torrent.activity = function() {
return torrent.rateDownload + torrent.rateUpload;
};
torrent['stati'] = {
'waiting_to_check': 1,
'checking': 2,
'downloading': 4,
'seeding': 8,
'paused': 16
// 'active': 32
};

return torrent;
};

0 comments on commit 5d3a64c

Please sign in to comment.