Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2013 08:53
Show Gist options
  • Save anonymous/7925024 to your computer and use it in GitHub Desktop.
Save anonymous/7925024 to your computer and use it in GitHub Desktop.
Simple Javascript for JQL History as provided by Rnejith V in https://answers.atlassian.com/questions/138938/what-happened-with-search-history
<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) + '">' + display + '</a></li>';
});
var historyBlock = '<nav class="aui-navgroup aui-navgroup-vertical"><div id="jql-history-panel"><div class="aui-nav-heading"><strong>JQL History</strong></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 lastJql = history[0];
if(lastJql != currJql){
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