Skip to content

Commit

Permalink
chg: [website] Various improvements to the main page.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Dec 31, 2024
1 parent b8fec62 commit dffc041
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
6 changes: 4 additions & 2 deletions website/web/static/js/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ function drawBarChartHomePage(sightings, chartDivId, title, backgroundColor) {
});
}


function drawVulnerabilityTable(sightings, containerId) {
const container = document.getElementById(containerId);

// Remove any existing table
container.innerHTML = '';

// Process data into a structured format
const processedData = {};
const vulnerabilities = new Map(); // Map to store total sightings for sorting
Expand Down Expand Up @@ -293,7 +295,7 @@ function drawVulnerabilityTable(sightings, containerId) {
const vulnCell = document.createElement('td');
const vulnLink = document.createElement('a');
vulnLink.href = `/vuln/${vuln}`;
vulnLink.textContent = vuln;
vulnLink.textContent = vuln.toUpperCase(); // Convert vulnerability ID to uppercase
vulnLink.style.textDecoration = 'none'; // Optional: Remove underline
vulnCell.appendChild(vulnLink);
row.appendChild(vulnCell);
Expand Down
19 changes: 19 additions & 0 deletions website/web/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ function getMonday(date) {
return d;
}

function getWeekNumber(date) {
// Clone the date to avoid modifying the original
const currentDate = new Date(date);

// Set the first day of the week to Monday
currentDate.setHours(0, 0, 0, 0);

// Move to the nearest Thursday (to account for ISO 8601 standard)
currentDate.setDate(currentDate.getDate() + (4 - (currentDate.getDay() || 7)));

// Calculate the year start
const yearStart = new Date(currentDate.getFullYear(), 0, 1);

// Calculate the ISO week number
const weekNumber = Math.ceil(((currentDate - yearStart) / 86400000 + 1) / 7);

return weekNumber;
}

// Function to add days to a date
function addDays(date, days) {
const result = new Date(date);
Expand Down
32 changes: 20 additions & 12 deletions website/web/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
<div class="d-flex flex-column">

{% if not vulnerability_id and not vendor and config.user_accounts %}
<div class="row pt-5 d-flex justify-content-end">
<div class="row pt-2">
<h4 id="weekNumber">Observations for the last week</h4>
</div>
<div class="row d-flex justify-content-end">
<div class="col-md text-center">
<div id="sightingsChartContainerSeen" class="chart-container-seen">
<canvas id="exploitedVulnsChartSeen" height="300"></canvas>
Expand All @@ -67,14 +70,6 @@
<a class="nav-link" id="sightings-tab" href="{{ url_for('sightings_bp.list_sightings') }}" aria-controls="sightings" aria-selected="false">Sightings</a>
</li>
</ul>
<!-- Add the form to the right -->
<form class="d-flex align-items-center">
<div class="input-group">
<span id="weekPicker" class="input-group-text bg-white border-end-0" title="Select a week to refresh the charts.">
{{ render_icon('calendar-event') }}
</span>
</div>
</form>
</div>
<div class="card-body">
<div class="tab-content" id="myTabContent">
Expand Down Expand Up @@ -107,14 +102,26 @@
</div>
</div>
</div>
<div class="row justify-content-between">

<div class="row">
<div class="col-md-auto ms-auto text-end"> <!-- Use col-md-auto and ms-auto for right alignment -->
<form>
<div class="input-group">
<span id="weekPicker" class="input-group-text bg-white border-end-0" title="Pick a time frame to refresh the charts.">
{{ render_icon('calendar-event') }}&nbsp;&nbsp;Pick a time frame
</span>
</div>
</form>
</div>
</div>

<div class="row mt-3 justify-content-between">
<h4>Evolution for the last month</h4>
<div class="col">
<div class="col" id="last-month-evolution">
<div id="vulnerabilityTable" style="overflow-x: auto; white-space: nowrap;"></div>
</div>
</div>
</div>

{% endif %}

{% if source %}
Expand Down Expand Up @@ -290,6 +297,7 @@ <h5>All the vulnerabilites related to {{vendor}} - {{product}}</h5>
loadSightings(formattedMonday, formattedNextSunday);
loadComments(formattedMonday, formattedNextSunday);
loadBundles(formattedMonday, formattedNextSunday);
document.getElementById("weekNumber").textContent = "Observations for the week "+getWeekNumber(formattedMonday)
}
},
});
Expand Down

0 comments on commit dffc041

Please sign in to comment.