Skip to content

Commit f47a6e2

Browse files
committed
Added filter by planned and performed actvities for mapping section
1 parent 8a35b11 commit f47a6e2

4 files changed

Lines changed: 124 additions & 28 deletions

File tree

src/app/component/mapping/mapping.component.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
background-color: gainsboro;
44
}
55

6+
.mat-form-field{
7+
margin: 20px;
8+
width: 90%;
9+
}
10+
611
.matrix-table{
712
margin: 20px;
813
}

src/app/component/mapping/mapping.component.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
<div class="content">
2+
23
<app-top-header section="Mappings"></app-top-header>
34

5+
<mat-form-field class="example-chip-list" appearance="fill">
6+
<mat-label>Filter</mat-label>
7+
<mat-chip-list #chipList aria-label="Filter" color="primary">
8+
<mat-chip
9+
*ngFor="let chip of currentChip"
10+
(removed)="remove(chip)">
11+
{{chip}}
12+
<button matChipRemove>
13+
<mat-icon>cancel</mat-icon>
14+
</button>
15+
</mat-chip>
16+
<input
17+
#chipInput
18+
[formControl]="chipCtrl"
19+
[matAutocomplete]="auto"
20+
[matChipInputFor]="chipList"
21+
[matChipInputSeparatorKeyCodes]="separatorKeysCodes">
22+
</mat-chip-list>
23+
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
24+
<mat-option *ngFor="let fruit of filteredChips | async" [value]="fruit">
25+
{{fruit}}
26+
</mat-option>
27+
</mat-autocomplete>
28+
</mat-form-field>
29+
30+
431
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8 matrix-table" >
532

633
<ng-container matColumnDef="dimension">

src/app/component/mapping/mapping.component.ts

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
22
import { ymlService } from '../../service/yaml-parser/yaml-parser.service';
33
import { MatTableDataSource } from '@angular/material/table';
4+
import {COMMA, ENTER} from '@angular/cdk/keycodes';
5+
import {ElementRef, ViewChild} from '@angular/core';
6+
import {FormControl} from '@angular/forms';
7+
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
8+
import {MatChipInputEvent} from '@angular/material/chips';
9+
import {Observable} from 'rxjs';
10+
import {map, startWith} from 'rxjs/operators';
411

512
export interface MappingElement {
613
dimension: string;
@@ -17,14 +24,31 @@ export interface MappingElement {
1724
styleUrls: ['./mapping.component.css']
1825
})
1926
export class MappingComponent implements OnInit {
20-
MAPPING_DATA:MappingElement[]=[]
21-
dataSource:any= new MatTableDataSource<MappingElement>(this.MAPPING_DATA);
27+
allMappingData:MappingElement[]=[]
28+
plannedMappingData:MappingElement[]=[]
29+
performedMappingData:MappingElement[]=[]
30+
31+
dataSource:any= new MatTableDataSource<MappingElement>(this.allMappingData);
2232
YamlObject:any;
2333

2434
displayedColumns: string[] = ['dimension', 'subDimension', 'taskName','samm2' ,'ISO'];
2535
allDimensionNames:string[]=[];
2636
temporaryMappingElement:any
27-
constructor(private yaml:ymlService) { }
37+
38+
separatorKeysCodes: number[] = [ENTER, COMMA];
39+
chipCtrl = new FormControl('');
40+
filteredChips: Observable<string[]>;
41+
currentChip: string[] = ['Performed Activities','Planned Activities'];
42+
allChips: string[] = ['Performed Activities','Planned Activities'];
43+
44+
@ViewChild('chipInput') chipInput!: ElementRef<HTMLInputElement>;
45+
46+
constructor(private yaml:ymlService) {
47+
this.filteredChips = this.chipCtrl.valueChanges.pipe(
48+
startWith(null),
49+
map((x: string | null) => (x ? this._filter(x) : this.allChips.slice())),
50+
);
51+
}
2852

2953
ngOnInit(): void {
3054
//gets value from generated folder
@@ -44,6 +68,7 @@ export class MappingComponent implements OnInit {
4468
}
4569
// weird fix to render DOM for table viewing in angular material
4670
this.dataSource._data.next(this.dataSource.data);
71+
this.allMappingData=this.dataSource.data
4772
})
4873

4974
//this.dataSource=new MatTableDataSource([...this.dataSource]);
@@ -57,7 +82,46 @@ export class MappingComponent implements OnInit {
5782
this.temporaryMappingElement={"dimension":dim,"subDimension":subDim,"taskName":task,"ISO":ISOArray,"samm2":SAMMArray}
5883
//console.log(this.temp)
5984
this.dataSource.data.push(this.temporaryMappingElement)
85+
if(this.YamlObject[dim][subDim][task]['isImplemented']){
86+
this.performedMappingData.push(this.temporaryMappingElement)
87+
}
88+
else{
89+
this.plannedMappingData.push(this.temporaryMappingElement)
90+
}
6091

6192
}
6293

94+
remove(chip: string): void {
95+
const index = this.currentChip.indexOf(chip);
96+
//console.log(fruit)
97+
if (index >= 0) {
98+
this.currentChip.splice(index, 1);
99+
}
100+
}
101+
102+
selected(event: MatAutocompleteSelectedEvent): void {
103+
this.currentChip.push(event.option.viewValue);
104+
if((this.currentChip.length>1)||(this.currentChip.length==0)){ // both planned and performed actvities are selected
105+
this.dataSource._data.next(this.allMappingData);
106+
}
107+
else{
108+
if(this.currentChip[0]=='Planned Activities'){ // planned actvities shows planned data
109+
this.dataSource._data.next(this.plannedMappingData);
110+
console.log(this.plannedMappingData)
111+
}
112+
else {
113+
this.dataSource._data.next(this.performedMappingData); // performed actvities shows performed data
114+
console.log(this.performedMappingData)
115+
}
116+
}
117+
118+
this.chipInput.nativeElement.value = '';
119+
this.chipCtrl.setValue(null);
120+
}
121+
122+
private _filter(value: string): string[] {
123+
const filterValue = value.toLowerCase();
124+
125+
return this.allChips.filter(chip => chip.toLowerCase().includes(filterValue));
126+
}
63127
}

src/app/component/matrix/matrix.component.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
<div class="content">
22
<app-top-header section="Matrix"></app-top-header>
33
<mat-form-field class="example-chip-list">
4-
<mat-label>Filter</mat-label>
5-
<mat-chip-list #chipList aria-label="Filter" color="primary">
6-
<mat-chip
7-
color="primary"
8-
*ngFor="let row of rowsCurrentlyBeingShown"
9-
(removed)="remove(row)"
10-
[selected]=true>
11-
{{row}}
12-
<button matChipRemove>
13-
<mat-icon>cancel</mat-icon>
14-
</button>
15-
</mat-chip>
16-
<input
17-
#rowInput
18-
[formControl]="rowCtrl"
19-
[matAutocomplete]="auto"
20-
[matChipInputFor]="chipList"
21-
[matChipInputSeparatorKeyCodes]="separatorKeysCodes">
22-
</mat-chip-list>
23-
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
24-
<mat-option *ngFor="let row of filteredRows | async" [value]="row">
25-
{{row}}
26-
</mat-option>
27-
</mat-autocomplete>
28-
</mat-form-field>
4+
<mat-label>Filter</mat-label>
5+
<mat-chip-list #chipList aria-label="Filter" color="primary">
6+
<mat-chip
7+
color="primary"
8+
*ngFor="let row of rowsCurrentlyBeingShown"
9+
(removed)="remove(row)"
10+
[selected]=true>
11+
{{row}}
12+
<button matChipRemove>
13+
<mat-icon>cancel</mat-icon>
14+
</button>
15+
</mat-chip>
16+
<input
17+
#rowInput
18+
[formControl]="rowCtrl"
19+
[matAutocomplete]="auto"
20+
[matChipInputFor]="chipList"
21+
[matChipInputSeparatorKeyCodes]="separatorKeysCodes">
22+
</mat-chip-list>
23+
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
24+
<mat-option *ngFor="let row of filteredRows | async" [value]="row">
25+
{{row}}
26+
</mat-option>
27+
</mat-autocomplete>
28+
</mat-form-field>
2929

3030

3131
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8 matrix-table">

0 commit comments

Comments
 (0)