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.

Files: 
CommentFileSizeAuthor
#7 rules_sort_weight-372328.patch1.11 KBaaronbauman
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch rules_sort_weight-372328.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Component:User Interface» User interface
Status:Active» Postponed

>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..

Version:6.x-1.x-dev» 7.x-2.x-dev
Status:Postponed» Active

Bumping to 7.x.

Status:Active» Closed (won't fix)

We cannot rely on the DB for this, we would have to manually code this. Thus for now, won't fix.

Is 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.

Status:Closed (won't fix)» Postponed (maintainer needs more info)
Issue tags:+ux

>>>>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?

Just 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?

Component:User interface» User Interface
Status:Postponed (maintainer needs more info)» Needs review
StatusFileSize
new1.11 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch rules_sort_weight-372328.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I 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.

Status:Needs review» Needs work

The last submitted patch, rules_sort_weight-372328.patch, failed testing.

Any update on this?

The patch in #7 does what it says, even though testbot doesn't like it.
May need a re-roll against latest dev.

Re #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.

I 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.

I realize that a rule can be triggered by multiple events; so I see that it does not really make sense to sort by event.

Not 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.

The 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.

var $activeRulesTable=jQuery(".rules-overview-table").first();var $segmentedTable=$activeRulesTable.clone();$segmentedTable.find("tbody").html(" ");var $cssSample=jQuery("#rules-admin-reaction-overview").find("th");var bgColor=$cssSample.css("background");var color=$cssSample.css("color");var $ruleRows=$activeRulesTable.find("tbody tr");var allEvents=[];$ruleRows.each(function(){var e=jQuery(this);var t=e.find(".rules-element-content-group").first().html();t=t.match(/[.]*Weight: ([-0-9]*)/);e.attr("data-weight",t[1]);var n=e.find("td:nth-child(2)").html();if(n){n=n.split(", ");jQuery.each(n,function(t,r){r=r.replace(/ /g,"-").toLowerCase();if(jQuery.inArray(r,allEvents)==-1){allEvents.push(r)}e.addClass(r);e.removeClass("even odd");if(n.length>1){e.addClass("multiple-events");e.find("td:nth-child(2)").html(e.find("td:nth-child(2)").html().replace(/, /g,"<br>"))}else{e.find("td:nth-child(2)").html("")}})}});allEvents.sort();jQuery.each(allEvents,function(e,t){var n="<tr>"+'<td colspan="8" style="text-transform:capitalize;color:'+color+";background:"+bgColor+';font-weight:bold;">'+t.replace(/-/g," ")+"</td>"+"</tr>";jQuery(n).appendTo($segmentedTable.find("tbody"));var r=$ruleRows.filter("."+t).clone();r.sort(function(e,t){var n=parseInt(jQuery(e).attr("data-weight"));var r=parseInt(jQuery(t).attr("data-weight"));return n<r?-1:n>r?1:0});r.filter(function(e){return(e+1)%2==0}).addClass("even");$segmentedTable.find("tbody").append(r)});$activeRulesTable.replaceWith($segmentedTable)

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.