#75 - add quick filter to file box
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2021-02-04 15:39:32 -06:00
parent 53a6d6d316
commit ed81610f31
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 49 additions and 2 deletions

View File

@ -20,13 +20,23 @@
<ion-button (click)="onActionClick('folder-add')"><i class="fa fa-folder-plus"></i>&nbsp;&nbsp;Folder</ion-button> <ion-button (click)="onActionClick('folder-add')"><i class="fa fa-folder-plus"></i>&nbsp;&nbsp;Folder</ion-button>
<ion-button (click)="onUploadFilesClick($event)"><i class="fa fa-upload"></i>&nbsp;&nbsp;Upload Files</ion-button> <ion-button (click)="onUploadFilesClick($event)"><i class="fa fa-upload"></i>&nbsp;&nbsp;Upload Files</ion-button>
<div class="buffer"></div>
<div class="filter">
<i class="filter-icon fa fa-search"></i>
<ion-input
placeholder="Quick filter..."
(ionChange)="onQuickFilterChange($event)"
></ion-input>
</div>
<input type="file" name="fileInput" #fileInput multiple style="display: none;" (change)="onUploadFilesChange($event)"> <input type="file" name="fileInput" #fileInput multiple style="display: none;" (change)="onUploadFilesChange($event)">
</ion-buttons> </ion-buttons>
</ion-toolbar> </ion-toolbar>
<div class="content-wrapper" (contextmenu)="onSurfaceContextMenu($event)"> <div class="content-wrapper" (contextmenu)="onSurfaceContextMenu($event)">
<div *ngIf="!items || !items.length" class="empty-text" (contextmenu)="onSurfaceContextMenu($event)">No files or folders.</div> <div *ngIf="!items || !items.length" class="empty-text" (contextmenu)="onSurfaceContextMenu($event)">No files or folders.</div>
<div *ngIf="items && items.length" class="folders"> <div *ngIf="items && items.length" class="folders">
<ng-container *ngFor="let item of items"> <ng-container *ngFor="let item of (visibleFilterItems ? visibleFilterItems : items)">
<div class="folder item" *ngIf="item.type === 'folder'" (contextmenu)="onItemContextMenu(item, $event)" (dblclick)="onItemActivate(item)"> <div class="folder item" *ngIf="item.type === 'folder'" (contextmenu)="onItemContextMenu(item, $event)" (dblclick)="onItemActivate(item)">
<div class="icon folder"><i class="fa fa-folder"></i></div> <div class="icon folder"><i class="fa fa-folder"></i></div>
<div class="title">{{ item.title }}</div> <div class="title">{{ item.title }}</div>
@ -34,7 +44,7 @@
</ng-container> </ng-container>
</div> </div>
<div *ngIf="items && items.length" class="files"> <div *ngIf="items && items.length" class="files">
<ng-container *ngFor="let item of items"> <ng-container *ngFor="let item of (visibleFilterItems ? visibleFilterItems : items)">
<div class="folder item" *ngIf="item.type === 'file'" (contextmenu)="onItemContextMenu(item, $event)" (dblclick)="onItemActivate(item)"> <div class="folder item" *ngIf="item.type === 'file'" (contextmenu)="onItemContextMenu(item, $event)" (dblclick)="onItemActivate(item)">
<div [ngClass]="'icon ' + item.category"><i [ngClass]="categoryIcons[item.category]"></i></div> <div [ngClass]="'icon ' + item.category"><i [ngClass]="categoryIcons[item.category]"></i></div>
<div class="title">{{ item.title }}</div> <div class="title">{{ item.title }}</div>

View File

@ -88,6 +88,19 @@ div.file-box-wrapper {
} }
} }
.buffer {
flex: 1;
}
.filter {
display: flex;
flex-direction: row;
.filter-icon {
margin-top: 10px;
}
}
.file-box-wrapper.dark { .file-box-wrapper.dark {
.content-wrapper { .content-wrapper {
background: #222; background: #222;

View File

@ -57,6 +57,9 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
public fileBoxName = 'New File Box'; public fileBoxName = 'New File Box';
public record?: FileBoxRecord; public record?: FileBoxRecord;
public quickFilterValue?: string;
public visibleFilterItems?: FileBoxItem[];
public history: FileBoxRecord[] = []; public history: FileBoxRecord[] = [];
public items: FileBoxItem[] = []; public items: FileBoxItem[] = [];
@ -138,6 +141,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
const children = await this.api.getFileBoxChildren(this.page.UUID, this.record.UUID); const children = await this.api.getFileBoxChildren(this.page.UUID, this.record.UUID);
this.items = [...children, ...files]; this.items = [...children, ...files];
this.refilter();
} }
public async navigateUp() { public async navigateUp() {
@ -452,4 +456,24 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
await alert.present(); await alert.present();
} }
onQuickFilterChange(event) {
this.quickFilterValue = event.detail.value || undefined;
this.refilter();
}
refilter() {
if ( this.quickFilterValue ) {
let visible = [...this.items];
const parts = this.quickFilterValue.toLowerCase().split(/\s/);
for ( const part of parts ) {
visible = visible.filter(item => item.title.toLowerCase().includes(part));
}
this.visibleFilterItems = visible;
} else {
this.visibleFilterItems = undefined;
}
}
} }