Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is it an idea to make the overview tables of rules and rulesets sortable?
Further I think they should be sorted first on their weight and secondly on their label.
Comment | File | Size | Author |
---|---|---|---|
#33 | interdiff-372328-27-33.txt | 2.41 KB | jacob.embree |
#33 | rules-sort_weight-372328-33.patch | 11.52 KB | jacob.embree |
| |||
#32 | rules-sort_weight-372328-32.patch | 846 bytes | Carine23 |
#27 | rules-sort_weight-372328-27.patch | 11.33 KB | hargobind |
Comments
Comment #1
fago>Further I think they should be sorted first on their weight and secondly on their label.
That's the case. Isn't it?
>Is it an idea to make the overview tables of rules and rulesets sortable?
Yep it is, however this won't happen for 1.0. But probably for a later version..
Comment #2
mitchell CreditAttribution: mitchell commentedBumping to 7.x.
Comment #3
fagoWe cannot rely on the DB for this, we would have to manually code this. Thus for now, won't fix.
Comment #4
videographics CreditAttribution: videographics commentedIs this worth revisiting? It just seems weird to see all my rules with a weight of -10 sitting at the bottom of the list and all the higher values above them. I wouldn't expect live updates with handles and all that, but if we can set the weight for each rule and show the weight for each rule on each line of the overview page, surely that value can be used to affect the sorting on that page.
Comment #5
mitchell CreditAttribution: mitchell commented>>>>Is this worth revisiting?
>>Yep it is, however this won't happen for 1.0.
Reopening for 2.x development.
>>We cannot rely on the DB for this, we would have to manually code this.
How might this be coded? What are the steps ahead?
Comment #6
videographics CreditAttribution: videographics commentedJust to be clear, I'm only suggesting we sort the list by the weight value. I understanding setting up handles to facilitate interactive reordering would be a bigger deal and might need to be put off, but If the weight value is right there to be displayed, why is it a challenge to use it for sorting? What am I missing?
Comment #7
AaronBaumanI haven't read through all the other threads and comments about this issue.
I'm not sure why it's so complicated to sort the rows in a table.
Here's a quick and simple patch that accomplishes the request without compromising any functionality.
I'm sure someone will let me know if i'm being naive.
Comment #9
timmarwick CreditAttribution: timmarwick commentedAny update on this?
Comment #10
AaronBaumanThe patch in #7 does what it says, even though testbot doesn't like it.
May need a re-roll against latest dev.
Comment #11
As If CreditAttribution: As If commentedRe #7: Found a problem on version 7.x-2.3+1-dev. While the patch does indeed sort rules by weight, it fails to make the corresponding changes in the edit/clone/etc links on the right-hand side. Reverting the patch restored my links to their proper destinations.
Comment #12
sbrattla CreditAttribution: sbrattla commentedI don't see why rules should be sorted by weight only?
I'd say they should be sorted by event and then weight. The weight does after all only apply within an event.
Comment #13
sbrattla CreditAttribution: sbrattla commentedI realize that a rule can be triggered by multiple events; so I see that it does not really make sense to sort by event.
Comment #14
As If CreditAttribution: As If commentedNot to make extra work for anybody, but it seems to me the way to do this right would be a sortable table:
Name | Event | Weight | Status | Operations
The first 4 columns could be sortable by clicking column headers. The default might be alpha by name (hell, what is the default now?)
Even cooler would be if a second click remembered the previous sort and used it as its secondary sort (i.e., if I click Weight then Event I get all rules sorted by weights within events).
The trickiest part is rules that fall under more than one event, as sbrattla pointed out. Those might appear more than once. But since both links would lead to the same place anyway, I don't really see that as a problem.
Comment #15
cjoy CreditAttribution: cjoy commentedThe patch from #7 sorts by weight alright, but also breaks the operations links correlation.
I ran into this issue coming from a Drupal Commerce use case:
Many rules reacting to a single event where execution order is relevant.
Problems encountered with the default Rules UI:
- it is hard to tell what logic will be performed when event X is triggered.
- it provides no overview of what events are actually tied to active rules
I ended up throwing a little javascript at the problem.
The script first groups the rules by event (alphabetical) and then sorts by weight within each group. Rules that are tied to multiple events are listed in each respective group and easily identified as "multiple event" rules. In this context, being able to dynamically sort the rules is of lesser importance, so I did not include it.
If you'd like to try it out, just go to 'admin/config/workflow/rules' and paste/run the script below in your browser console.
minified to save space, pretty syntax at: https://www.dropbox.com/s/eyirg2dyzldpqww/rules_bettertableformat.js
preview at: https://www.dropbox.com/s/m8y43e16di1hyht/rules_bettertableformat.jpg
P.S.: If this issue is the wrong place for this comment, feel free to move and/or delete it.
Comment #16
reszliI converted cjoy's comment into a patch for ease of use if someone else also needs it - until a final solution is implemented.
Comment #17
dema501 CreditAttribution: dema501 commented#16 works for me
Comment #18
cjoy CreditAttribution: cjoy commentedthank you @reszli - happy to see that the little hack is of use to others :)
Just a minor glitch in that patch: the behaviors scope.
I guess "behaviors.quantityWidgetSpinner" is a copy/paste leftover and should probably be renamed to avoid conflicts.
Comment #19
Imaaxa-Cory CreditAttribution: Imaaxa-Cory commentedUntil this functionality is incorporated into rules, I am using a view to give me a list of rules that is sortable by Label, Plugin, Active, Weight and grouped by Plugin. It also has exposed filters in a block to add to the page. The Labels are links to edit the the rules.
Comment #20
AaronBauman2 years later... rules overview table is sorted by entity id, which really makes no sense.
Here's a reroll.
Comment #22
AaronBaumanafter this i'm giving up, testbot
Comment #23
hargobindThanks @aaronbauman for your work on this patch.
I see a typo/discrepancy with the code
uasort($entities, array('self', 'sortObjectsByWeight'));
and the actual function namesortByWeight()
. I fixed this in the attached patch.Since I make use of the Event column in the rules config, I have found it useful to sort on that column. I also made it possible to specify multiple sorts.
Thoughts?
Comment #24
NWOM CreditAttribution: NWOM commented#23 applied cleanly, but the following notices/warnings are shown on the "workflow/rules" page:
This notice is shown multiple times, dependent on the amount of rules that exist:
Notice: Undefined offset: 0 in RulesUIController->sortObjectsByEvent() (line 283 of /var/aegir/platforms/panopoly-7.x-1.35/sites/{SITE}/modules/rules/ui/ui.controller.inc).
This warning is shown once at the end of all of the notices:
Warning: uasort(): Array was modified by the user comparison function in RulesUIController->overviewTable() (line 228 of /var/aegir/platforms/panopoly-7.x-1.35/sites/{SITE}/modules/rules/ui/ui.controller.inc).
Running cron and clearing all cache does not remove the notices/warnings. Sorting was also not possible.
Comment #25
upunkt CreditAttribution: upunkt commented+1 @Imaaxa-Cory #19 for this approach! I added a column
Module
for a commerce site also. This helped a lot.Comment #26
ThePiano.SG CreditAttribution: ThePiano.SG commented@NWOM, there's a slight error in the patch in #23.
rules > ui > ui.controller.inc > sortObjectsByEvent()
Before:
After:
3 very important things to note:
Taking into account stable sort:
Comment #27
hargobind@ThePiano.SG great idea to add a stable-sort!
Here's another take which incorporates the bug fix and stable-sort code in #24.
Another big improvement was to add a draggable table on the Rules Settings page for users to choose sort order. I also added Status sorting, and Plugin sorting on the Components page.
Module maintainers: this new code makes some big modifications to
rules_admin.inc
, namely it adds a theme_FORM_ID() wrapper to the settings form, and a submit handler to process the draggable form weights. I based that approach on the tabledrag_example_simple_form code example.I think this is finally ready for mainstream. Please test!!
Comment #28
TR CreditAttribution: TR commentedWill this patch also address #2533840: Order rules by label instead of by id ?
Comment #29
hargobind@TR yes, it will. I just closed that issue as a duplicate of this one.
Comment #30
TR CreditAttribution: TR commentedI also found #2990428: Display rules grouped by tags
Comment #31
Carine23 CreditAttribution: Carine23 commentedJust tested patch #27 and the issue found by #11 is still relevant:
So the links go to another rule basically.
Comment #32
Carine23 CreditAttribution: Carine23 commentedI have created a patch for the links, as the solution looks very simple (but let me know if it's not OK).
Instead of sending the entity id to overviewTableRow() from overviewTable(), I send the machine name of the rule, as intended (overviewTableRow takes $name as second parameter, not id).
Comment #33
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration, 3Sages commentedI'm not sure what to make of #32.
Keys need to be preserved for the operation links. This patch is based on #27 and preserves the keys.
Comment #34
hargobindThanks Jacob! This patch works great and the links are finally working again. (I'm guessing my patch in #27 broke with the release of 2.10 or 2.11.)
Did we get all the possible sort options? It's now possible to sort on: Name, Event (on the Rules page), Weight, Plugin (on the Components page), Status
Marking this as RTBC since I tested it and couldn't find any problems. But would love to get a few other people to test this since Rules is such a highly used module and we don't want to introduce any new bugs.
Comment #35
delacosta456 CreditAttribution: delacosta456 commentedhi apply the patch #33 which apply correctly But as soon as i change the table's behavior in settings i always get this messages
Notice: Undefined offset: 0 in RulesUIController::sortObjectsByEvent() (line 287 of /Applications/MAMP/htdocs/webdev/rbbdoc/rbbdev/wroot/sites/all/modules/dev/rules/ui/ui.controller.inc).