Skip to content

Commit

Permalink
Add OR search dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
floogulinc committed Sep 14, 2022
1 parent 9b17ab5 commit 3c85923
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { ComicComponent } from './comic/comic.component';
import { ImageListLoaderComponent } from './image-list-loader/image-list-loader.component';
import { ToolbarActionsComponent } from './toolbar-actions/toolbar-actions.component';
import { JoinPipe } from './utils/join.pipe';
import { OrSearchDialogComponent } from './or-search-dialog/or-search-dialog.component';


const MAT_MODULES = [
Expand Down Expand Up @@ -104,7 +105,8 @@ const MAT_MODULES = [
ComicComponent,
ImageListLoaderComponent,
ToolbarActionsComponent,
JoinPipe
JoinPipe,
OrSearchDialogComponent
],
imports: [
BrowserModule,
Expand Down
10 changes: 10 additions & 0 deletions src/app/or-search-dialog/or-search-dialog.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1 mat-dialog-title>Add OR Search</h1>
<div mat-dialog-content>
<div fxFlex>
<app-tag-input [(ngModel)]="tags" [enableOrSearch]="false" placeholder="Tags"></app-tag-input>
</div>
</div>
<div mat-dialog-actions align="end">
<button mat-button (click)="onNoClick()">Cancel</button>
<button mat-button [mat-dialog-close]="tags" cdkFocusInitial>Add</button>
</div>
Empty file.
23 changes: 23 additions & 0 deletions src/app/or-search-dialog/or-search-dialog.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { OrSearchDialogComponent } from './or-search-dialog.component';

describe('OrSearchDialogComponent', () => {
let component: OrSearchDialogComponent;
let fixture: ComponentFixture<OrSearchDialogComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ OrSearchDialogComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(OrSearchDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
23 changes: 23 additions & 0 deletions src/app/or-search-dialog/or-search-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { HydrusSearchTags } from '../hydrus-tags';

@Component({
selector: 'app-or-search-dialog',
templateUrl: './or-search-dialog.component.html',
styleUrls: ['./or-search-dialog.component.scss']
})
export class OrSearchDialogComponent implements OnInit {

tags: HydrusSearchTags = [];

constructor(public dialogRef: MatDialogRef<OrSearchDialogComponent>) { }

ngOnInit(): void {
}

onNoClick(): void {
this.dialogRef.close();
}

}
16 changes: 14 additions & 2 deletions src/app/tag-input/tag-input.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<mat-form-field class="tag-form-field">
<mat-form-field class="tag-form-field" appearance="outline">
<mat-label>{{placeholder}}</mat-label>
<mat-chip-list #chipList [attr.aria-label]="placeholder">
<ng-template ngFor let-tag [ngForOf]="searchTags" let-i="index" >
<mat-chip *ngIf="tag | isString; else arrayTag" [selectable]="false" color="primary"
Expand All @@ -18,7 +19,6 @@
</ng-template>
</ng-template>
<input #tagInput
[placeholder]="placeholder"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
matChipInputAddOnBlur="false"
Expand All @@ -43,4 +43,16 @@
</ng-template>
</ng-container>
</mat-autocomplete>

<button *ngIf="enableOrSearch || enableSystemPredicates" type="button" mat-icon-button matSuffix [matMenuTriggerFor]="menu" aria-label="Example icon-button with a menu">
<mat-icon>add</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button *ngIf="enableOrSearch" type="button" mat-menu-item (click)="orSearchButton()">
OR Search
</button>
<button *ngIf="enableSystemPredicates" type="button" mat-menu-item (click)="systemPredicateButton()">
System Predicate
</button>
</mat-menu>
</mat-form-field>
39 changes: 37 additions & 2 deletions src/app/tag-input/tag-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { MatAutocompleteSelectedEvent, MatAutocomplete } from '@angular/material
import { Observable, of } from 'rxjs';
import { HydrusTagsService } from '../hydrus-tags.service';
import { HydrusSearchTags, HydrusTagSearchTag } from '../hydrus-tags';
import { OrSearchDialogComponent } from '../or-search-dialog/or-search-dialog.component';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';

@Component({
selector: 'app-tag-input',
Expand All @@ -27,6 +29,10 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {

//inputControl = new FormControl("", this.validators)

@Input() enableOrSearch = true;

@Input() enableSystemPredicates = true;

@Input() placeholder: string;

@Input() defaultTags: HydrusSearchTags;
Expand All @@ -41,7 +47,9 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
@Optional() @Self() private controlDir: NgControl,
public filesService: HydrusFilesService,
public tagsService: HydrusTagsService,
private cd: ChangeDetectorRef) {
private cd: ChangeDetectorRef,
public dialog: MatDialog
) {
if (this.controlDir) {
this.controlDir.valueAccessor = this
}
Expand Down Expand Up @@ -85,7 +93,7 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
return;
}

const input = event.input;
const input = event.chipInput.inputElement;
const value = event.value.toLowerCase(); // Hydrus tags are always lowercase

this.addSearchTag(value);
Expand All @@ -107,6 +115,13 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
this.tags.emit(this.searchTags);
}

addSearchTagsArray(tags: HydrusSearchTags) {
if(tags.length > 0) {
this.searchTags.push([...tags]);
this.tags.emit(this.searchTags);
}
}

setSearchTags(tags: string[]) {
this.searchTags = [...tags];
this.tags.emit(this.searchTags);
Expand Down Expand Up @@ -149,5 +164,25 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
// return results;
// }

orSearchButton() {
const dialogRef = this.dialog.open<OrSearchDialogComponent, {}, HydrusSearchTags>(
OrSearchDialogComponent,
{
width: '80vw',
}
);

dialogRef.afterClosed().subscribe(result => {
if(result) {
this.addSearchTagsArray(result);
}
});

}

systemPredicateButton() {

}


}

0 comments on commit 3c85923

Please sign in to comment.