In a previous post I've explained how to create a Jira plugin for a unique issue ID across the projects. I'd recommend reading that post before this one. The issue ID, a unique one is useful (if that is your requirement, of course) but would be even more useful if you could search for that.
According to the documentation the CustomFieldSearcher interface defines IssueSearcher that's usable by the custom field objects. IssueSearcher in turn is responsible for all search related activities in the Issue Navigator.
Like pre-configured custom field implementations, you will find several implementations packaged out of the box for searchers. More often than not you may have to just pick which searcher implementation suits the data type of your custom field. In this case, our unique issue ID custom field is a number, and so we can pick either ExactNumberSearcher or a NumberRangeSearcher. I picked the latter.
So to add the search functionality there are two pieces to it:
- define it in the the descriptor
- add views so that search fields show up for searching, and also for viewing the search criteria.
Plugin Descriptor
Only the additions made for the search functionality is displayed below, for the actual custom field definition please refer to the previous post.
<atlassian-plugin>
...
...
<customfield-searcher key="uniqueIssueIdSearcher" name="Unique Issue Id Searcher"
class="com.atlassian.jira.issue.customfields.searchers.NumberRangeSearcher">
<description>Allows search for unique issue ID.</description>
<resource type="velocity" name="view"
location="templates/plugins/fields/view-searcher/view-searcher-number-range.vm" />
<resource type="velocity" name="search"
location="templates/plugins/fields/edit-searcher/search-number-range.vm" />
<valid-customfield-type package="com.suryasuravarapu.jira.plugins" key="uniqueIssueId" />
</customfield-searcher>
</atlassian-plugin>
A searcher is defined with NumberRangeSearcher. Resources locations are provided for view and search. The last line specifies what are the valid custom field types for this searcher. You may add one ore more types here.
Velocity Templates
The two velocity templates needed for search and view are provided below. They are self-explanatory.
search-number-range.vm
#searcherEditHeader (${customField.id} ${customField.name})
<span class="lead">$i18n.getText('common.words.between')</span>
<input type="text"
name="${customField.id}:greaterThan"
id="${customField.id}:greaterThan"
class="smallInputField"
value="$!value.getFirstValueForKey('greaterThan')"
/>
$i18n.getText('common.words.and')
<input type="text"
name="${customField.id}:lessThan"
id="${customField.id}:lessThan"
class="smallInputField"
value="$!value.getFirstValueForKey('lessThan')"
/>
#searcherEditFooter (${customField.id} $customField.description)
view-searcher-number.vm
#searcherHeader ($customField)
<span class="lead">$i18n.getText('common.words.between')</span>
#if ($value.getFirstValueForKey('greaterThan'))
$value.getFirstValueForKey('greaterThan')
#else
${i18n.getText("common.filters.any.value")}
#end
${i18n.getText("common.words.and")}
#if ($value.getFirstValueForKey('lessThan'))
$value.getFirstValueForKey('lessThan')
#else
${i18n.getText("common.filters.any.value")}
#end
#searcherFooter ($customField)
Note: Just make sure that you select your new searcher template in the custom field you defined in the Jira Administration section.
Follow on Twitter