Friday, September 9, 2011

Collapse/Expand All Comments in JIRA Issue Details Screen

In JIRA, when you are looking at an issue, it often shows all the comments expanded. This would be OK if there are only a couple of comments and they are compact, but often comments are added to JIRA via emails and each email contains the whole thread and thus it makes very hard to read/browse through the comments as they all seem to run together with same text repeated in successive comments. For example, you would often see comments displayed like this (http://jira.atlassian.com/browse/JRA-12569):You could collapse all the comments and JIRA will automatically show the first line of the comment which makes it very easy to look at all the comments as whole and improves the readability of the issue. For example, the above page is displayed like below when all the comments are collapsed:Problem:

You would have to collapse each comment one by one as there is no single button that can collapse all the comments in one click. This could be quite tedious if there are many comments in an issue. I believe if the JIRA instance is integrated with Confluence, it provides this feature but our instance of JIRA is stand-alone and that is why I came up with this technique.

Solution:

Use the following steps to install two macros that allow you to collapse/expand all the comments in JIRA window with a single click:

  1. Launch Internet Explorer (IE)
  2. While in the IE window, type “about:blank” in the address bar.
  3. Press Ctrl+D key combination to bring up the Add a Favorite dialog box.
  4. In this dialog box, select the “Favorites Bar” from the “Create in” drop-down and type “Collapse JIRA Comments” in the “Name” box and click on the “Add” button.

  5. Turn on the “Favorites Bar” if it is not already on. Right-click on the toolbar area and select “Favorites Bar”.
  6. In the “Favorites Bar”, you should now see a new icon by name “Collapse JIRA Comments” as shown below:

  7. Right-click on this icon and click on Properties command to bring up the link properties dialog box as shown below:

  8. In this dialog box, while in the “Web Document” tab, enter the following javascript code in the box titled “URL”:

javascript:if(!window._ctwixi){function _ctwixi(){jQuery(“.verbose”).each(function(){if (jQuery(this).css(“display”) == “block”) jQuery(this).find(“.twixi”).click();});return;}}_ctwixi();

  1. Click on the “Change Icon” button to bring up the “Change Icon” dialog box as shown below:

  2. In this dialog box, click on the “Browse” button and select the shell32.dll and click “Open” as shown below:

  3. Select the collapsed folder icon in the icons shown in the “Change Icon” dialog box and click OK as shown below:

  4. Click on “OK” in the “Collapse JIRA Comments Properties” dialog box.
  5. Click on “Yes” in the following warning dialog box:

  6. Navigate to any JIRA issue page and click on this button in the favorites bar to collapse all the comments.
  7. Repeat the above steps to add a button to “Expand JIRA Comments” using the following javascript code:

javascript:if(!window._etwixi){function _etwixi(){jQuery(“.concise”).each(function(){if (jQuery(this).css(“display”) == “block”) jQuery(this).find(“.twixi”).click();});return;}}_etwixi();

Conclusion:

You should now have two buttons in your IE Favorites Bar that you could use to collapse/expand JIRA comments while looking at a JIRA issue.

As you can see, I am using the jQuery in my javascript snippets, this works because JIRA already uses jQuery and hence we do not have to worry about making sure jQuery is already loaded.

Thanks for reading and look forward to your comments.

1 comment:

Arianna Fabbri said...

Hi,
I've tried your script but it's not working on Jira 6.3.8. Is something changed?

Thank you
Regards
Arianna