Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebUI Add Limit Share Ratio context menu option #8598

Merged
merged 3 commits into from
Apr 14, 2018

Conversation

Piccirello
Copy link
Member

GUI:
screen shot 2018-03-14 at 2 01 44 am

WebUI:
screen shot 2018-03-14 at 2 04 38 am

ratioLimit = -1;

qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong();
if (seedingTimeLimit == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use <=?
And also in above instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you drop zero?

FYI, setRatioLimit/setSeedingTimeLimit checks its params for incorrect values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to handle the case where values of 0 should be treated as no limit. But the GUI doesn't seem to exhibit this behavior, so removing this code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it does do this in UpDownRatioDlg::ratio(). But this is WebUI-implementation specific so I'm now handling this in shareratio.html's js logic.

if (hashes.length === 1) {
var hash = hashes[0];
var row = torrentsTable.rows[hash].full_data;
console.log(row);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit code in the early hours of the morning. Removing this.

height: 175
});
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this empty line.

@@ -163,6 +162,33 @@ initializeWindows = function() {
}
};

shareRatioFN = function() {
console.log("Limit share ratio...");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@@ -387,13 +412,12 @@ initializeWindows = function() {
if (hashes.length == 1) {
var hash = hashes[0];
var row = torrentsTable.rows[hash];
if (row) {
var name = row.full_data.name;
if (row)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the curly braces, better safe than sorry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional's code block doesn't seem complex enough to warrant curly braces.

};

// select current values
if (hashesList.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about if (hashesList.length !== 1) return;? and you save some indention.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced this code.

if ($('setMinutes').get('checked'))
seedingTimeLimitValue = $('minutes').get('value');
}
else return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add braces here to be coherent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, it is not accepted to write consistent code in web development, as well as adhere to any other rules... Nothing personal, it follows from all my observations of the web code.

function getSelectedRadioValue(name) {
var radios = document.getElementsByName(name);

for (var i = 0; i < radios.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++i and instances below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this context the results are identical, and i++ is a lot more common in JavaScript. We have 39 instances of i++ in our js codebase, but only 1 instance of ++i.

Copy link
Member

@Chocobo1 Chocobo1 Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm merely pointing out the coding style, until the coding guidelines extends to JS, I can't/won't force you to change it.

In this context the results are identical, and i++ is a lot more common in JavaScript.

Of course and I often wonder why that is the case in JS world given ++i, i++ have the same counterparts in C++...

@@ -76,6 +76,11 @@ function friendlyPercentage(value) {
return percentage.toFixed(1) + "%";
}

function friendlyFloat(value, precision) {
var mult = Math.pow(10, precision);
return Math.round(value * mult) / mult;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fell over this... why multiply then divide?
can't you do return Math.round(value).toFixed(2)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that we can round to a specific digit. Otherwise Math.round(value) will round to the nearest int, with toFixed(2) adding two zeros.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining it.
AFAIK javascript numbers are always float type, then this function can be just return value.toFixed(precision); right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK javascript numbers are always float type, then this function can be just return value.toFixed(precision); right?

You're right. That's a simpler solution too.

@@ -120,6 +120,7 @@ <h1 class="applicationTitle">qBittorrent Web User Interface <span class="version
</li>
<li class="separator"><a href="#DownloadLimit"><img src="theme/kt-set-max-download-speed" alt="QBT_TR(Limit download rate...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Limit download rate...)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#UploadLimit"><img src="theme/kt-set-max-upload-speed" alt="QBT_TR(Limit upload rate...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Limit upload rate...)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#ShareRatio"><img src="theme/ratio" alt="QBT_TR(Limit share ratio...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Limit share ratio...)QBT_TR[CONTEXT=TransferListWidget]</a></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the img src, there is already one at icons/skin/ratio.png, the webUI cannot access there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That version is 256x256 and 5x larger than this icon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's "usually" better to provide large image and scale it down than scale up small image, especially when high-dpi monitor is getting common.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant 5x larger in terms of file size. In the WebUI this image has a static, specified height of 16px x 16px.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant 5x larger in terms of file size.

Surely our bottleneck isn't here... and almost all icons in the icon folder are 256x256, obviously you can see the motivation.
If you really insist adding the icon, move it to www/private/image folder.

In the WebUI this image has a static, specified height of 16px x 16px.

Would be better if we used em as unit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better if we used em as unit.

This would be a great goal for a separate PR. I don't feel comfortable switching units for this small change.

@glassez glassez added the WebUI WebUI-related issues/changes label Mar 14, 2018
@@ -622,6 +622,26 @@ void TorrentsController::setDownloadLimitAction()
applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *torrent) { torrent->setDownloadLimit(limit); });
}

void TorrentsController::setShareLimitAction()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use setShareLimits

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update this.

ratioLimit = -1;

qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong();
if (seedingTimeLimit == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you drop zero?

FYI, setRatioLimit/setSeedingTimeLimit checks its params for incorrect values.

@Piccirello Piccirello force-pushed the limit-share-ratio branch 2 times, most recently from 09564ab to 7768630 Compare March 19, 2018 07:55
@Piccirello
Copy link
Member Author

Are per-torrent rate limits supposed to be persisted between application restarts? They appear not to be.

@glassez
Copy link
Member

glassez commented Mar 19, 2018

They appear not to be.

What makes you think that?

@Piccirello
Copy link
Member Author

What makes you think that?

In my testing, custom ratios aren't persisted across restarts. "No limit" does appear to be persisted correctly. To reproduce:

  1. Limit torrent's share ratio to custom ratio/minutes
  2. Exit qBittorrent
  3. Launch qBittorrent
  4. Verify share ratio is set back to global

@Arathen
Copy link

Arathen commented Mar 20, 2018

custom ratios aren't persisted across restarts

This hasn't been my experience. I make extensive use of per-torrent share ratios (the reason I requested them for the WebUI) and if they didnt persist across restarts it would be a show stopper for me. What I have found and reported previously under #7335 is that the default global share ratio does not stick. If I set a default share ratio it gets applied to all torrents which dont already have an explicit per-torrent ratio set, but then after a reasonably short period of time (I havent timed it but its less than an hour or so) it just reverts back to Bittorrent\MaxRatio=-1 in the config file for no apparent reason that ive been able to identify.

Per-torrent share ratios are ok though. Im seeding a couple of hundred long-term torrents, all of which have per-torrent share ratios which have persisted through numerous application (and server) restarts.

@Piccirello
Copy link
Member Author

@Arathen what version of qBittorrent are you running?

I'm experiencing this both on master and on 4.0.4. Can anyone else try to reproduce this and see if it works as expected?

@Arathen
Copy link

Arathen commented Mar 20, 2018

@Piccirello Im running master.

@Chocobo1
Copy link
Member

Can anyone else try to reproduce this and see if it works as expected?

It work as expected, I only tested in GUI.
Are you using webUI? or GUI?

@Piccirello
Copy link
Member Author

Are you using webUI? or GUI?

I first noticed it when testing the WebUI feature, but verified in the GUI. When testing master I'm exclusively checking the GUI.

If anyone can confirm that the WebUI functionality works post-restart, I can just chalk it up to a local client issue.

@Arathen
Copy link

Arathen commented Mar 21, 2018

Confirmed. I grabbed down your PR, compiled and ran nox with it. Over the course of the last hour and a half I've successfully set per-torrent ratio limits via the WebUI and restarted the daemon half a dozen times. All per-torrent limits are preserved through the restarts just fine. I have not compiled or tested the GUI.

Thank you again for implementing this @Piccirello. It truly is a game changing feature for me :)

@Piccirello
Copy link
Member Author

Thanks for confirming @Arathen. And glad I could get this feature implemented. With luck we can get this in 4.0.5.

@Arathen
Copy link

Arathen commented Mar 23, 2018

One minor issue that i've noticed with this - it doesn't seem to work on multiple torrent selections. It works great for a single torrent, but when you Control or Shift click to select multiple lines, clicking the "Save" button after setting a share ratio seems to do nothing.

Like I said, its a minor issue. The overall functionality as it is now is completely usable and far outweighs the glitch.

@Piccirello
Copy link
Member Author

One minor issue that i've noticed with this - it doesn't seem to work on multiple torrent selections. It works great for a single torrent, but when you Control or Shift click to select multiple lines, clicking the "Save" button after setting a share ratio seems to do nothing.

I'm so glad you caught this. This issue should now be fixed with the latest commit. Your testing is much appreciated!

While working on this, I figured out my "local" issue with saving torrent share limits. Turns out that the torrents for which share limits aren't being persisted are all in an error state. Torrents in a good state (Paused, Downloading, Seeding, etc.) successfully persist share ratios across application reboots.

<!DOCTYPE html>
<html lang="${LANG}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #8621 is merged now, can you please apply the changes to here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to reflect the changes.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDlg]</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the script tags too.

<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/misc.js"></script>
<script type="text/javascript">
console.log("shareratio.html");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover. I've removed it.


const qreal ratioLimit = params()["ratioLimit"].toDouble();
const qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong();
const QStringList hashes {params()["hashes"].split('|')};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency please change to: const QStringList hashes = params()["hashes"].split('|'); or you can choose using the curly braces in the above 2 lines instead.

And now its time to squash commits!

I'll turn a blind eye to the coding style comments on JS for now, mind you we also updated the coding guidelines recently (#8629 & #8640).

<title>QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDlg]</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script src="scripts/mootools-1.2-core-yc.js"></script>
<script src="scripts/mootools-1.2-more.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since #8672 is merged, please rebase this PR and also you'll need to change this to: scripts/lib/mootools-1.2-core-yc.js, scripts/lib/mootools-1.2-more.js.

@Piccirello Piccirello force-pushed the limit-share-ratio branch 2 times, most recently from 0fa8746 to adb0d2b Compare April 9, 2018 05:01
@Piccirello
Copy link
Member Author

All commits have been squashed and rebased

Chocobo1
Chocobo1 previously approved these changes Apr 9, 2018
Copy link
Member

@Chocobo1 Chocobo1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Chocobo1
Copy link
Member

@Piccirello
Due to #8622 merged, there are conflicts now...
I can help you resolve it (and also reformat it) if you don't have the time.
I tested the PR and it's OK in current form.

@Piccirello
Copy link
Member Author

I can help you resolve it (and also reformat it) if you don't have the time.

That would be a huge help. Finding time has been tough lately, and now I’m without a computer for the next several days.

@Chocobo1
Copy link
Member

That would be a huge help. Finding time has been tough lately, and now I’m without a computer for the next several days.

Okay, its done now.

@Piccirello
Copy link
Member Author

@Chocobo1 thanks for taking care of this

Copy link
Member

@glassez glassez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to change Wiki accordingly (both pages for current and new API).

@Chocobo1 Chocobo1 merged commit a70942e into qbittorrent:master Apr 14, 2018
@Chocobo1
Copy link
Member

@Chocobo1 thanks for taking care of this

No problem and thanks a lot for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants