mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-19 13:07:52 +00:00
Appliances filtering
This commit is contained in:
parent
63b2f2340a
commit
632ee71378
@ -17,5 +17,5 @@
|
|||||||
</mat-table>
|
</mat-table>
|
||||||
</div>
|
</div>
|
||||||
<div mat-dialog-actions align="end">
|
<div mat-dialog-actions align="end">
|
||||||
<button mat-button (click)="onNoClick()" tabindex="-1" color="accent">No Thanks</button>
|
<button mat-button (click)="onNoClick()" tabindex="-1" color="accent">Close</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,6 +22,7 @@ import 'rxjs/add/observable/fromEvent';
|
|||||||
})
|
})
|
||||||
export class ApplianceListDialogComponent implements OnInit {
|
export class ApplianceListDialogComponent implements OnInit {
|
||||||
server: Server;
|
server: Server;
|
||||||
|
applianceDatabase: ApplianceDatabase;
|
||||||
dataSource: ApplianceDataSource;
|
dataSource: ApplianceDataSource;
|
||||||
displayedColumns = ['name'];
|
displayedColumns = ['name'];
|
||||||
|
|
||||||
@ -35,7 +36,8 @@ export class ApplianceListDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.dataSource = new ApplianceDataSource(this.server, this.applianceService);
|
this.applianceDatabase = new ApplianceDatabase(this.server, this.applianceService);
|
||||||
|
this.dataSource = new ApplianceDataSource(this.applianceDatabase);
|
||||||
|
|
||||||
Observable.fromEvent(this.filter.nativeElement, 'keyup')
|
Observable.fromEvent(this.filter.nativeElement, 'keyup')
|
||||||
.debounceTime(150)
|
.debounceTime(150)
|
||||||
@ -51,27 +53,53 @@ export class ApplianceListDialogComponent implements OnInit {
|
|||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilter(filterValue: string) {
|
//
|
||||||
filterValue = filterValue.trim(); // Remove whitespace
|
// applyFilter(filterValue: string) {
|
||||||
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
|
// filterValue = filterValue.trim(); // Remove whitespace
|
||||||
this.dataSource.filter = filterValue;
|
// filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
|
||||||
}
|
// this.dataSource.filter = filterValue;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class ApplianceDatabase {
|
||||||
|
dataChange: BehaviorSubject<Appliance[]> = new BehaviorSubject<Appliance[]>([]);
|
||||||
|
|
||||||
|
get data(): Appliance[] {
|
||||||
|
return this.dataChange.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(private server: Server, private applianceService: ApplianceService) {
|
||||||
|
this.applianceService.list(this.server).subscribe((appliances: Appliance[]) => {
|
||||||
|
this.dataChange.next(appliances);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
export class ApplianceDataSource extends DataSource<Appliance> {
|
export class ApplianceDataSource extends DataSource<Appliance> {
|
||||||
filterChange = new BehaviorSubject('');
|
filterChange = new BehaviorSubject('');
|
||||||
|
|
||||||
get filter(): string { return this.filterChange.value; }
|
get filter(): string { return this.filterChange.value; }
|
||||||
set filter(filter: string) { this.filterChange.next(filter); }
|
set filter(filter: string) { this.filterChange.next(filter); }
|
||||||
|
|
||||||
constructor(private server: Server, private applianceService: ApplianceService) {
|
constructor(private applianceDatabase: ApplianceDatabase) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(): Observable<Appliance[]> {
|
connect(): Observable<Appliance[]> {
|
||||||
return this.applianceService.list(this.server);
|
const displayDataChanges = [
|
||||||
|
this.applianceDatabase.dataChange,
|
||||||
|
this.filterChange,
|
||||||
|
];
|
||||||
|
|
||||||
|
return Observable.merge(...displayDataChanges).map(() => {
|
||||||
|
return this.applianceDatabase.data.slice().filter((item: Appliance) => {
|
||||||
|
const searchStr = (item.name).toLowerCase();
|
||||||
|
return searchStr.indexOf(this.filter.toLowerCase()) !== -1;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {}
|
disconnect() {}
|
||||||
|
@ -20,6 +20,7 @@ export class ApplianceComponent implements OnInit {
|
|||||||
listAppliancesModal() {
|
listAppliancesModal() {
|
||||||
const dialogRef = this.dialog.open(ApplianceListDialogComponent, {
|
const dialogRef = this.dialog.open(ApplianceListDialogComponent, {
|
||||||
width: '600px',
|
width: '600px',
|
||||||
|
height: '560px',
|
||||||
data: {
|
data: {
|
||||||
'server': this.server
|
'server': this.server
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user