Release WiFiTrip format v2.0.0
This commit is contained in:
+161
-2
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
|
||||
from .config import (
|
||||
RECENT_SESSIONS_LIMIT,
|
||||
SESSIONS_PAGE_LIMIT,
|
||||
)
|
||||
|
||||
from .utils import (
|
||||
@@ -807,8 +808,21 @@ def generate_dashboard(
|
||||
def generate_capture_sessions(
|
||||
conn,
|
||||
context=None,
|
||||
sessions_page_limit=None,
|
||||
):
|
||||
|
||||
if sessions_page_limit is None:
|
||||
display_limit = SESSIONS_PAGE_LIMIT
|
||||
elif str(sessions_page_limit).lower() == "all":
|
||||
display_limit = "all"
|
||||
else:
|
||||
try:
|
||||
display_limit = int(sessions_page_limit)
|
||||
if display_limit <= 0:
|
||||
raise ValueError
|
||||
except (TypeError, ValueError):
|
||||
display_limit = SESSIONS_PAGE_LIMIT
|
||||
|
||||
sessions = all_sessions(
|
||||
conn
|
||||
)
|
||||
@@ -957,7 +971,7 @@ Total sessions: <b>{len(sessions)}</b>
|
||||
</article>
|
||||
""")
|
||||
|
||||
html += """
|
||||
html += f"""
|
||||
|
||||
<div class="session-list-toolbar">
|
||||
|
||||
@@ -981,12 +995,40 @@ Total sessions: <b>{len(sessions)}</b>
|
||||
↓
|
||||
</button>
|
||||
|
||||
<label for="session-limit">
|
||||
Show:
|
||||
</label>
|
||||
|
||||
<select id="session-limit">
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
<option value="500">500</option>
|
||||
<option value="all">All</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
id="session-custom-limit"
|
||||
min="1"
|
||||
step="1"
|
||||
placeholder="Number"
|
||||
aria-label="Custom number of sessions"
|
||||
style="width: 100px;"
|
||||
>
|
||||
|
||||
<span id="session-count"></span>
|
||||
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="session-list"
|
||||
id="session-list"
|
||||
data-sort-direction="desc"
|
||||
data-display-limit="{display_limit}"
|
||||
data-default-limit="{SESSIONS_PAGE_LIMIT}"
|
||||
>
|
||||
"""
|
||||
|
||||
@@ -1002,13 +1044,83 @@ Total sessions: <b>{len(sessions)}</b>
|
||||
const list = document.getElementById("session-list");
|
||||
const sortSelect = document.getElementById("session-sort");
|
||||
const directionButton = document.getElementById("session-sort-direction");
|
||||
const limitSelect = document.getElementById("session-limit");
|
||||
const customLimitInput = document.getElementById("session-custom-limit");
|
||||
const sessionCount = document.getElementById("session-count");
|
||||
|
||||
if (!list || !sortSelect || !directionButton) {
|
||||
if (
|
||||
!list ||
|
||||
!sortSelect ||
|
||||
!directionButton ||
|
||||
!limitSelect ||
|
||||
!customLimitInput ||
|
||||
!sessionCount
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
let descending = true;
|
||||
|
||||
const defaultLimit = Number(list.dataset.defaultLimit) || 20;
|
||||
const initialLimit = list.dataset.displayLimit;
|
||||
const predefinedLimits = ["10", "20", "50", "100", "500", "all"];
|
||||
|
||||
function getDisplayLimit() {
|
||||
|
||||
if (limitSelect.value === "all") {
|
||||
return "all";
|
||||
}
|
||||
|
||||
if (limitSelect.value === "custom") {
|
||||
const value = Number(customLimitInput.value);
|
||||
|
||||
if (
|
||||
!Number.isInteger(value) ||
|
||||
value <= 0
|
||||
) {
|
||||
return defaultLimit;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
return Number(limitSelect.value) || defaultLimit;
|
||||
}
|
||||
|
||||
function updateUrl() {
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const limit = getDisplayLimit();
|
||||
|
||||
params.set("limit", String(limit));
|
||||
|
||||
const query = params.toString();
|
||||
const newUrl = window.location.pathname +
|
||||
(query ? "?" + query : "") +
|
||||
window.location.hash;
|
||||
|
||||
window.history.replaceState({}, "", newUrl);
|
||||
}
|
||||
|
||||
function applyDisplayLimit() {
|
||||
|
||||
const cards = Array.from(
|
||||
list.querySelectorAll(".session-compact-card")
|
||||
);
|
||||
|
||||
const limit = getDisplayLimit();
|
||||
const visibleCount = limit === "all"
|
||||
? cards.length
|
||||
: Math.min(cards.length, limit);
|
||||
|
||||
cards.forEach(function (card, index) {
|
||||
card.style.display = index >= visibleCount ? "none" : "";
|
||||
});
|
||||
|
||||
sessionCount.textContent =
|
||||
"Showing " + visibleCount + " of " + cards.length;
|
||||
}
|
||||
|
||||
function sortSessions() {
|
||||
|
||||
const sortBy = sortSelect.value;
|
||||
@@ -1071,6 +1183,8 @@ Total sessions: <b>{len(sessions)}</b>
|
||||
directionButton.textContent = descending ? "↓" : "↑";
|
||||
|
||||
list.dataset.sortDirection = descending ? "desc" : "asc";
|
||||
|
||||
applyDisplayLimit();
|
||||
}
|
||||
|
||||
sortSelect.addEventListener("change", function () {
|
||||
@@ -1087,6 +1201,51 @@ Total sessions: <b>{len(sessions)}</b>
|
||||
sortSessions();
|
||||
});
|
||||
|
||||
limitSelect.addEventListener("change", function () {
|
||||
|
||||
if (limitSelect.value !== "custom") {
|
||||
customLimitInput.value = "";
|
||||
}
|
||||
|
||||
if (limitSelect.value === "custom") {
|
||||
customLimitInput.focus();
|
||||
}
|
||||
|
||||
applyDisplayLimit();
|
||||
updateUrl();
|
||||
});
|
||||
|
||||
customLimitInput.addEventListener("input", function () {
|
||||
|
||||
limitSelect.value = "custom";
|
||||
|
||||
const value = Number(customLimitInput.value);
|
||||
|
||||
if (
|
||||
Number.isInteger(value) &&
|
||||
value > 0
|
||||
) {
|
||||
applyDisplayLimit();
|
||||
updateUrl();
|
||||
} else {
|
||||
applyDisplayLimit();
|
||||
}
|
||||
});
|
||||
|
||||
if (initialLimit === "all") {
|
||||
|
||||
limitSelect.value = "all";
|
||||
|
||||
} else if (predefinedLimits.includes(initialLimit)) {
|
||||
|
||||
limitSelect.value = initialLimit;
|
||||
|
||||
} else {
|
||||
|
||||
limitSelect.value = "custom";
|
||||
customLimitInput.value = initialLimit;
|
||||
}
|
||||
|
||||
sortSessions();
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user