Edgewall Software
Modify

Opened 10 years ago

Last modified 5 years ago

#10323 new enhancement

Enable sorting in TitleIndex macro

Reported by: carlos.lopezperez@… Owned by:
Priority: normal Milestone: next-major-releases
Component: wiki system Version:
Severity: normal Keywords: Macro TitleIndex order desc bitesized
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

The goal is to be allowed to order the result of the macro TitleIndex in the same way that RepositoryIndex with the addition of the parameters order and desc.

  • Order possible values: [title|date]
  • Desc possible values: [0|1], same repositoryindex.

For example:

[[TitleIndex(order=title, desc=1)]]

Attachments (7)

TitleIndex_reverse.patch (1.6 KB ) - added by benjamin.a.lau@… 9 years ago.
patch to reverse the TitleIndex list.
#10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_added_two_parameters.patch (3.2 KB ) - added by tkempitiya@… 6 years ago.
added two parameters order(title|date) and desc(0|1) to the TitleIndex macro. Used sql query to get date information.
#10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_added_two_parameters_2.patch (3.2 KB ) - added by tkempitiya@… 6 years ago.
Thanks, I removed the case insensitivity for title sorting
#10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_added_two_parameters_3.patch (3.6 KB ) - added by tkempitiya@… 6 years ago.
Thanks, I updated the description. About the WikiSystem I don't think it cache the time. Is there any other way to get time more efficiently
10323_monthsort.patch (2.6 KB ) - added by anonymous 6 years ago.
#10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_use_pages_metadata_and_testing.patch (6.6 KB ) - added by tkempitiya@… 6 years ago.
added pages_metadata to get date of wiki pages and added new test cases
t10323-index_order.diff (3.1 KB ) - added by Jun Omae 6 years ago.

Download all attachments as: .zip

Change History (25)

comment:1 by Remy Blank, 10 years ago

Keywords: bitesized added
Milestone: 0.13next-major-0.1X

by benjamin.a.lau@…, 9 years ago

Attachment: TitleIndex_reverse.patch added

patch to reverse the TitleIndex list.

in reply to:  1 comment:2 by benjamin.a.lau@…, 9 years ago

I guess what I did is kind of related to this… I wanted to "reverse" the results of the TitleIndex so I added a "reverse" option to do this. I guess this is a very limited version of what this ticket is proposing.

Usage:

[[TitleIndex(reverse=True)]]

comment:3 by noleti@…, 8 years ago

I used Benjamin's patch and it basically works, but subgroups will be in wrong order if grouping is enabled. I was able to get my intended ordering to work by adding some additional sort() changes similar to Benjamin's.

by tkempitiya@…, 6 years ago

added two parameters order(title|date) and desc(0|1) to the TitleIndex macro. Used sql query to get date information.

comment:4 by Ryan J Ollos, 6 years ago

Milestone: next-major-releases1.2
Owner: set to Ryan J Ollos
Status: newassigned

comment:5 by Jun Omae, 6 years ago

The patch seems title sorts by case-insensitive and that is incompatible behavior. We should sort by case-sensitive since WikiPageName is case-sensitive.

by tkempitiya@…, 6 years ago

Thanks, I removed the case insensitivity for title sorting

comment:6 by Peter Suter, 6 years ago

Thanks for the patch!

The _description string should be updated to mention these new parameters.

Should WikiSystem.get_pages() maybe query and cache the time as well? But then the cache would get invalidated much more often.

by tkempitiya@…, 6 years ago

Thanks, I updated the description. About the WikiSystem I don't think it cache the time. Is there any other way to get time more efficiently

comment:7 by Ryan J Ollos, 6 years ago

About the WikiSystem I don't think it cache the time. Is there any other way to get time more efficiently?

Another cached property could be added to the WikiSystem class, perhaps named pages_modtime: tags/trac-1.1.6/trac/wiki/api.py@:288-292#L254. Or should we aim to generalize and add a pages_metadata cached property that returns all of the page metadata (basically, everything except the text)?

In addition to caching the modtime, the aim is to keep SQL out of macros.py. Ideally the SQL would be in model.py, but for now it's fine to extend the existing functions in api.py.

An order_by parameter could then be added to WikiSystem.get_pages.

I'm probably overlooking something, but for what case is p a tuple in index_order?

Unit tests can be added in tags/trac-1.1.6/trac/wiki/tests/macros.py.

Lines need to wrap at 79 chars, per TracDev/CodingStyle.

comment:8 by Peter Suter, 6 years ago

For some reason I thought env.get_known_users(last_visit=True) (as proposed in comment:8:ticket:10736) was now allowed, and WikiSystem.get_pages(time=True) would be a logical continuation of that. (But now I see that has not happened.)

A general page metadata solution seems desirable.

An order_by parameter looks clean, but might not allow sorting format=group or format=hierarchy by time.

In those format cases p is a tuple (path_elements, page_name). See tree_group() and tree_hierarchy().

Last edited 6 years ago by Ryan J Ollos (previous) (diff)

comment:9 by anonymous, 6 years ago

We could really use a smart "natural" sort mode where in wiki pages like wiki:Meeting/2015/Aug/10 etc. the Aug part is detected as a month abbreviation and sorted "correctly" between similar page names with Jul and Sep.

Sorry, if this is too specific / out-of-scope. A plugin would be fine, but macros don't offer any extension points.

in reply to:  7 ; comment:10 by anonymous, 6 years ago

Replying to Ryan J Ollos:

Or should we aim to generalize and add a pages_metadata cached property that returns all of the page metadata (basically, everything except the text)?

Maybe even the text or at least the extracted page title for #10523.

by anonymous, 6 years ago

Attachment: 10323_monthsort.patch added

in reply to:  10 comment:11 by Ryan J Ollos, 6 years ago

Replying to anonymous:

Maybe even the text or at least the extracted page title for #10523.

I was concerned about execution speed and memory usage when including text in the query, but I haven't done any profiling.

Last edited 6 years ago by Ryan J Ollos (previous) (diff)

by tkempitiya@…, 6 years ago

added pages_metadata to get date of wiki pages and added new test cases

comment:12 by Ryan J Ollos, 6 years ago

Thanks for revising the patch. One suggestion - use a namedtuple in get_pages_metadata.

by Jun Omae, 6 years ago

Attachment: t10323-index_order.diff added

comment:13 by Jun Omae, 6 years ago

Quick review:

  • The pages_metadata is incorrect. The latest version of each page should be cached. Also, we shouldn't use costly DISTINCT with all fields in the general cases.
  • Using both pages_metadata and WikiSystem.get_pages() is race. The get_pages() uses pages decorated @cached. I think we should use only pages_metadata.
  • We should invalidate the cache of pages_metadata when a page is saved, renamed and deleted. See del WikiSystem(self.env).pages in trac/wiki/model.py and trac/wiki/admin.py.
  • UnboundLocalError when order=xxxxx parameter is passed.
  • In the latest patch, uses of index_order for tree_group and tree_hierarchy are removed. Is that intentional?
  • I don't think that if type(p) is tuple in index_order is elegant. How about t10323-index_order.diff?
  • More tests. That tests don't cover the added features.
Last edited 6 years ago by Jun Omae (previous) (diff)

in reply to:  9 comment:14 by Jun Omae, 6 years ago

Replying to anonymous:

We could really use a smart "natural" sort mode where in wiki pages like wiki:Meeting/2015/Aug/10 etc. the Aug part is detected as a month abbreviation and sorted "correctly" between similar page names with Jul and Sep.

Sorry, if this is too specific / out-of-scope. A plugin would be fine, but macros don't offer any extension points.

-1 but please create a new ticket for that if you want the feature.

That feature isn't useful for non-English users. Also, the smartsort parameter naming is not smart. At least, I don't know what kind of sort is used by smartsort.

comment:15 by Ryan J Ollos, 6 years ago

Milestone: 1.2next-major-releases

Unscheduling until comment:13 issues are addressed.

comment:16 by Ryan J Ollos, 6 years ago

#12319 closed as a duplicate.

comment:17 by Ryan J Ollos, 5 years ago

Owner: Ryan J Ollos removed
Status: assignednew

comment:18 by hfrmobile, 5 years ago

vote +1 for "Enable sorting in TitleIndex macro"

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.