File
Description
Edit Feature/Observation Dialog Component
Modal dialog component which is used to edit a custom feature or observation set
For Observation sets the user can update name and the list of samples included
For Feature sets the user can update name
Implements
Metadata
| changeDetection |
ChangeDetectionStrategy.Default |
| selector |
mev-edit-feature-set-dialog |
| styleUrls |
./edit-feature-set-dialog.component.scss |
| templateUrl |
./edit-feature-set-dialog.component.html |
Index
Properties
|
|
|
Methods
|
|
|
Accessors
|
|
|
Methods
|
applyFilter
|
applyFilter(filterValue: string)
|
|
|
Filtering observations by name
Parameters :
| Name |
Type |
Optional |
| filterValue |
string
|
No
|
|
|
confirmEdit
|
confirmEdit()
|
|
|
Method is triggered when user clicks the Save button
|
|
isAllSelected
|
isAllSelected()
|
|
|
Whether the number of selected elements matches the total number of rows.
|
|
masterToggle
|
masterToggle()
|
|
|
Selects all rows if they are not all selected; otherwise clear selection.
|
|
ngAfterViewInit
|
ngAfterViewInit()
|
|
|
|
|
|
onNoClick
|
onNoClick()
|
|
|
Function is triggered when user clicks the Cancel button
|
|
Public
data
|
Type : any
|
Decorators :
@Inject(MAT_DIALOG_DATA)
|
|
|
|
isObservationSet
|
Default value : true
|
|
|
|
observationSetsDisplayedColumns
|
|
|
|
observationSetsDisplayedColumnsAttributesOnly
|
|
|
|
paginator
|
Type : MatPaginator
|
Decorators :
@ViewChild(MatPaginator)
|
|
|
|
selection
|
Default value : new SelectionModel(true, [])
|
|
|
|
submitted
|
Default value : false
|
|
|
Accessors
|
f
|
getf()
|
|
|
Convenience getter for easy access to form fields
|
import {
Component,
OnInit,
ChangeDetectionStrategy,
Inject,
ViewChild
} from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { SelectionModel } from '@angular/cdk/collections';
import { MatPaginator } from '@angular/material/paginator';
import { CustomSetType } from '@app/_models/metadata';
/**
* Edit Feature/Observation Dialog Component
*
* Modal dialog component which is used to edit a custom feature or observation set
* For Observation sets the user can update name and the list of samples included
* For Feature sets the user can update name
*/
@Component({
selector: 'mev-edit-feature-set-dialog',
templateUrl: './edit-feature-set-dialog.component.html',
styleUrls: ['./edit-feature-set-dialog.component.scss'],
changeDetection: ChangeDetectionStrategy.Default
})
export class EditFeatureSetDialogComponent implements OnInit {
selection = new SelectionModel(true, []);
customSetType: string;
isObservationSet = true;
allObservationSetsDS;
observationForm: FormGroup;
submitted = false;
observationSetsDisplayedColumns;
observationSetsDisplayedColumnsAttributesOnly;
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor(
private formBuilder: FormBuilder,
public dialogRef: MatDialogRef<EditFeatureSetDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
) {}
ngOnInit(): void {
// if no custom set type is passed, assume Observation set by default
this.customSetType = this.data?.type || CustomSetType.ObservationSet;
if (this.customSetType === CustomSetType.FeatureSet) {
this.isObservationSet = false;
}
this.observationForm = this.formBuilder.group({
observationSetName: [this.data.name, Validators.required],
observationSetColor: [
this.data.color,
[...(this.isObservationSet ? [Validators.required] : [])]
]
});
if (this.isObservationSet) {
this.allObservationSetsDS = this.data.observationSetDS;
this.observationSetsDisplayedColumns = this.data.observationSetsDisplayedColumns;
this.observationSetsDisplayedColumnsAttributesOnly = this.data.observationSetsDisplayedColumnsAttributesOnly;
this.allObservationSetsDS.data
.filter(el =>
this.data.selectedElements.some(selEl => selEl.id === el.id)
)
.forEach(row => {
this.selection.select(row);
});
}
}
ngAfterViewInit() {
if (this.isObservationSet) {
this.allObservationSetsDS.paginator = this.paginator;
}
}
/**
* Function is triggered when user clicks the Cancel button
*
*/
onNoClick(): void {
this.dialogRef.close();
}
submit() {
//empty stuff
}
/**
* Whether the number of selected elements matches the total number of rows.
*/
isAllSelected() {
const numSelected = this.selection.selected.length;
const numRows = this.allObservationSetsDS.filteredData.length;
return numSelected === numRows;
}
/**
* Selects all rows if they are not all selected; otherwise clear selection.
*/
masterToggle() {
this.isAllSelected()
? this.selection.clear()
: this.allObservationSetsDS.filteredData.forEach(row =>
this.selection.select(row)
);
}
/**
* Convenience getter for easy access to form fields
*/
get f() {
return this.observationForm.controls;
}
/**
* Method is triggered when user clicks the Save button
*
*/
confirmEdit() {
const name = this.observationForm.value.observationSetName;
const color = this.observationForm.value.observationSetColor;
const samples = this.selection.selected;
const observationSet = {
name: name,
color: color,
type: this.customSetType,
multiple: true
};
// for Feature sets users can't update sample list
if (this.customSetType === CustomSetType.ObservationSet) {
observationSet['elements'] = samples;
}
this.dialogRef.close(observationSet);
}
/**
* Filtering observations by name
*/
applyFilter(filterValue: string) {
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.allObservationSetsDS.filter = filterValue;
}
}
<div class="container">
<p *ngIf="isObservationSet; else featureSetText">
Update the name of the observation set, its color and sample list. Then click the Save button.
</p>
<ng-template #featureSetText>
<p>
Update the name of the feature set. Then click the Save button.
</p>
</ng-template>
<form class="mat-dialog-content" (ngSubmit)="submit" [formGroup]="observationForm">
<div class="form">
<mat-form-field class="form-control" color="accent">
<mat-label>Enter {{ customSetType | lowercase}} name</mat-label>
<input matInput formControlName=observationSetName name=observationSetName>
</mat-form-field>
<mat-form-field *ngIf="isObservationSet" class="form-control" color="accent">
<mat-label>Select your color for the observation set:</mat-label>
<input type="color" class="color-picker-input" matInput formControlName=observationSetColor
name=observationSetColor>
</mat-form-field>
<div *ngIf="isObservationSet">
Select samples:
<div class="mat-elevation-z8">
<div class="filter-panel">
<mat-form-field class="form-control">
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
</div>
<table mat-table [dataSource]="allObservationSetsDS">
<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox (change)="$event ? masterToggle() : null"
[checked]="selection.hasValue() && isAllSelected()"
[indeterminate]="selection.hasValue() && !isAllSelected()">
</mat-checkbox>
</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox (click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)">
</mat-checkbox>
</td>
</ng-container>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<ng-container
*ngFor="let attrCol of observationSetsDisplayedColumnsAttributesOnly; let colIndex = index"
matColumnDef="{{attrCol}}">
<th mat-header-cell *matHeaderCellDef>{{ attrCol }}</th>
<td mat-cell *matCellDef="let element">
{{ element.attributes[attrCol] ? element.attributes[attrCol].value : '' }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="observationSetsDisplayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: observationSetsDisplayedColumns;"
(click)="selection.toggle(row)">
</tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 25]">
</mat-paginator>
</div>
</div>
<div *ngIf="!isObservationSet">
Selected features:
<ul>
<li *ngFor="let elem of data.selectedElements">{{ elem.id }}</li>
</ul>
</div>
</div>
<div class="button-panel">
<button mat-button [mat-dialog-close]="1" mat-raised-button color="accent" [type]="submit"
[disabled]="!observationForm.valid" (click)="confirmEdit()">Save</button>
<button mat-button (click)="onNoClick()" tabindex="-1">Cancel</button>
</div>
</form>
</div>
.container {
font-size: 14px;
}
.mat-dialog-content {
overflow-y: auto;
}
.form-control {
width: 100%;
}
.filter-panel {
padding: 0 10px;
}
table {
width: 100%;
}
.color-picker-input {
width: 40px;
height: 40px;
margin: 0;
padding: 0;
}
.button-panel {
margin-top: 25px;
}
Legend
Html element with directive