Skip to content

Instantly share code, notes, and snippets.

@regstuff
Forked from dodok1/gist:7925037
Created December 22, 2019 15:19
Show Gist options
  • Save regstuff/d0e2b928008d94fd7f7e76ed33f3250c to your computer and use it in GitHub Desktop.
Save regstuff/d0e2b928008d94fd7f7e76ed33f3250c to your computer and use it in GitHub Desktop.
Improved ordering and full JQL as tooltip
<script type='text/javascript'>
var refreshJqlHistoryPane = function() {
var localHistory = localStorage.getItem('jqlHistory');
if(localHistory){
var history = JSON.parse(localHistory);
var historyEntries = history.map(function(jql){
var display = jql;
if(display.length > 25){
display = display.substr(0,22) + "...";
}
return '<li><a href="'+ AJS.contextPath() + '/issues/?jql=' + encodeURIComponent(jql) + '" title="' + AJS.escapeHtml(jql) + '">' + display + '</a></li>';
});
var historyBlock = '<nav class="aui-navgroup aui-navgroup-vertical"><div id="jql-history-panel"><div class="aui-nav-heading">JQL History</div>' +
'<ul class="aui-nav">' +
historyEntries.join("") + '</ul></div></nav>';
if(AJS.$('#jql-history-panel')){
AJS.$('#jql-history-panel').remove();
}
AJS.$(AJS.$('.filter-panel-section')[0]).after(historyBlock);
}
}
var handleJqlSearch = function(){
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(){
var currJql = AJS.$('#advanced-search').val();
if(null != currJql && currJql !== "")
{
var rawdata = localStorage.getItem('jqlHistory');
var history;
if(rawdata){
history = JSON.parse(rawdata);
var match = -1;
while( (match = history.indexOf(currJql)) > -1 ) history.splice(match, 1);
history.unshift(currJql)
if(history.length > 10) history.pop();
}
else{
history = new Array();
history.push(currJql);
}
localStorage.setItem('jqlHistory', JSON.stringify(history));
}
refreshJqlHistoryPane();
});
}
AJS.$(document).ready(function() {
if(AJS.$('#advanced-search')) {
handleJqlSearch();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment