Skip to content

Commit 6a2f02d

Browse files
authored
Merge pull request #349 from vbakke/feat/344-team-names
Allow team names to be controlled by meta.yaml
2 parents 568a4ba + 46e4f64 commit 6a2f02d

10 files changed

Lines changed: 230 additions & 196 deletions

File tree

src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { MappingComponent } from './component/mapping/mapping.component';
77
import { MatrixComponent } from './component/matrix/matrix.component';
88
import { ActivityDescriptionComponent } from './component/activity-description/activity-description.component';
99
import { UsageComponent } from './component/usage/usage.component';
10-
import { Teams } from './component/teams/teams.component';
10+
import { TeamsComponent } from './component/teams/teams.component';
1111

1212
const routes: Routes = [
1313
{ path: '', component: MatrixComponent },
1414
{ path: 'circular-heatmap', component: CircularHeatmapComponent },
1515
{ path: 'activity-description', component: ActivityDescriptionComponent },
1616
{ path: 'mapping', component: MappingComponent },
1717
{ path: 'usage', component: UsageComponent },
18-
{ path: 'teams', component: Teams },
18+
{ path: 'teams', component: TeamsComponent },
1919
{ path: 'about', component: AboutUsComponent },
2020
{ path: 'userday', component: UserdayComponent },
2121
];

src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { UsageComponent } from './component/usage/usage.component';
2020
import { UserdayComponent } from './component/userday/userday.component';
2121
import { AboutUsComponent } from './component/about-us/about-us.component';
2222
import { DependencyGraphComponent } from './component/dependency-graph/dependency-graph.component';
23-
import { Teams } from './component/teams/teams.component';
23+
import { TeamsComponent } from './component/teams/teams.component';
2424
import { ToStringValuePipe } from './pipe/to-string-value.pipe';
2525

2626
@NgModule({
@@ -37,7 +37,7 @@ import { ToStringValuePipe } from './pipe/to-string-value.pipe';
3737
UsageComponent,
3838
AboutUsComponent,
3939
DependencyGraphComponent,
40-
Teams,
40+
TeamsComponent,
4141
ToStringValuePipe,
4242
UserdayComponent,
4343
],

src/app/component/activity-description/activity-description.component.ts

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface activityDescription {
3737
assessment: string;
3838
comments: string;
3939
isImplemented: boolean;
40-
teamsImplemented: Object;
40+
teamsImplemented: Record<string, any>;
4141
}
4242

4343
@Component({
@@ -78,6 +78,7 @@ export class ActivityDescriptionComponent implements OnInit {
7878
YamlObject: any;
7979
GeneralLabels: string[] = [];
8080
KnowledgeLabels: string[] = [];
81+
TeamList: string[] = [];
8182
rowIndex: number = 0;
8283
markdown: md = md();
8384
SAMMVersion: string = 'OWASP SAMM VERSION 2';
@@ -95,16 +96,20 @@ export class ActivityDescriptionComponent implements OnInit {
9596
//gets value from sample file
9697
this.yaml.setURI('./assets/YAML/meta.yaml');
9798
// Function sets label data
99+
console.log(this.perfNow() + 's: meta.yaml fetch');
98100
this.yaml.getJson().subscribe(data => {
99-
this.YamlObject = data;
100-
this.GeneralLabels = this.YamlObject['strings']['en']['labels'];
101-
this.KnowledgeLabels =
102-
this.YamlObject['strings']['en']['KnowledgeLabels'];
101+
console.log(this.perfNow() + 's: meta.yaml');
102+
this.GeneralLabels = data['strings']['en']['labels'];
103+
this.KnowledgeLabels = data['strings']['en']['KnowledgeLabels'];
104+
this.TeamList = data['teams']; // Genuine teams (the true source)
105+
console.log(this.perfNow() + 's: meta.yaml processed');
103106
});
104107
//gets value from generated folder
108+
console.log(this.perfNow() + 's: generated.yaml fetch');
105109
this.yaml.setURI('./assets/YAML/generated/generated.yaml');
106110
// Function sets data
107111
this.yaml.getJson().subscribe(data => {
112+
console.log(this.perfNow() + 's: generated.yaml downloaded');
108113
this.YamlObject = data;
109114

110115
var allDimensionNames = Object.keys(this.YamlObject);
@@ -250,40 +255,48 @@ export class ActivityDescriptionComponent implements OnInit {
250255
data['isImplemented'],
251256
false
252257
);
253-
const dataFromLocalStorage = localStorage.getItem('dataset');
258+
let combinedTeamsImplemented: any = {};
259+
const dataFromLocalStorage: string | null =
260+
localStorage.getItem('dataset');
254261
if (dataFromLocalStorage !== null) {
255-
var parsedDataFromLocalStorage = JSON.parse(dataFromLocalStorage);
256-
var index = -1;
257-
for (var i = 0; i < parsedDataFromLocalStorage.length; i++) {
258-
for (
259-
var j = 0;
260-
j < parsedDataFromLocalStorage[i]['Activity'].length;
261-
j++
262-
) {
263-
if (
264-
parsedDataFromLocalStorage[i]['Activity'][j]['uuid'] ===
265-
data['uuid']
266-
) {
267-
console.log('test', parsedDataFromLocalStorage[i]['Activity'][j]);
268-
269-
index = i;
270-
this.currentActivity.teamsImplemented =
271-
parsedDataFromLocalStorage[i]['Activity'][j][
272-
'teamsImplemented'
273-
];
262+
let localData = JSON.parse(dataFromLocalStorage);
263+
let localDataActivity = null;
274264

265+
// Find the activity with the correct uuid
266+
for (let subdim of localData) {
267+
for (let activity of subdim?.Activity) {
268+
if (activity?.uuid === data?.uuid) {
269+
console.log('Found', activity);
270+
localDataActivity = activity;
275271
break;
276272
}
277273
}
274+
if (localDataActivity) break;
278275
}
279-
// this.currentActivity.teamsEvidence = this.defineEvidenceObject();
280-
} else this.currentActivity.teamsImplemented = data['teamsImplemented'];
276+
277+
// Combine teams status from local storage and loaded yaml file
278+
combinedTeamsImplemented = Object.assign(
279+
{},
280+
localDataActivity?.teamsImplemented,
281+
this.currentActivity?.teamsImplemented
282+
);
283+
} else {
284+
combinedTeamsImplemented = data['teamsImplemented'];
285+
}
286+
287+
// Only keep genuine teams
288+
this.currentActivity.teamsImplemented = {};
289+
for (let team of this.TeamList) {
290+
this.currentActivity.teamsImplemented[team] =
291+
combinedTeamsImplemented[team];
292+
}
281293

282294
this.currentActivity.teamsEvidence = this.defineEvidenceObject(
283295
data['teamsEvidence']
284296
);
285297
// console.log("data['teamsEvidence']", data['teamsEvidence']);
286298
this.openall();
299+
console.log(this.perfNow() + 's: generated.yaml processed');
287300
});
288301
}
289302

@@ -378,4 +391,8 @@ export class ActivityDescriptionComponent implements OnInit {
378391
element.closeAll();
379392
});
380393
}
394+
395+
perfNow() {
396+
return (performance.now() / 1000).toFixed(3);
397+
}
381398
}

src/app/component/circular-heatmap/circular-heatmap.component.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ <h2>Nothing to show</h2>
218218
</mat-chip>
219219
<mat-chip
220220
#c="matChip"
221-
*ngFor="let group of teamGroups | keyvalue"
221+
*ngFor="let group of teamGroups | keyvalue : unsorted"
222222
(click)="toggleTeamGroupSelection(c)">
223223
{{ group.key }}
224224
</mat-chip>
@@ -263,14 +263,15 @@ <h2>Nothing to show</h2>
263263
</mat-expansion-panel-header>
264264
<ng-template matExpansionPanelContent>
265265
<ul class="team-list">
266-
<li
267-
*ngFor="let item of activity.teamsImplemented | keyvalue">
266+
<li *ngFor="let teamname of teamVisible">
268267
<mat-checkbox
269-
[checked]="item.value === true"
270-
*ngIf="teamVisible.includes(item.key | ToStringValue)"
268+
[checked]="activity.teamsImplemented[teamname]"
271269
color="primary"
272-
(click)="this.teamCheckbox(activityIndex, item.key)">
273-
{{ item.key }}
270+
(click)="
271+
this.teamCheckbox(activityIndex, teamname);
272+
$event.preventDefault()
273+
">
274+
{{ teamname }}
274275
</mat-checkbox>
275276
</li>
276277
</ul>
@@ -288,7 +289,7 @@ <h2>Nothing to show</h2>
288289
class="normal-button"
289290
mat-raised-button
290291
class="downloadButtonClass"
291-
(click)="SaveEditedYAMLfile()">
292+
(click)="saveEditedYAMLfile()">
292293
Download edited YAML file
293294
</button>
294295
<button

0 commit comments

Comments
 (0)