Skip to content

Commit 409d241

Browse files
author
Antti Huovila
committed
Cleaned up a function
Signed-off-by: Antti Huovila <anthu456@student.liu.se>
1 parent 0af308b commit 409d241

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

src/i18n/locales/en.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@
362362
"authenticated": "Authenticated",
363363
"authors": "Authors",
364364
"bom": "BOM",
365+
"bom_deleted": "BOM successfully deleted",
365366
"bom_format": "BOM Format",
366367
"bom_uploaded": "BOM uploaded",
367368
"browse": "Browse",
@@ -493,6 +494,7 @@
493494
"data": "Data",
494495
"dates": "Dates",
495496
"delete": "Delete",
497+
"delete_bom_tooltip": "Delete BOM from project.",
496498
"delete_license_group": "Delete License Group",
497499
"delete_policy": "Delete Policy",
498500
"delete_selected": "Delete selected items",
@@ -593,6 +595,7 @@
593595
"matrix": "Matrix",
594596
"metric_refresh_requested": "A refresh has been requested. Metrics will be updated when the refresh task has completed.",
595597
"name": "Name",
598+
"no_bom_available": "No BOM exists for project",
596599
"no_file_chosen": "No file chosen",
597600
"non_vulnerable": "Non Vulnerable",
598601
"not_affected": "Not Affected",
@@ -780,11 +783,9 @@
780783
"references": "References",
781784
"reindex": "Rebuild index(es)",
782785
"rejected": "Rejected",
783-
"remove_component": "Remove Component",
784786
"remove_bom": "Remove BOM",
787+
"remove_component": "Remove Component",
785788
"removing_dependencies": "Removing dependencies, {n} left",
786-
"bom_deleted": "BOM successfully deleted",
787-
"no_bom_available": "No BOM exists for project",
788789
"reported_by": "Reported By",
789790
"required_component_identifier": "A component identifier is required",
790791
"required_component_name": "The component name is required",
@@ -863,7 +864,6 @@
863864
"upload": "Upload",
864865
"upload_bom": "Upload BOM",
865866
"upload_bom_tooltip": "Upload BOM, all components will be analyzed for vulnerabilities",
866-
"delete_bom_tooltip": "Delete BOM from project.",
867867
"upload_vex": "Upload VEX",
868868
"url": "URL",
869869
"urls": "URLs",

src/views/portfolio/projects/ProjectComponents.vue

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
v-permission="PERMISSIONS.PORTFOLIO_MANAGEMENT"
4141
style="margin-left: 0px"
4242
>
43-
<span class="fa fa-minus"></span> {{ $t('message.remove_bom') }}
43+
<span class="fa fa-minus"></span> {{ $t('message.remove_bom') }}
4444
</b-button>
4545
<b-dropdown
4646
variant="outline-primary"
@@ -124,14 +124,15 @@
124124
:uuid="this.uuid"
125125
v-on:refreshTable="refreshTable"
126126
/>
127-
<b-modal
128-
ref="confirmModal"
129-
title="Confirm Removal"
130-
>
127+
<b-modal ref="confirmModal" title="Confirm Removal">
131128
<p>Are you sure you want to remove the BOM and all its components?</p>
132129
<div slot="modal-footer">
133-
<b-button variant="outline-primary" @click="$refs.confirmModal.hide()">Cancel</b-button>
134-
<b-button variant="outline-danger" @click="handleRemoveBom">Remove</b-button>
130+
<b-button variant="outline-primary" @click="$refs.confirmModal.hide()"
131+
>Cancel</b-button
132+
>
133+
<b-button variant="outline-danger" @click="handleRemoveBom"
134+
>Remove</b-button
135+
>
135136
</div>
136137
</b-modal>
137138
</div>
@@ -429,42 +430,44 @@ export default {
429430
try {
430431
let allDependencies = [];
431432
let page = 1;
432-
let pageSize = 100; // Adjust based on API limits
433-
//Step 1: Fetch all dependencies and handling pagination
433+
let pageSize = 100;
434434
while (true) {
435-
let response = await this.axios.get(`${getDependenciesUrl}?page=${page}&size=${pageSize}`);
435+
let response = await this.axios.get(
436+
`${getDependenciesUrl}?page=${page}&size=${pageSize}`,
437+
);
436438
let dependencies = response.data;
437439
if (!dependencies || dependencies.length === 0) break;
438440
allDependencies = allDependencies.concat(dependencies);
439441
page++;
440442
}
441-
//Step 2: Delete dependencies in batches
442443
let batchSize = 50;
443444
let lengthAllDependencies = allDependencies.length;
444445
if (lengthAllDependencies !== 0) {
445-
for (let i = 0; i < allDependencies.length; i += batchSize) {
446-
let batch = allDependencies.slice(i, i + batchSize);
447-
this.$toastr.s(this.$t("message.removing_dependencies", { n: lengthAllDependencies }));
448-
lengthAllDependencies -= batch.length;
449-
let deletePromises = batch.map(dep =>
450-
this.axios.delete(`${this.$api.BASE_URL}/${this.$api.URL_COMPONENT}/${dep.uuid}`)
451-
);
452-
await Promise.all(deletePromises);
453-
this.$refs.table.refresh({ silent: true });
446+
for (let i = 0; i < allDependencies.length; i += batchSize) {
447+
let batch = allDependencies.slice(i, i + batchSize);
448+
this.$toastr.s(
449+
this.$t('message.removing_dependencies', {
450+
n: lengthAllDependencies,
451+
}),
452+
);
453+
lengthAllDependencies -= batch.length;
454+
let deletePromises = batch.map((dep) =>
455+
this.axios.delete(
456+
`${this.$api.BASE_URL}/${this.$api.URL_COMPONENT}/${dep.uuid}`,
457+
),
458+
);
459+
await Promise.all(deletePromises);
460+
this.$refs.table.refresh({ silent: true });
461+
}
462+
await this.axios.delete(deleteBomUrl);
463+
this.$toastr.s(this.$t('message.bom_deleted'));
464+
this.$refs.table.removeAll();
465+
await this.axios.get(`/api/v1/metrics/project/${this.uuid}/refresh`);
466+
} else {
467+
this.$toastr.w(this.$t('message.no_bom_available'));
454468
}
455-
//Step 3: Delete the BOM after all its components are removed
456-
await this.axios.delete(deleteBomUrl);
457-
this.$toastr.s(this.$t("message.bom_deleted"));
458-
//Step 4: Refresh the table
459-
this.$refs.table.removeAll();
460-
//Step 5: Refresh the metrics
461-
await this.axios.get(`/api/v1/metrics/project/${this.uuid}/refresh`);
462-
}
463-
else {
464-
this.$toastr.w(this.$t("message.no_bom_available"));
465-
}
466469
} catch (error) {
467-
this.$toastr.w(this.$t("condition.unsuccessful_action"));
470+
this.$toastr.w(this.$t('condition.unsuccessful_action'));
468471
}
469472
},
470473
downloadBom: function (data) {

0 commit comments

Comments
 (0)