1
1
import { HydrusFilesService } from './../hydrus-files.service' ;
2
- import { Component , OnInit , Output , EventEmitter , ViewChild , ElementRef , Input , Optional , Self } from '@angular/core' ;
2
+ import { Component , OnInit , Output , EventEmitter , ViewChild , ElementRef , Input , Optional , Self , input } from '@angular/core' ;
3
3
import { COMMA , ENTER } from '@angular/cdk/keycodes' ;
4
4
import { MatChipInputEvent } from '@angular/material/chips' ;
5
- import { ControlValueAccessor , NgControl , UntypedFormControl } from '@angular/forms' ;
6
- import { switchMap } from 'rxjs/operators' ;
7
- import { MatAutocompleteSelectedEvent , MatAutocomplete } from '@angular/material/autocomplete' ;
8
- import { Observable , firstValueFrom , of } from 'rxjs' ;
5
+ import { ControlValueAccessor , FormControl , NgControl , UntypedFormControl } from '@angular/forms' ;
6
+ import { distinctUntilChanged , map , startWith , switchMap } from 'rxjs/operators' ;
7
+ import { MatAutocompleteSelectedEvent , MatAutocomplete , MatOption } from '@angular/material/autocomplete' ;
8
+ import { Observable , combineLatest , firstValueFrom , of } from 'rxjs' ;
9
9
import { HydrusTagsService } from '../hydrus-tags.service' ;
10
10
import { HydrusSearchTags , HydrusTagSearchTag , TagDisplayType , isSingleTag } from '../hydrus-tags' ;
11
11
import { MatDialog } from '@angular/material/dialog' ;
12
- import { allSystemPredicates , predicateGroups , SystemPredicate } from '../hydrus-system-predicates' ;
12
+ import { allSystemPredicates , predicateGroups , SystemPredicate , systemTagsForSearch } from '../hydrus-system-predicates' ;
13
13
import { SystemPredicateDialogComponent } from '../system-predicate-dialog/system-predicate-dialog.component' ;
14
14
import { TagInputDialogComponent } from '../tag-input-dialog/tag-input-dialog.component' ;
15
15
import { SettingsService } from '../settings.service' ;
@@ -38,6 +38,12 @@ interface ConvertedPredicateGroup {
38
38
predicates : ConvertedPredicate [ ]
39
39
}
40
40
41
+ export interface HydrusTagSearchTagUI {
42
+ value : string ,
43
+ count ?: number ,
44
+ systemPredicate ?: SystemPredicate
45
+ }
46
+
41
47
@Component ( {
42
48
selector : 'app-tag-input' ,
43
49
templateUrl : './tag-input.component.html' ,
@@ -50,9 +56,6 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
50
56
searchTags : HydrusSearchTags = [ ] ;
51
57
readonly separatorKeysCodes : number [ ] = [ ENTER , COMMA ] ;
52
58
53
- tagCtrl = new UntypedFormControl ( ) ;
54
- filteredTags : Observable < HydrusTagSearchTag [ ] > ;
55
-
56
59
//inputControl = new FormControl("", this.validators)
57
60
58
61
@Input ( ) enableOrSearch = true ;
@@ -69,6 +72,22 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
69
72
70
73
@Input ( ) enableSiblingParentsDialog = true ;
71
74
75
+ showSystemPredicateAutocompleteByDefault = input ( )
76
+
77
+
78
+ tagCtrl = new FormControl ( '' ) ;
79
+ filteredTagsFromAPI$ : Observable < HydrusTagSearchTagUI [ ] > = this . tagCtrl . valueChanges . pipe (
80
+ switchMap ( search => search && search . length >= 3 ? this . tagsService . searchTags ( search , this . displayType ) : of ( [ ] ) )
81
+ ) ;
82
+
83
+ filteredSystemPredicates$ : Observable < HydrusTagSearchTagUI [ ] > = this . tagCtrl . valueChanges . pipe (
84
+ map ( ( input ) => input ? systemTagsForSearch . filter ( p => p . value . startsWith ( input ) ) : [ ] ) ,
85
+ ) ;
86
+
87
+ filteredTags$ : Observable < HydrusTagSearchTagUI [ ] > = combineLatest ( [ this . filteredTagsFromAPI$ , this . filteredSystemPredicates$ , ] ) . pipe (
88
+ map ( ( [ api , predicates ] ) => [ ...api , ...predicates ] ) ,
89
+ )
90
+
72
91
@Output ( )
73
92
tags = new EventEmitter < HydrusSearchTags > ( ) ;
74
93
@@ -87,11 +106,7 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
87
106
if ( this . controlDir ) {
88
107
this . controlDir . valueAccessor = this
89
108
}
90
-
91
- this . filteredTags = this . tagCtrl . valueChanges . pipe (
92
- switchMap ( search => search && search . length >= 3 ? this . tagsService . searchTags ( search , this . displayType ) : of ( [ ] ) )
93
- ) ;
94
- }
109
+ }
95
110
96
111
favoriteTags = this . settingsService . appSettings . favoriteTags ;
97
112
@@ -180,8 +195,14 @@ export class TagInputComponent implements OnInit, ControlValueAccessor {
180
195
}
181
196
182
197
selected ( event : MatAutocompleteSelectedEvent ) : void {
183
- const negated = this . tagInput . nativeElement . value . startsWith ( '-' ) ;
184
- this . addSearchTag ( ( negated ? '-' : '' ) + event . option . value ) ;
198
+ const option : MatOption < HydrusTagSearchTagUI > = event . option
199
+ console . log ( option )
200
+ if ( option . value . systemPredicate ) {
201
+ this . systemPredicateButton ( option . value . systemPredicate )
202
+ } else {
203
+ const negated = this . tagInput . nativeElement . value . startsWith ( '-' ) ;
204
+ this . addSearchTag ( ( negated ? '-' : '' ) + option . value . value ) ;
205
+ }
185
206
this . tagInput . nativeElement . value = '' ;
186
207
this . tagCtrl . setValue ( null ) ;
187
208
}
0 commit comments