Created
December 12, 2013 08:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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