Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stoicadianaa committed Jun 7, 2024
1 parent af726cc commit 14f81fa
Show file tree
Hide file tree
Showing 25 changed files with 320 additions and 1,367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h3>Projects using this licence</h3>
@if (library.seeAllDirectLibraries) {
<ul>
@for (directLibrary of library.directLibraries; track $index) {
<li>{{directLibrary._id}}</li>
<li>{{directLibrary._id}}&#64;{{directLibrary.version}}</li>
}
</ul>
}
Expand All @@ -86,7 +86,7 @@ <h3>Projects using this licence</h3>
@if (library.seeAllIndirectLibraries) {
<ul>
@for (indirectLibrary of library.indirectLibraries; track $index) {
<li>{{indirectLibrary._id}}</li>
<li>{{indirectLibrary._id}}&#64;{{indirectLibrary.version}}</li>
}
</ul>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import {Component, Input, OnInit} from '@angular/core';
import { CommonModule } from '@angular/common';
import {Dependency, Project} from "@core/project";
import {LibraryInfo} from "@core/library";
import {Licence} from "@core/licence";
import {MatTableDataSource, MatTableModule} from "@angular/material/table";
import {OperationalRiskDependencies} from "../old-dependencies-table/old-dependencies-table";
import {LicenceRulesService} from "../../../../common/services/licence-rules.service";
import {animate, state, style, transition, trigger} from "@angular/animations";
import {OldDepDetailsComponent} from "../old-dependencies-table/old-dep-details/old-dep-details.component";
import {MatListModule} from "@angular/material/list";
Expand Down Expand Up @@ -49,10 +46,9 @@ export class LicencingIssuesComponent implements OnInit {
@Input() dependencies: Dependency[] = [];
@Input() licences: any[] = [];

constructor(private licenceRules: LicenceRulesService) { }
constructor() { }

columns = ['licenceID', 'projects', 'libraries', 'conditions', 'limitations', 'permissions', 'issues'];
// columns = ['licenceID', 'projects', 'libraries', 'issues'];
data: LicenceIssue[] = [];
dataSource!: MatTableDataSource<LicenceIssue>;
projectIDs: string[] = [];
Expand All @@ -61,46 +57,28 @@ export class LicencingIssuesComponent implements OnInit {
ngOnInit() {
this.projectIDs = this.projects.map(project => project._id);

this.data = this.licences
.filter(licence => (licence.permissions ?? []).length > 0 && (licence.conditions ?? []).length > 0 && (licence.limitations ?? []).length > 0)
this.data = (this.licences ?? [])
.filter(licence => this.hasDetailedInformation(licence))
.map(licence => {
let licenceLibraries: LibraryDisplay[] = []; // Declare inside the map function

this.projects.forEach(project => {
project.dependencies.forEach(dependency => {
let library = this.libraries?.get(dependency.name);
if (library !== undefined && library.licenses.some(libLicence => libLicence === licence._id)) {
for (let lib of licence.libraries) {
if (project.dependencies.find(dep => dep.name === lib.name)) {
let libraryDisplay = licenceLibraries.find(libraryDisplay => libraryDisplay.projectId === project._id);

if (libraryDisplay) {
if (dependency.directDep) {
libraryDisplay.directLibraries?.push(library);
}
else {
libraryDisplay.indirectLibraries.push(library);
}
lib.directDep ? libraryDisplay.directLibraries?.push(lib) : libraryDisplay.indirectLibraries.push(lib);
} else {
if (dependency.directDep) {
licenceLibraries.push({
projectId: project._id,
directLibraries: [library],
indirectLibraries: [],
seeAllDirectLibraries: false,
seeAllIndirectLibraries: false
});
}
else {
licenceLibraries.push({
projectId: project._id,
directLibraries: [],
indirectLibraries: [library],
seeAllDirectLibraries: false,
seeAllIndirectLibraries: false
});
}
licenceLibraries.push({
projectId: project._id,
directLibraries: lib.directDep ? [lib] : [],
indirectLibraries: !lib.directDep ? [lib] : [],
seeAllDirectLibraries: false,
seeAllIndirectLibraries: false
});
}
}
});
}
});

return {
Expand All @@ -113,10 +91,32 @@ export class LicencingIssuesComponent implements OnInit {
}
})

this.data = Object.values(this.data.reduce((acc: any, cur) => {
if (!acc[cur.licenceID]) {
acc[cur.licenceID] = cur;
} else {
acc[cur.licenceID] = {
...acc[cur.licenceID],
projects: [...(acc[cur.licenceID].projects || []), ...(cur.projects || [])].filter((project, index, self) =>
index === self.findIndex((t) => (
t.projectId === project.projectId
))
),
libraries: [...(acc[cur.licenceID].libraries || []), ...(cur.libraries || [])].filter((library, index, self) =>
index === self.findIndex((t) => (
t.licenceID === library.licenceID
))
),
permissions: cur.permissions,
conditions: cur.conditions,
limitations: cur.limitations,
};
}
return acc;
}, {}));

this.data = this.data.filter((licence, index, self) =>
index === self.findIndex((t) => (
t.licenceID === licence.licenceID
)) && this.isCopyleft(licence)
this.isCopyleft(licence)
);

this.dataSource = new MatTableDataSource<LicenceIssue>(this.data);
Expand All @@ -128,5 +128,7 @@ export class LicencingIssuesComponent implements OnInit {
licence.conditions?.includes('document-changes')) ?? false;
}

protected readonly Array = Array;
hasDetailedInformation(licence: any) {
return (licence?.permissions ?? []).length > 0 && (licence?.conditions ?? []).length > 0 && (licence?.limitations ?? []).length > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export class OldDependenciesTable implements OnChanges, OnChanges, AfterViewInit
}

if (this.projects !== undefined && this.libraries !== undefined) {
this.getDependencies();
this.filterDependencies();

if (this.dependencies.size > 0) {
this.dataSource = new MatTableDataSource(Array.from(this.dependencies.values()));
this.dataSource = new MatTableDataSource(Array.from(this.dependencies.values()).sort((a, b) => a.lastUpdated - b.lastUpdated));
}
}
}
Expand All @@ -85,7 +85,7 @@ export class OldDependenciesTable implements OnChanges, OnChanges, AfterViewInit
this.dataSource.sort = this.sort;
}

getDependencies() {
filterDependencies() {
let dependencies = new Map<string, OperationalRiskDependencies>();
this.projects!.forEach(project => {
project.dependencies.filter(dependency => {
Expand All @@ -108,11 +108,9 @@ export class OldDependenciesTable implements OnChanges, OnChanges, AfterViewInit
let savedDep = dependencies.get(dependency._id)!;

let projectDependency = savedDep.projects.findIndex(value => {
if (value.projectId !== project._id) {
console.log(value.projectId, project._id);
}
return value.projectId === project._id;
});

if (projectDependency != -1) {
savedDep.projects[projectDependency].dependencyVersions.add(dependency.version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {OUT_OF_SUPPORT_MONTHS, OUTDATED_MONTHS} from "@core/constants";
import {VulnerableLibraryVersionsComponent} from "./vulnerable-library-versions/vulnerable-library-versions.component";
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
import {MatProgressBarModule} from "@angular/material/progress-bar";
import {concatMap, delay, finalize, from, map, Observable} from "rxjs";
import {bufferCount, concatMap, delay, finalize, forkJoin, from, map, Observable} from "rxjs";
import {LibraryInfo, LibraryVersion} from "@core/library";
import {LibrariesService} from "../../../common/services/libraries.service";
import {LicencingIssuesComponent} from "./licencing-issues/licencing-issues.component";
Expand Down Expand Up @@ -43,9 +43,7 @@ export class SystemDashboardComponent implements OnChanges {
this.projects = changes['projects'].currentValue;

this.projects.forEach(project => {
project.dependencies.forEach(dependency => {
this.dependencies.push(dependency);
});
this.dependencies.push(...project.dependencies);
});

this.totalDependencies = this.dependencies.length;
Expand Down Expand Up @@ -81,22 +79,30 @@ export class SystemDashboardComponent implements OnChanges {

getDependencies(): Observable<Map<string, LibraryInfo>> {
let libraries = new Map<string, LibraryInfo>();

let observables = this.dependencies.map(dependency => this.libraryService.find(dependency._id).pipe(
delay(1)
));
let observables = this.dependencies.map(dependency => this.libraryService.find(dependency._id));

return from(observables).pipe(
concatMap(request => request),
map((lib: LibraryInfo) => {
try {
libraries.set(lib.name, lib);
}
catch (e: any) {
console.warn('Error adding library to map', e)
}
this.totalLoaded++;
// Group the observables into batches of 20
bufferCount(20),
// Use the concatMap operator to handle these batches one by one
concatMap(batch => forkJoin(batch)),
// Use the map operator to process each fetched library
map((libs: LibraryInfo[]) => {
libs.forEach(lib => {
try {
// Add the library to the map with its name as the key
libraries.set(lib.name, lib);
}
catch (e: any) {
// Log a warning if there's an error adding the library to the map
console.warn('Error adding library to map', e)
}
// Increment the totalLoaded variable each time a library is successfully fetched
this.totalLoaded++;
// delay(1);
});

// Return the updated libraries map
return libraries;
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
tr.example-detail-row {
height: 0;
}

table {
display: block;
overflow-x: auto;
white-space: nowrap;
}

table tbody {
display: table;
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
@if (tableData !== undefined) {
<table mat-table [dataSource]="tableData" multiTemplateDataRows style="width: 80%">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<div table-responsive>
<table mat-table [dataSource]="tableData" multiTemplateDataRows style="">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>

<ng-container matColumnDef="dependency-type">
<th mat-header-cell *matHeaderCellDef> type </th>
<td mat-cell *matCellDef="let element"> {{element.dependencyType}} </td>
</ng-container>
<ng-container matColumnDef="dependency-type">
<th mat-header-cell *matHeaderCellDef> type </th>
<td mat-cell *matCellDef="let element"> {{element.dependencyType}} </td>
</ng-container>

<ng-container matColumnDef="version">
<th mat-header-cell *matHeaderCellDef> version </th>
<td mat-cell *matCellDef="let element"> {{element.version}} </td>
</ng-container>
<ng-container matColumnDef="version">
<th mat-header-cell *matHeaderCellDef> version </th>
<td mat-cell *matCellDef="let element"> {{element.version}} </td>
</ng-container>

<ng-container matColumnDef="severity">
<th mat-header-cell *matHeaderCellDef> severity </th>
<td mat-cell *matCellDef="let element"> {{getVulnerabilitySeverity(element.vulnerabilities)}} </td>
</ng-container>
<ng-container matColumnDef="severity">
<th mat-header-cell *matHeaderCellDef> severity </th>
<td mat-cell *matCellDef="let element"> {{getVulnerabilitySeverity(element.vulnerabilities)}} </td>
</ng-container>

<ng-container matColumnDef="suggestedVersion">
<th mat-header-cell *matHeaderCellDef> suggestedVersion </th>
<td mat-cell *matCellDef="let element"> {{element.suggestedVersion}} </td>
</ng-container>
<ng-container matColumnDef="suggestedVersion">
<th mat-header-cell *matHeaderCellDef> suggestedVersion </th>
<td mat-cell *matCellDef="let element"> {{element.suggestedVersion}} </td>
</ng-container>

<ng-container matColumnDef="upgradeType">
<th mat-header-cell *matHeaderCellDef> upgradeType </th>
<td mat-cell *matCellDef="let element"> {{element.upgradeType}} </td>
</ng-container>
<ng-container matColumnDef="upgradeType">
<th mat-header-cell *matHeaderCellDef> upgradeType </th>
<td mat-cell *matCellDef="let element"> {{element.upgradeType}} </td>
</ng-container>

<ng-container matColumnDef="expandedDetail">
<td mat-cell *matCellDef="let element" [attr.colspan]="tableColumns.length">
<div class="example-element-detail" [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
<app-vulnerable-library-details [element]="element"></app-vulnerable-library-details>
</div>
</td>
</ng-container>
<ng-container matColumnDef="expandedDetail">
<td mat-cell *matCellDef="let element" [attr.colspan]="tableColumns.length">
<div class="example-element-detail" [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
<app-vulnerable-library-details [element]="element"></app-vulnerable-library-details>
</div>
</td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="tableColumns"></tr>
<tr mat-row *matRowDef="let element; columns: tableColumns;"
class="example-element-row"
[class.example-expanded-row]="expandedElement === element"
(click)="expandedElement = expandedElement === element ? null : element">
</tr>
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="example-detail-row"></tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]"
showFirstLastButtons
aria-label="Select page of periodic elements">
</mat-paginator>
<tr mat-header-row *matHeaderRowDef="tableColumns"></tr>
<tr mat-row *matRowDef="let element; columns: tableColumns;"
class="example-element-row"
[class.example-expanded-row]="expandedElement === element"
(click)="expandedElement = expandedElement === element ? null : element">
</tr>
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="example-detail-row"></tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]"
showFirstLastButtons
aria-label="Select page of periodic elements">
</mat-paginator>
</div>
}
Loading

0 comments on commit 14f81fa

Please sign in to comment.