@@ -320,18 +320,17 @@ export class MappingComponent implements OnInit {
320320 //console.log(this.temp)
321321 }
322322
323- // remong filter chip
324- remove ( chip : string ) : void {
323+ // remove filter chip
324+ removeChip ( chip : string ) : void {
325325 const index = this . currentChip . indexOf ( chip ) ;
326- //console.log(fruit)
327326 if ( index >= 0 ) {
328327 this . currentChip . splice ( index , 1 ) ;
329328 }
330329 this . changeTableBasedOnCurrentFilter ( ) ;
331330 }
332331
333332 //adding filter chip
334- selected ( event : MatAutocompleteSelectedEvent ) : void {
333+ addChip ( event : MatAutocompleteSelectedEvent ) : void {
335334 this . currentChip . push ( event . option . viewValue ) ;
336335 this . changeTableBasedOnCurrentFilter ( ) ;
337336 }
@@ -344,38 +343,47 @@ export class MappingComponent implements OnInit {
344343 ) ;
345344 }
346345
346+ //check sort value and change table data accordingly
347+ checkSortValueAndChangeTableData (
348+ taskData : any ,
349+ ISOData : any ,
350+ SAMMData : any
351+ ) : void {
352+ if ( this . currentlySortingByTask ) {
353+ this . dataSource = taskData ;
354+ } else if ( this . currentlySortingByISO ) {
355+ this . dataSource = ISOData ;
356+ } else {
357+ this . dataSource = SAMMData ;
358+ }
359+ }
360+
347361 changeTableBasedOnCurrentFilter ( ) {
348362 if ( this . currentChip . length > 1 || this . currentChip . length == 0 ) {
349363 // both planned and performed actvities are selected
350364
351365 //Check current sort value
352- if ( this . currentlySortingByTask ) {
353- this . dataSource = this . allMappingDataSortedByTask ;
354- } else if ( this . currentlySortingByISO ) {
355- this . dataSource = this . allMappingDataSortedByISO ;
356- } else {
357- this . dataSource = this . allMappingDataSortedBySAMM ;
358- }
366+ this . checkSortValueAndChangeTableData (
367+ this . allMappingDataSortedByTask ,
368+ this . allMappingDataSortedByISO ,
369+ this . allMappingDataSortedBySAMM
370+ ) ;
359371 } else if ( this . currentChip [ 0 ] == 'Planned Activities' ) {
360372 // planned actvities shows planned data
361373
362374 //Check current sort value
363- if ( this . currentlySortingByTask ) {
364- this . dataSource = this . plannedMappingDataSortedByTask ;
365- } else if ( this . currentlySortingByISO ) {
366- this . dataSource = this . plannedMappingDataSortedByISO ;
367- } else {
368- this . dataSource = this . plannedMappingDataSortedBySAMM ;
369- }
375+ this . checkSortValueAndChangeTableData (
376+ this . plannedMappingDataSortedByTask ,
377+ this . plannedMappingDataSortedByISO ,
378+ this . plannedMappingDataSortedBySAMM
379+ ) ;
370380 } else {
371381 //Check current sort value
372- if ( this . currentlySortingByTask ) {
373- this . dataSource = this . performedMappingDataSortedByTask ;
374- } else if ( this . currentlySortingByISO ) {
375- this . dataSource = this . performedMappingDataSortedByISO ;
376- } else {
377- this . dataSource = this . performedMappingDataSortedBySAMM ;
378- }
382+ this . checkSortValueAndChangeTableData (
383+ this . performedMappingDataSortedByTask ,
384+ this . performedMappingDataSortedByISO ,
385+ this . performedMappingDataSortedBySAMM
386+ ) ;
379387 }
380388
381389 this . chipInput . nativeElement . value = '' ;
0 commit comments