Last active
August 29, 2015 14:09
-
-
Save markreid/3c1de168832fa6ad89a8 to your computer and use it in GitHub Desktop.
quick-filter JIRA Agile view by assignee name
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
// quick filter jira agile view by assignee | |
(function(){ | |
var constants = { | |
ISSUE_CLASS: '.ghx-issue' | |
}; | |
var issuesLookup; | |
// querySelectorAll-to-array | |
var $ = function(selector){ | |
return nodeListToArray(document.querySelectorAll(selector)); | |
} | |
function bootstrap(){ | |
issuesLookup = buildIssuesLookup(); | |
injectStyles(); | |
buildFilterBox(); | |
} | |
function nodeListToArray(nodeList){ | |
var arr = []; | |
var nodeListLength = nodeList.length; | |
for(var i=0; i<nodeListLength; i++){ | |
arr.push(nodeList[i]); | |
} | |
return arr; | |
} | |
function buildIssuesLookup(){ | |
return $(constants.ISSUE_CLASS).map(function(el){ | |
var img = el.querySelector('.ghx-avatar img'); | |
return { | |
el: el, | |
assignee: img ? img.getAttribute('data-tooltip') : '' | |
}; | |
}); | |
} | |
function getFilteredIssueList(issues, str){ | |
return issues.filter(function(issue){ | |
return issue.assignee.match(new RegExp(str, 'i')); | |
}); | |
} | |
function enableFiltering(){ | |
document.body.classList.add('issue-filtering'); | |
$('.ghx-issue.showme').forEach(function(el){ | |
el.classList.remove('showme'); | |
}); | |
} | |
function disableFiltering(){ | |
document.body.classList.remove('issue-filtering'); | |
$('.ghx-issue.showme').forEach(function(el){ | |
el.classList.remove('showme'); | |
}); | |
} | |
function injectStyles(){ | |
var style = document.createElement('style'); | |
style.setAttribute('type', 'text/css'); | |
style.innerHTML = '.issue-filtering .ghx-issue{ display:none;} .ghx-issue.showme {display: block !important;} input#quick-user-filter{ border: 1px solid #ccc; border-radius: 2px; padding: 4px; }'; | |
document.body.appendChild(style); | |
} | |
function buildFilterBox(){ | |
var input = document.createElement('input'); | |
input.setAttribute('id', 'quick-user-filter'); | |
input.setAttribute('placeholder', 'user filter'); | |
input.addEventListener('keyup', function(evt){ | |
if(input.value === ''){ | |
disableFiltering(); | |
} else { | |
filterByName(input.value); | |
} | |
}); | |
var quickFilters = document.querySelector('#js-work-quickfilters'); | |
var firstQuickFilter = quickFilters.querySelector('dd'); | |
quickFilters.insertBefore(input, firstQuickFilter); | |
} | |
function filterByName(str){ | |
enableFiltering(); | |
var filteredIssues = getFilteredIssueList(issuesLookup, str); | |
filteredIssues.forEach(function(issue){ | |
issue.el.classList.add('showme'); | |
}); | |
} | |
bootstrap(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment