Skip to content

Commit 4a3fbdb

Browse files
committed
Fixed unwanted behaviour in fetching statistics
1 parent 2987bde commit 4a3fbdb

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/main/java/com/codeboy/service/VulnerabilityService.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.util.ArrayList;
1111
import java.util.HashMap;
12+
import java.util.LinkedHashMap;
1213
import java.util.List;
1314

1415
public class VulnerabilityService {
@@ -22,7 +23,7 @@ public VulnerabilityService() {
2223

2324
public HashMap<String, Integer> getStatistics() {
2425
HashMap<String, Integer> statistics = this.vulnerabilityRepository.fetchStatistics();
25-
return statistics;
26+
return this.prepareStats(statistics);
2627
}
2728

2829
public VulnerabilityDto getById(Integer id) {
@@ -45,4 +46,18 @@ public List<VulnerabilityDto> getAll() {
4546
}
4647
return dtos;
4748
}
49+
50+
private HashMap<String, Integer> prepareStats(HashMap<String, Integer> statistics) {
51+
Integer high = statistics.getOrDefault("High", 0);
52+
Integer medium = statistics.getOrDefault("Medium", 0);
53+
Integer low = statistics.getOrDefault("Low", 0);
54+
55+
return new LinkedHashMap<>() {
56+
{
57+
put("High", high);
58+
put("Medium", medium);
59+
put("Low", low);
60+
}
61+
};
62+
}
4863
}

src/main/resources/css/style.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ input:checked + .slider::before {
311311
color: var(--clr-dark);
312312
}
313313

314-
315314
/* Show button */
316315
.sidebar-show {
317316
position: fixed;
@@ -349,13 +348,22 @@ body {
349348
/* ============================== */
350349
.statistics-container {
351350
display: flex;
351+
align-content: flex-start;
352352
justify-content: center;
353353
}
354354

355355
.statistics {
356356
padding: 10px;
357357
}
358358

359+
.statistics > ol {
360+
display: table;
361+
}
362+
363+
.statistics > ol > li {
364+
display: table-row;
365+
}
366+
359367
/* ============================== */
360368
/* BUTTON STYLES */
361369
/* ============================== */
@@ -416,6 +424,15 @@ li:nth-child(even) {
416424
background-color: var(--clr-light);
417425
}
418426

427+
.statistics-container > .statistics > li {
428+
display: inline-block;
429+
}
430+
431+
.recent-files > li:hover {
432+
color: var(--clr-primary-hover);
433+
font-weight: bold;
434+
}
435+
419436
/* ============================== */
420437
/* DARK MODE */
421438
/* ============================== */

src/main/resources/js/script.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ function handleFileProcessing() {
1717

1818
function handleFileSelection(filePath) {
1919
try {
20-
const result = processFile(filePath);
21-
// displayStatistics(result);
20+
processFile(filePath);
21+
goTo('analytics.html');
2222
} catch (error) {
2323
console.error(error);
2424
}
@@ -27,6 +27,7 @@ function handleFileSelection(filePath) {
2727
function displayStatistics(statistics) {
2828
let statisticsList = document.getElementById("statistics");
2929
statisticsList.innerHTML = "";
30+
3031
Object.entries(statistics).forEach(([key, value]) => {
3132
let li = document.createElement("li");
3233
li.textContent = `${key}: ${value}`

0 commit comments

Comments
 (0)