11import { Component , OnInit } from '@angular/core' ;
22import { ymlService } from '../../service/yaml-parser/yaml-parser.service' ;
33import { MatTableDataSource } from '@angular/material/table' ;
4- import { COMMA , ENTER , T } from '@angular/cdk/keycodes' ;
4+ import { COMMA , ENTER } from '@angular/cdk/keycodes' ;
55import { ElementRef , ViewChild } from '@angular/core' ;
66import { FormControl } from '@angular/forms' ;
77import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete' ;
@@ -31,6 +31,14 @@ export interface MappingElementSortedByISO {
3131 subDimension : string ;
3232 taskName : string ;
3333 samm2 :string [ ] ;
34+ description :string ;
35+ risk :string ;
36+ measure :string ;
37+ knowledge :string ;
38+ resources :string ;
39+ time :string ;
40+ usefulness :string ;
41+ dependsOn :string [ ]
3442}
3543
3644
@@ -63,6 +71,10 @@ export class MappingComponent implements OnInit {
6371 allDimensionNames :string [ ] = [ ] ;
6472 temporaryMappingElement :any
6573
74+ //labels
75+ knowledgeLabels : string [ ] = [ ]
76+ generalLabels : string [ ] = [ ]
77+
6678 separatorKeysCodes : number [ ] = [ ENTER , COMMA ] ;
6779 FilterCtrl = new FormControl ( '' ) ;
6880 SortCtrl = new FormControl ( '' ) ;
@@ -80,6 +92,14 @@ export class MappingComponent implements OnInit {
8092 }
8193
8294 ngOnInit ( ) : void {
95+ //gets value from meta folder
96+ this . yaml . setURI ( './assets/YAML/meta.yaml' ) ;
97+ // Function sets label data
98+ this . yaml . getJson ( ) . subscribe ( ( data ) => {
99+ //console.log(data)
100+ this . knowledgeLabels = data [ 'strings' ] [ 'en' ] [ 'KnowledgeLabels' ]
101+ this . generalLabels = data [ 'strings' ] [ 'en' ] [ 'labels' ]
102+ } )
83103 //gets value from generated folder
84104 this . yaml . setURI ( './assets/YAML/generated/generated.yaml' ) ;
85105 // Function sets data
@@ -157,7 +177,59 @@ export class MappingComponent implements OnInit {
157177 setValueandAppendToDatasetandSortbyISO ( dim :string , subDim :string , task :string ) {
158178 var ISOArray :string [ ] = this . YamlObject [ dim ] [ subDim ] [ task ] [ 'references' ] [ 'iso27001-2017' ]
159179 var SAMMArray :string [ ] = this . YamlObject [ dim ] [ subDim ] [ task ] [ 'references' ] [ 'samm2' ]
160- this . temporaryMappingElement = { "dimension" :dim , "subDimension" :subDim , "taskName" :task , "ISO" :"" , "samm2" :SAMMArray }
180+ try {
181+ var CurrentDescription :string = this . YamlObject [ dim ] [ subDim ] [ task ] [ 'description' ]
182+ }
183+ catch {
184+ var CurrentDescription :string = ""
185+ }
186+ try {
187+ var CurrentRisk :string = this . YamlObject [ dim ] [ subDim ] [ task ] [ 'risk' ]
188+ }
189+ catch {
190+ var CurrentRisk :string = ""
191+ }
192+ try {
193+ var CurrentMeasure :string = this . YamlObject [ dim ] [ subDim ] [ task ] [ 'measure' ]
194+ }
195+ catch {
196+ var CurrentMeasure :string = ""
197+ }
198+ try {
199+ var CurrentKnowledge :string = this . knowledgeLabels [ this . YamlObject [ dim ] [ subDim ] [ task ] [ 'difficultyOfImplementation' ] [ 'knowledge' ] ]
200+
201+ }
202+ catch {
203+ var CurrentKnowledge :string = ""
204+ }
205+ try {
206+
207+ var CurrentTime :string = this . generalLabels [ this . YamlObject [ dim ] [ subDim ] [ task ] [ 'difficultyOfImplementation' ] [ 'time' ] ]
208+ }
209+ catch {
210+ var CurrentTime :string = ""
211+ }
212+ try {
213+ var CurrentResources :string = this . generalLabels [ this . YamlObject [ dim ] [ subDim ] [ task ] [ 'difficultyOfImplementation' ] [ 'resources' ] ]
214+ }
215+ catch {
216+ var CurrentResources :string = ""
217+ }
218+ try {
219+ var CurrentUsefulness :string = this . generalLabels [ this . YamlObject [ dim ] [ subDim ] [ task ] [ 'usefulness' ] ]
220+ }
221+ catch {
222+ var CurrentUsefulness :string = ""
223+ }
224+ try {
225+ var CurrentDependsOn :string [ ] = this . YamlObject [ dim ] [ subDim ] [ task ] [ 'dependsOn' ]
226+ }
227+ catch {
228+ var CurrentDependsOn :string [ ] = [ ]
229+ }
230+ this . temporaryMappingElement = { "dimension" :dim , "subDimension" :subDim , "taskName" :task , "ISO" :"" , "samm2" :SAMMArray ,
231+ description :CurrentDescription , risk :CurrentRisk , measure :CurrentMeasure , knowledge :CurrentKnowledge , time :CurrentTime ,
232+ resources :CurrentResources , usefulness :CurrentUsefulness , dependsOn :CurrentDependsOn }
161233 if ( ISOArray . length == 0 ) {
162234 this . allMappingDataSortedByISO . push ( this . temporaryMappingElement )
163235 if ( this . YamlObject [ dim ] [ subDim ] [ task ] [ 'isImplemented' ] ) {
@@ -313,14 +385,15 @@ export class MappingComponent implements OnInit {
313385
314386 exportToExcel ( ) {
315387 /* passing the table id */
316- let element = document . getElementById ( "excel-table" ) ;
317- const ws : XLSX . WorkSheet = XLSX . utils . table_to_sheet ( element ) ;
388+ // let element = document.getElementById("excel-table");
389+ // const ws: XLSX.WorkSheet =XLSX.utils.table_to_sheet(element);
318390
319391 /* generate workbook and add the worksheet */
320- const wb : XLSX . WorkBook = XLSX . utils . book_new ( ) ;
321- XLSX . utils . book_append_sheet ( wb , ws , "Sheet1" ) ;
392+ // const wb: XLSX.WorkBook = XLSX.utils.book_new();
393+ // XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
322394
323395 /* save to file */
324- XLSX . writeFile ( wb , "Planned-Activities-Sorted-By-ISO.xlsx" ) ;
396+ //XLSX.writeFile(wb, "Planned-Activities-Sorted-By-ISO.xlsx");
397+ console . log ( this . allMappingDataSortedByISO )
325398 }
326399}
0 commit comments