Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions debug_toolbar/static/debug_toolbar/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,18 @@
#djDebug .djdt-highlighted {
background-color: lightgrey;
}
@keyframes flash-new {
from {
background-color: green;
}
to {
background-color: inherit;
}
}
#djDebug .flash-new {
animation: flash-new 1s;
}

.djdt-hidden {
display: none;
}
86 changes: 74 additions & 12 deletions debug_toolbar/static/debug_toolbar/js/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,79 @@ import { $$, ajaxForm } from "./utils.js";

const djDebug = document.getElementById("djDebug");

function difference(setA, setB) {
const _difference = new Set(setA);
for (const elem of setB) {
_difference.delete(elem);
}
return _difference;
}

/**
* Create an array of dataset properties from a NodeList.
* @param nodes
* @param key
* @returns {[]}
*/
function pluckData(nodes, key) {
const data = [];
nodes.forEach(function (obj) {
data.push(obj.dataset[key]);
});
return data;
}

function refreshHistory() {
const formTarget = djDebug.querySelector(".refreshHistory");
const container = document.getElementById("djdtHistoryRequests");
const oldIds = new Set(
pluckData(container.querySelectorAll("tr[data-store-id]"), "storeId")
);

return ajaxForm(formTarget)
.then(function (data) {
// Remove existing rows first then re-populate with new data
container
.querySelectorAll("tr[data-store-id]")
.forEach(function (node) {
node.remove();
});
data.requests.forEach(function (request) {
container.innerHTML = request.content + container.innerHTML;
});
})
.then(function () {
const allIds = new Set(
pluckData(
container.querySelectorAll("tr[data-store-id]"),
"storeId"
)
);
const newIds = difference(allIds, oldIds);
const lastRequestId = newIds.values().next().value;
return {
allIds,
newIds,
lastRequestId,
};
})
.then(function (refreshInfo) {
refreshInfo.newIds.forEach(function (newId) {
const row = container.querySelector(
`tr[data-store-id="${newId}"]`
);
row.classList.add("flash-new");
});
setTimeout(() => {
container
.querySelectorAll("tr[data-store-id]")
.forEach((row) => {
row.classList.remove("flash-new");
});
}, 2000);
});
}

$$.on(djDebug, "click", ".switchHistory", function (event) {
event.preventDefault();
const newStoreId = this.dataset.storeId;
Expand Down Expand Up @@ -36,16 +109,5 @@ $$.on(djDebug, "click", ".switchHistory", function (event) {

$$.on(djDebug, "click", ".refreshHistory", function (event) {
event.preventDefault();
const container = document.getElementById("djdtHistoryRequests");
ajaxForm(this).then(function (data) {
// Remove existing rows first then re-populate with new data
container
.querySelectorAll("tr[data-store-id]")
.forEach(function (node) {
node.remove();
});
data.requests.forEach(function (request) {
container.innerHTML = request.content + container.innerHTML;
});
});
refreshHistory();
});
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Next version
django-debug-toolbar can now use Django’s test settings tools, like
``@override_settings``, to reconfigure the toolbar during tests.
* Optimize rendering of SQL panel, saving about 30% of its run time.
* New records in history panel will flash green.

3.2.4 (2021-12-15)
------------------
Expand Down