Skip to content

Commit

Permalink
chg: [website] Experiment a new switch checkbox to let the user choos…
Browse files Browse the repository at this point in the history
…e to only display sightings of type seen.
  • Loading branch information
cedricbonhomme committed Jan 24, 2025
1 parent 840a06a commit 9c90e15
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion vulnerabilitylookup/feeders/cvelistv5
Submodule cvelistv5 updated 382 files
2 changes: 1 addition & 1 deletion vulnerabilitylookup/feeders/fkie_nvd
Submodule fkie_nvd updated 335 files
2 changes: 1 addition & 1 deletion vulnerabilitylookup/feeders/github
Submodule github updated 221 files
2 changes: 1 addition & 1 deletion vulnerabilitylookup/feeders/vulnrichment
Submodule vulnrichment updated 418 files
44 changes: 37 additions & 7 deletions website/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ <h4 id="last-month-evolution">Evolution for the last month</h4>
oninput="handleSliderChange(this.value)">
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="switchSightingsType" checked>
<label class="form-check-label" for="switchSightingsType" id="switchSightingsTypeLabel">All sightings</label>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div id="vulnerabilityTable" class="table-responsive" style="overflow-x: auto; white-space: nowrap;">
<!-- Waiting spinner -->
Expand Down Expand Up @@ -197,21 +207,32 @@ <h4 id="last-month-evolution">Evolution for the last month</h4>
}

// Default minSightings value for the vulnerability table
let minSightings = 3;
// let minSightings = 3;

// Initial data load
loadVulns();
loadSightings(date_from, date_to); // One week
loadComments(getDateSinceToday(31), date_to); // One month
loadBundles(getDateSinceToday(31), date_to); // One month
updateVulnerabilityTable(getDateSinceToday(31), date_to, minSightings); // One month
updateVulnerabilityTable(getDateSinceToday(31), date_to); // One month

// Handle slider changes
document.getElementById("minSightings").oninput = function () {
minSightings = this.value; // Update minSightings
updateVulnerabilityTable(date_from, date_to, minSightings);
// minSightings = this.value; // Update minSightings
updateVulnerabilityTable(date_from, date_to);
};

const checkbox = document.getElementById('switchSightingsType');
checkbox.addEventListener('change', () => {
if (checkbox.checked) {
document.getElementById("switchSightingsTypeLabel").innerHTML = "All sightings";
} else {
document.getElementById("switchSightingsTypeLabel").innerHTML = "Only seen";
}
updateVulnerabilityTable(date_from, date_to);
});


// Handle week picker changes
flatpickr("#weekPicker", {
plugins: [new weekSelect()],
Expand All @@ -233,7 +254,7 @@ <h4 id="last-month-evolution">Evolution for the last month</h4>
loadSightings(date_from, date_to); // Selected week
loadComments(date_from, date_to); // Selected week
loadBundles(date_from, date_to); // Selected week
updateVulnerabilityTable(date_from, date_to, minSightings); // Selected week
updateVulnerabilityTable(date_from, date_to); // Selected week

// Update the header and reset filters
document.getElementById("weekNumber").textContent =
Expand Down Expand Up @@ -303,16 +324,25 @@ <h4 id="last-month-evolution">Evolution for the last month</h4>
});
};

async function updateVulnerabilityTable(date_from, date_to, minSightings) {
async function updateVulnerabilityTable(date_from, date_to) {
const url = "{{ url_for('apiv1.sighting_sightings_list') }}";
let allData = [];
let page = 1; // Start at page 1
const per_page = 1000;

minSightings = document.getElementById("minSightings").value;

allSightings = document.getElementById("switchSightingsType").checked;

try {
while (true) {
// Fetch data for the current page
const response = await fetch(`${url}?date_from=${date_from}&date_to=${date_to}&page=${page}&per_page=${per_page}`);
request = `${url}?date_from=${date_from}&date_to=${date_to}&page=${page}&per_page=${per_page}`;
if (allSightings === false) {
request = `${request}&type=seen`;
}
console.log(request);
const response = await fetch(request);
const result = await response.json();

if (result.metadata.count === 0) {
Expand Down

0 comments on commit 9c90e15

Please sign in to comment.