Created
September 13, 2017 02:45
-
-
Save fabioelia/51a20acfc3ceab46536c057ef988e09f to your computer and use it in GitHub Desktop.
Add sorting to jira backlog view
This file contains hidden or 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
| (() => { | |
| const issueBlocks = $('.js-issue-list'); | |
| $(issueBlocks).map(function() { | |
| const issueBlock = this; | |
| let sortingRow = document.createElement('div'); | |
| sortingRow.innerHTML = `<div class="ghx-issue-content"> | |
| <div class="ghx-row"> | |
| <span class="ghx-type" data-sort="ghx-type" data-key="title" title="Issue Type"> | |
| IT | |
| </span> | |
| <div class="ghx-flags" style="vertical-align: initial"> | |
| <span class="ghx-priority" data-sort="ghx-priority" data-key="title" title="Priority"> | |
| P | |
| </span> | |
| </div> | |
| <div class="ghx-key" data-sort="ghx-key" title="Ticket #"> | |
| Ticket # | |
| </div> | |
| <div class="ghx-summary"> | |
| <span class="ghx-inner" data-sort="ghx-summary">Title</span> | |
| </div> | |
| </div> | |
| <div class="ghx-end ghx-row"> | |
| <span class="ghx-end"> | |
| <span data-sort="aui-label.ghx-label" data-key="data-epickey">Epic </span> | |
| <span data-sort="ghx-avatar-img" data-key="alt">A </span> | |
| <span data-sort="ghx-statistic-badge" >SP</span> | |
| </span> | |
| </div> | |
| </div>`; | |
| sortingRow.classList ='sorting js-issue ghx-issue-compact'; | |
| issueBlock.prepend(sortingRow); | |
| $(sortingRow).find('[data-sort]').on('click', function(event) { | |
| event.target.attributes['data-order'] = event.target.attributes['data-order'] || { value: 1}; | |
| const sortBy = event.target.attributes['data-sort'].value; | |
| const invert = event.target.attributes['data-order'].value || -1; | |
| const key = event.target.attributes['data-key'] ? event.target.attributes['data-key'].value : null; | |
| event.target.attributes['data-order'].value *= -1; | |
| issueBlock; | |
| const children = $(issueBlock).children('.js-issue:not(.sorting)'); | |
| children.sort(function(a,b) { | |
| const first = $(invert === 1 ? a : b).find(`.${sortBy}`); | |
| const second = $(invert === 1 ? b : a).find(`.${sortBy}`); | |
| if (key) { | |
| return (first.attr(key) || '').localeCompare((second.attr(key) || '')); | |
| } | |
| return first.text().localeCompare(second.text()); | |
| }); | |
| children.map(function(c) { | |
| issueBlock.appendChild(this); | |
| }); | |
| }) | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment