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

luci-base: fix sort order for size columns #6643

Closed
wants to merge 1 commit into from

Conversation

raenye
Copy link
Contributor

@raenye raenye commented Oct 21, 2023

Currently elements of package size, packet size, etc. columns are interpreted as text strings, so we have "800 B" > "7.54 KiB" > "5.11 MiB". To fix this, a new regexp is added to UITable.deriveSortKey.

It is still not a perfect fix for System->Software->Installed, since pagination is done based on package names, so within each page the packages are sorted correctly, but the smallest (resp., largest) package is not necessarily on the first (resp., last) page.

Closes: #5994 (see also #6120)

Currently elements of package size, packet size, etc. columns are
interpreted as text strings, so we have "800 B" > "7.54 KiB" > "5.11 MiB".
To fix this, a new regexp is added to UITable.deriveSortKey.

It is still not a perfect fix for System->Software->Installed, since
pagination is done based on package names, so within each page the packages
are sorted correctly, but the smallest (resp., largest) package is not
necessarily on the first (resp., last) page.

Closes: openwrt#5994 (see also openwrt#6120)

Signed-off-by: Rani Hod <[email protected]>
@raenye
Copy link
Contributor Author

raenye commented Nov 7, 2023

@jow- Would you please take a look?

@jow-
Copy link
Contributor

jow- commented Nov 7, 2023

I think a better solution is adding a data-value attribute to the affected cells which contains the raw, unformatted byte value.

@raenye
Copy link
Contributor Author

raenye commented Nov 7, 2023

Maybe this should be the only value, and let css magic do the text formatting for rendering?

@jow-
Copy link
Contributor

jow- commented Nov 7, 2023

CSS magic can't do that as far as I know.

@systemcrash
Copy link
Contributor

I think a better solution is adding a data-value attribute to the affected cells which contains the raw, unformatted byte value.

I came to suggest this. Exclude any units from the numeric value, and append those at a later stage, so sorting is done on raw numbers.

@systemcrash systemcrash added fix pull request fixing a bug Work needed Needs work by the pullrequest creator labels Dec 5, 2023
@systemcrash
Copy link
Contributor

This looks related to #4087

@knarrff
Copy link
Contributor

knarrff commented Dec 10, 2023

This looks related to #4087

It is - plus as #4087 correctly points out, 'k' 'M' and 'G' are for 10^3, 10^6 and 10^9. However, the idea of the report is still an important one: columns should sort by real number, and even across pages.

@raenye
Copy link
Contributor Author

raenye commented Dec 11, 2023

@systemcrash my JS skills are not sufficient to make the recommended changes. Should I close the PR?

@systemcrash
Copy link
Contributor

Have a crack at it. This is a great learning opportunity.

@jow-
Copy link
Contributor

jow- commented Dec 11, 2023

Are there currently any tables left requiring this change? While I agree that it might be nice to smartly detect formatted size values and sort them accordingly, the proper fix should be adjusting affected tables to contain a data-value attribute. This can be achieved by changing the existing value expression to a two-element array where the first element should be the raw numeric value and the second value the formatted display text.

See for example commit 4f4ad9b which fixed some tables shown in the nlbwmon application. The underlying capability to the UITable class has been added in 90a2b1e

@systemcrash
Copy link
Contributor

systemcrash commented Dec 11, 2023 via email

@jow-
Copy link
Contributor

jow- commented Dec 11, 2023

Does the sorting logic then depend in the browser?

I don't understand that question. Why should it depend on the browser?

@systemcrash
Copy link
Contributor

Because the data is at the client, and the client is the users web browser. So column sorting is performed by the browser. Or?

@jow-
Copy link
Contributor

jow- commented Dec 11, 2023

Uhm, yes but the current sorting is done by the browser as well?

@knarrff
Copy link
Contributor

knarrff commented Dec 11, 2023

Because the data is at the client, and the client is the users web browser. So column sorting is performed by the browser. Or?

It should not be done at the browser, because at most the data of the current page is available to the browser (edit: I was wrong here) and sorting should span pages.

@jow-
Copy link
Contributor

jow- commented Dec 11, 2023

It should not be done at the browser, because at most the data of the current page is available to the browser and sorting should span pages.

There is no server side rendering in LuCI anymore, all data is rendered locally in the browser by building the table DOM from a multi dimensional array (or, in some cases by reading JS generated HTML table DOM and translating it into an internally table representation which is then eventually re-rendered) so sorting happens in the browser as well, naturally.

There's also no paging for the most part. The only paging I can think of is the software package list in the opkg menu, but that is rendered browser-side as well, it actually parses the raw package metadata list locally using JavaScript and dynamically builds the tables and paging logic

@systemcrash
Copy link
Contributor

systemcrash commented Dec 11, 2023 via email

@jow-
Copy link
Contributor

jow- commented Dec 11, 2023

So pagination of data should also happen at the browser.

It is, there is no single server side rendered/paged table view in LuCI within this repository I am aware of.

The only exception should be the opkg package list display, but neither this PR nor the existing quick column sort logic will fix sorting across it's paged views. Solving that would require reworking the entire opkg view (or building paging logic right into the UITable class here: https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/ui.js#L3179)

@knarrff
Copy link
Contributor

knarrff commented Dec 11, 2023

The only exception should be the opkg package list display

Looking at that page (/cgi-bin/luci/admin/system/opkg ?), also this seems to get all data at once (an almost 5 MB data chunk), which is then locally paginated. So, it seems what @jow- suggests should be possible, including sorting across pages (which currently does not work).

@systemcrash
Copy link
Contributor

@knarrff was opkg page your only concern here?

@knarrff
Copy link
Contributor

knarrff commented Dec 11, 2023

I did not have a particular page in mind, but assumed that pagination happens because it would reduce bandwidth usage. That pagination is not done server-side should make sorting a whole lot easier.

@systemcrash
Copy link
Contributor

@systemcrash my JS skills are not sufficient to make the recommended changes. Should I close the PR?

Would you like to try and add the necessary fields using this PR that @jow- highlighted earlier here?

@raenye
Copy link
Contributor Author

raenye commented Dec 11, 2023

I'll try this, thanks.

@systemcrash
Copy link
Contributor

@raenye Do you have an update?

@systemcrash systemcrash marked this pull request as draft December 30, 2023 02:56
@systemcrash
Copy link
Contributor

See @jow-'s latest e7f2e6b

@raenye
Copy link
Contributor Author

raenye commented May 21, 2024

See @jow-'s latest e7f2e6b

Thanks, but 63e5d38 already did that part for opkg.js.
Nevertheless, it doesn't solve the pagination issue, just the per-page sorting.

In any case, this PR is no longer relevant, so I'm closing this. If I find the time to fix pagination, I'll create a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pull request fixing a bug Work needed Needs work by the pullrequest creator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nlbwmon: sort is broken -- sorts by the number, not respecting the units
4 participants