How to create a read-only "summary" version of a field, for display in space-constrained places like gadgets or search results.

Over-large fields

Some fields contain a lot of info. For instance, a Checklist for JIRA field (from our Checkboxes Plugin comparison):

 

When displayed as a filter column it looks passable:

 but within the Structure plugin's table it breaks completely:

Creating a summary field

What we want is a summarized view of a field, suitable for viewing in space-constrained places such as our Structure table, or a dashboard portlet.

The Script Runner plugin is excellent for this sort of thing. We define a new custom field, Milestone Status, of type Scripted Field:

Our new Milestone Status summary field will look like this:

It is intended to display well in Structure table rows:

The Milestone Status custom field's output is defined by the following Groovy code:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.commons.lang.StringEscapeUtils

def shortname(name) {
    switch (name) {
     case ~/Overview.*/: "Doc"; break
     case ~/.*User Stories.*/: "Stories"; break
     case ~/UX.*/: "UX"; break
     case ~/.*Tech Spec.*/: "Tech Spec"; break
     case ~/.*shirt.*/: "T-Shirt"; break
     case ~/.*prints.*/: "Sprints Scheduled"; break
     default: name; 
    }
}
cf = ComponentAccessor.customFieldManager.getCustomFieldObject(13803)
return issue.getCustomFieldValue(cf).collect { i->
    "<span style='color: " + (i.checked ? "red" : "grey") + "' " +
          "title='" +
        StringEscapeUtils.escapeHtml(i.name) + "'>"  + 
        (i.checked ? "☑" : "☐") + " " +
        StringEscapeUtils.escapeHtml(shortname(i.name)) +
        "</span>" ;
}.join(" ")

 

  • No labels