@@ -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}
0 commit comments