Skip to content

Instantly share code, notes, and snippets.

@Juhlinus
Created September 10, 2019 11:27
Show Gist options
  • Save Juhlinus/ce178a328cdf88cb449c2c2030589b49 to your computer and use it in GitHub Desktop.
Save Juhlinus/ce178a328cdf88cb449c2c2030589b49 to your computer and use it in GitHub Desktop.
(function() {
if ($('.sort-queries-by-time').length == 0) {
$('.phpdebugbar-widgets-sqlqueries .phpdebugbar-widgets-status')
.append('<a class="sort-queries-by-time" style="padding: 2px 11px 2px 7px;margin-right: 5px;margin-top: -1px;border-radius: 5px;text-transform: uppercase;font-weight: bold;color: #ffffff;font-size: 11px;background: #f4645f;box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);float: right;line-height: 1.8em;">✌ Group</a>');
}
function groupBy(list, keyGetter) {
const map = new Map();
list.forEach((item) => {
const key = keyGetter(item);
const collection = map.get(key);
if (!collection) {
map.set(key, [item]);
} else {
collection.push(item);
}
});
return Array.from(map);
}
var type = null;
$(".sort-queries-by-time").off('click');
$(".sort-queries-by-time").click(function() {
var $this = $(this);
var items = $this.parent().parent().find('.phpdebugbar-widgets-list li').get();
const grouped = groupBy(items, (item) => {
if (item.classList.length !== 1) {
return item.classList[2]
}
return 'unique'
})
// clear the list and re-add sorted items on button click
$this.parent().parent().find(".phpdebugbar-widgets-list").empty();
grouped.forEach((group) => {
$this.parent().parent().find(".phpdebugbar-widgets-list").append(group[0] + '(' + group[1].length + ')')
group[1].forEach((element) => $this.parent().parent().find(".phpdebugbar-widgets-list").append(element))
})
});
}
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment