15

2

I've got a filter that returns all the cases in a given iteration. These cases have lots of sub-cases, and they are displayed with every case expanded, which takes up several screens of space. Is there a way to automatically collapse the tree so that only the top-level cases are shown?

Fog Creek Case FC1917611

flag

6 Answers

10

We have a case open to consider this feature for a future release. Please up-vote this question to show your support for adding this feature.


Right now, you can use BugMonkey. Install the plugin and then add the following code to the Javascript section for all users:

FogBugz 7.X

if( window.location.href.indexOf("pg=pgList") > 0 || window.location.href.indexOf("pgx=LF") > 0)
{
    $(".listToolbar nobr").prepend("<a href='javascript:void 0;' onclick='toggleAllHierarchies(); return false;'>Toggle Hierarchies</a>&nbsp;");
}

function toggleAllHierarchies()
{
    var rgTRs = $("#bugGrid tr");
    for (ix = 0; ix < rgTRs.length; ix++)
    {
        var oRow = rgTRs[ix];

        if ($("a.arrow", oRow).length > 0)
        {
            GridControl.toggleNode(oRow.uid);
        }
    }
}

FogBugz 8.X

if( window.location.href.indexOf("pg=pgList") > 0 || window.location.href.indexOf("pgx=LF") > 0)
{
    $('#listNav')
    .prepend('<a href="#">Toggle Hierarchies</a>&nbsp;|&nbsp;')
    .click(function() {
        var rgTRs = $("#bugGrid tr");
        for (ix = 0; ix < rgTRs.length; ix++)
        {
            var oRow = rgTRs[ix];

           if ($("a.arrow", oRow).length > 0)
           {
               GridControl.toggleNode(oRow.uid);
           }
        }
        return false;
    });
}

This will insert a "Toggle Hierarchies" link next to the "Outline View" and "Select Columns" actions (in FogBugz 7), or the "Save" and "More" actions (in FogBugz 8) in the upper-right corner of the list view page that should collapse/expand all the hierarchy cases in the current view.

link|flag
Is there any reason that selecting a filter from the Filters drop down does not send pg=pgList in the url? (It prevents this toggle from showing up in a freshly chosen filter) – Sergei Apr 26 2010 at 4:33
@Sergei I've updated the script to handle this. The case you're describing uses a short-form URL (pgx=LF) that tells FogBugz to load the specified filter (LF => Load Filter) instead of the usual pg=pgList. – db Apr 29 2010 at 14:28
1

It seems to have stopped working with FogBugz 8.0.

link|flag
I've updated my answer for FogBugz 8. – db Mar 11 at 16:34
1

The BugMonkey script would not work for me in version 8.0 either. I found another way to achieve the same thing presuming you are using a saved filter. Go to Manage Saved Filters, edit the filter and select the "Show only cases with no parent case" option. Cases with sub-cases still show with their expand arrow next to them.

link|flag
This isn't working for me? I have that "with no parent cases" option checked, but when I click the filter again they're all still there and expanded by default. – Peter Nov 16 2010 at 21:28
That's nice, but then the subcases are all grayed out. Of course it would still work, but it makes you think they're not in the filter. – Avi D Jan 13 2011 at 15:03
1

Just got this working in FB8, here is the code:

// http://fogbugz.stackexchange.com/questions/1046/is-there-a-way-to-bulk-collapse-all-of-the-cases-in-a-filter/1052#1052
if( window.location.href.indexOf("pg=pgList") > 0 || window.location.href.indexOf("pgx=LF") > 0 || $("#bugGrid" ) )
{
    $("#listNav").prepend("<a href='javascript:void 0;' onclick='toggleAllHierarchies(); return false;'>Collapse/Expand child cases</a> | ");
}

function toggleAllHierarchies()
{
    var rgTRs = $("#bugGrid tr");
    for (ix = 0; ix < rgTRs.length; ix++)
    {
        var oRow = rgTRs[ix];

        if ($("a.arrow", oRow).length > 0)
        {
            GridControl.toggleNode(oRow.uid);
        }
    }
}
link|flag
@Pete, thanks this is nice! Any reason it doesnt work in Chrome? (The prepend works a charm, but the link doesnt work - since the function is not recognized.) – Avi D Jan 16 2011 at 7:07
nm, I hacked it up to work with some jquery: $("#collapseLink").click(function() {...}); inside the if statement... Don't know why this wouldnt work in GC, though... – Avi D Jan 16 2011 at 7:37
1 
@Avi_D: Can you add the entire new function. I've got the same problem as you had. – Kaboing Jan 20 2011 at 15:19
What version of Chrome are you using? It works a treat for me in Version 8. Also check your other JS, any errors in any of it and it will prevent the lot from running. – Pete Duncanson Jan 24 2011 at 13:31
1

function expand_all() {
  $("#bugGrid tr").each(function(idx, row) {
    var arrows = $("a.arrow[exp=0]", row);
    if (row.uid && arrows.length > 0) {
      GridControl.toggleNode(row.uid);      
    }
  });
  return false;
}
function collapse_all() {
  $("#bugGrid tr").each(function(idx, row) {
    var arrows = $("a.arrow[exp=1]", row);
    if (row.uid && arrows.length > 0) {
      GridControl.toggleNode(row.uid);      
    }
  });
  return false;
}
if( window.location.href.indexOf("pg=pgList") > 0 || window.location.href.indexOf("pgx=LF") > 0 || $("#bugGrid" ) )
{
  $("#listNav").prepend("<a id=\"collapse_all\" href=\"#\">Collapse All</a> | <a id=\"expand_all\" href=\"#\">Expand All</a> | ");
}
$("#collapse_all").click(collapse_all);
$("#expand_all").click(expand_all);
link|flag
For me (using Chrome) this collapses the first arrow only. – Michel de Ruiter Mar 21 at 9:55
@Michel, sorry about that. I had fixed it on my site, and forgotten to update it here. This version is better anyhow as it properly calls toggle instead of collapse/update (which got the arrow graphics out of sync). This works great for me. – Trey Stout Mar 21 at 22:09
Works now! One more thing: if the very first case is a tree, it is not collapsed/expanded...?! – Michel de Ruiter Mar 22 at 8:59
I'll try making a filter where the first item is a tree. That's fairly weird. Maybe the first item has some special markup that causes the matching to miss. – Trey Stout Mar 22 at 15:59
0

Nice! Thanks, works a treat.

link|flag

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.