Skip to content

Commit

Permalink
fix: search bar filter now persists between list refreshes
Browse files Browse the repository at this point in the history
Refs: #101
  • Loading branch information
urz9999 committed Apr 29, 2021
1 parent a16d77d commit ad7137a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/session/session/session.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<a (click)="createAccount();" tooltip="Create Account" class="small-btn"><i class="far fa-plus"></i></a>
<span class="search-bar">
<input type="text" (keyup)="filterSessions($any($event.target).value)" placeholder="Search by..."/>
<input #filterField type="text" (keyup)="filterSessions($any($event.target).value)" placeholder="Search by..."/>
<i class="far fa-search"></i>
</span>
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/app/session/session/session.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, NgZone, OnDestroy, OnInit} from '@angular/core';
import {Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {WorkspaceService} from '../../services/workspace.service';
import {ConfigurationService} from '../../services-system/configuration.service';
import {ActivatedRoute, Router} from '@angular/router';
Expand Down Expand Up @@ -46,6 +46,9 @@ export class SessionComponent extends AntiMemLeak implements OnInit, OnDestroy {

workspace;

@ViewChild('filterField', { static: false})
filterField: ElementRef;

constructor(
private router: Router,
private route: ActivatedRoute,
Expand Down Expand Up @@ -116,6 +119,9 @@ export class SessionComponent extends AntiMemLeak implements OnInit, OnDestroy {
this.zone.run(() => {
this.activeSessions = this.sessionService.listSessions().filter( session => session.active === true);
this.notActiveSessions = this.sessionService.alterOrderByTime(this.sessionService.listSessions().filter( session => session.active === false));
if (this.filterField) {
this.filterInactiveSessions(this.filterField.nativeElement.value);
}
});
}

Expand All @@ -129,6 +135,10 @@ export class SessionComponent extends AntiMemLeak implements OnInit, OnDestroy {

filterSessions(query) {
this.getSessions();
this.filterInactiveSessions(query);
}

filterInactiveSessions(query) {
if (query !== '') {
this.notActiveSessions = this.notActiveSessions.filter(s => {
const idpID = this.workspace.idpUrl.filter(idp => idp && idp.url.toLowerCase().indexOf(query.toLowerCase()) > -1).map(m => m.id);
Expand Down

0 comments on commit ad7137a

Please sign in to comment.