mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Add back plus button which retains filter text
This commit is contained in:
		| @@ -1,30 +1,45 @@ | |||||||
| <div class="form-group paperless-input-select"> | <div class="form-group paperless-input-select"> | ||||||
|   <label [for]="inputId">{{title}}</label> |   <label [for]="inputId">{{title}}</label> | ||||||
|   <div> |     <div [class.input-group]="allowCreateNew"> | ||||||
|     <ng-select *ngIf="allowCreateNew; else noAddTag" name="inputId" [(ngModel)]="value" |       <ng-select *ngIf="allowCreateNew; else noAddTag" name="inputId" [(ngModel)]="value" | ||||||
|       [disabled]="disabled" |  | ||||||
|       [style.color]="textColor" |  | ||||||
|       [style.background]="backgroundColor" |  | ||||||
|       [clearable]="allowNull" |  | ||||||
|       [items]="items" |  | ||||||
|       [addTag]="addItemRef" |  | ||||||
|       bindLabel="name" |  | ||||||
|       bindValue="id" |  | ||||||
|       (blur)="onTouched()"> |  | ||||||
|     </ng-select> |  | ||||||
|     <ng-template #noAddTag> |  | ||||||
|       <ng-select name="inputId" [(ngModel)]="value" |  | ||||||
|         [disabled]="disabled" |         [disabled]="disabled" | ||||||
|         [style.color]="textColor" |         [style.color]="textColor" | ||||||
|         [style.background]="backgroundColor" |         [style.background]="backgroundColor" | ||||||
|         [clearable]="allowNull" |         [clearable]="allowNull" | ||||||
|         [items]="items" |         [items]="items" | ||||||
|  |         [addTag]="addItemRef" | ||||||
|         bindLabel="name" |         bindLabel="name" | ||||||
|         bindValue="id" |         bindValue="id" | ||||||
|         (blur)="onTouched()"> |         (change)="onChange(value)" | ||||||
|  |         (search)="onSearch($event)" | ||||||
|  |         (focus)="clearLastSearchTerm()" | ||||||
|  |         (clear)="clearLastSearchTerm()" | ||||||
|  |         (blur)="onBlur()"> | ||||||
|       </ng-select> |       </ng-select> | ||||||
|     </ng-template> |       <ng-template #noAddTag> | ||||||
|   </div> |         <ng-select name="inputId" [(ngModel)]="value" | ||||||
|  |           [disabled]="disabled" | ||||||
|  |           [style.color]="textColor" | ||||||
|  |           [style.background]="backgroundColor" | ||||||
|  |           [clearable]="allowNull" | ||||||
|  |           [items]="items" | ||||||
|  |           bindLabel="name" | ||||||
|  |           bindValue="id" | ||||||
|  |           (change)="onChange(value)" | ||||||
|  |           (search)="onSearch($event)" | ||||||
|  |           (focus)="clearLastSearchTerm()" | ||||||
|  |           (clear)="clearLastSearchTerm()" | ||||||
|  |           (blur)="onBlur()"> | ||||||
|  |         </ng-select> | ||||||
|  |       </ng-template> | ||||||
|  |       <div *ngIf="allowCreateNew" class="input-group-append"> | ||||||
|  |         <button class="btn btn-outline-secondary" type="button" (click)="addItem()"> | ||||||
|  |           <svg class="buttonicon" fill="currentColor"> | ||||||
|  |             <use xlink:href="assets/bootstrap-icons.svg#plus" /> | ||||||
|  |           </svg> | ||||||
|  |         </button> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|   <small *ngIf="hint" class="form-text text-muted">{{hint}}</small> |   <small *ngIf="hint" class="form-text text-muted">{{hint}}</small> | ||||||
|   <small *ngIf="getSuggestions().length > 0"> |   <small *ngIf="getSuggestions().length > 0"> | ||||||
|     <span i18n>Suggestions:</span>  |     <span i18n>Suggestions:</span>  | ||||||
|   | |||||||
| @@ -39,6 +39,8 @@ export class SelectComponent extends AbstractInputComponent<number> { | |||||||
|  |  | ||||||
|   public addItemRef: (name) => void |   public addItemRef: (name) => void | ||||||
|  |  | ||||||
|  |   private _lastSearchTerm: string | ||||||
|  |  | ||||||
|   get allowCreateNew(): boolean { |   get allowCreateNew(): boolean { | ||||||
|     return this.createNew.observers.length > 0 |     return this.createNew.observers.length > 0 | ||||||
|   } |   } | ||||||
| @@ -52,7 +54,28 @@ export class SelectComponent extends AbstractInputComponent<number> { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   addItem(name: string) { |   addItem(name: string) { | ||||||
|     this.createNew.next(name) |     if (name) this.createNew.next(name) | ||||||
|  |     else this.createNew.next(this._lastSearchTerm) | ||||||
|  |     this.clearLastSearchTerm() | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   clickNew() { | ||||||
|  |     this.createNew.next(this._lastSearchTerm) | ||||||
|  |     this.clearLastSearchTerm() | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   clearLastSearchTerm() { | ||||||
|  |     this._lastSearchTerm = null | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   onSearch($event) { | ||||||
|  |     this._lastSearchTerm = $event.term | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   onBlur() { | ||||||
|  |     setTimeout(() => { | ||||||
|  |       this.clearLastSearchTerm() | ||||||
|  |     }, 3000); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| <div class="form-group paperless-input-select paperless-input-tags"> | <div class="form-group paperless-input-select paperless-input-tags"> | ||||||
|   <label for="tags" i18n>Tags</label> |   <label for="tags" i18n>Tags</label> | ||||||
|  |  | ||||||
|   <div class="flex-nowrap"> |   <div class="input-group flex-nowrap"> | ||||||
|     <ng-select name="tags" [items]="tags" bindLabel="name" bindValue="id" [(ngModel)]="value" |     <ng-select name="tags" [items]="tags" bindLabel="name" bindValue="id" [(ngModel)]="value" | ||||||
|       [multiple]="true" |       [multiple]="true" | ||||||
|       [closeOnSelect]="false" |       [closeOnSelect]="false" | ||||||
| @@ -10,7 +10,10 @@ | |||||||
|       [addTag]="createTagRef" |       [addTag]="createTagRef" | ||||||
|       addTagText="Add tag" |       addTagText="Add tag" | ||||||
|       (change)="onChange(value)" |       (change)="onChange(value)" | ||||||
|       (blur)="onTouched()"> |       (search)="onSearch($event)" | ||||||
|  |       (focus)="clearLastSearchTerm()" | ||||||
|  |       (clear)="clearLastSearchTerm()" | ||||||
|  |       (blur)="onBlur()"> | ||||||
|  |  | ||||||
|       <ng-template ng-label-tmp let-item="item"> |       <ng-template ng-label-tmp let-item="item"> | ||||||
|         <span class="tag-wrap tag-wrap-delete" (click)="removeTag(item.id)"> |         <span class="tag-wrap tag-wrap-delete" (click)="removeTag(item.id)"> | ||||||
| @@ -26,6 +29,14 @@ | |||||||
|         </div> |         </div> | ||||||
|       </ng-template> |       </ng-template> | ||||||
|     </ng-select> |     </ng-select> | ||||||
|  |  | ||||||
|  |     <div class="input-group-append"> | ||||||
|  |       <button class="btn btn-outline-secondary" type="button" (click)="createTag()"> | ||||||
|  |         <svg class="buttonicon" fill="currentColor"> | ||||||
|  |           <use xlink:href="assets/bootstrap-icons.svg#plus" /> | ||||||
|  |         </svg> | ||||||
|  |       </button> | ||||||
|  |     </div> | ||||||
|   </div> |   </div> | ||||||
|   <small class="form-text text-muted" *ngIf="hint">{{hint}}</small> |   <small class="form-text text-muted" *ngIf="hint">{{hint}}</small> | ||||||
|   <small *ngIf="getSuggestions().length > 0"> |   <small *ngIf="getSuggestions().length > 0"> | ||||||
|   | |||||||
| @@ -56,9 +56,11 @@ export class TagsComponent implements OnInit, ControlValueAccessor { | |||||||
|   value: number[] |   value: number[] | ||||||
|  |  | ||||||
|   tags: PaperlessTag[] |   tags: PaperlessTag[] | ||||||
|    |  | ||||||
|   public createTagRef: (name) => void |   public createTagRef: (name) => void | ||||||
|  |  | ||||||
|  |   private _lastSearchTerm: string | ||||||
|  |  | ||||||
|   getTag(id) { |   getTag(id) { | ||||||
|     if (this.tags) { |     if (this.tags) { | ||||||
|       return this.tags.find(tag => tag.id == id) |       return this.tags.find(tag => tag.id == id) | ||||||
| @@ -81,6 +83,7 @@ export class TagsComponent implements OnInit, ControlValueAccessor { | |||||||
|     var modal = this.modalService.open(TagEditDialogComponent, {backdrop: 'static'}) |     var modal = this.modalService.open(TagEditDialogComponent, {backdrop: 'static'}) | ||||||
|     modal.componentInstance.dialogMode = 'create' |     modal.componentInstance.dialogMode = 'create' | ||||||
|     if (name) modal.componentInstance.object = { name: name } |     if (name) modal.componentInstance.object = { name: name } | ||||||
|  |     else if (this._lastSearchTerm) modal.componentInstance.object = { name: this._lastSearchTerm } | ||||||
|     modal.componentInstance.success.subscribe(newTag => { |     modal.componentInstance.success.subscribe(newTag => { | ||||||
|       this.tagService.listAll().subscribe(tags => { |       this.tagService.listAll().subscribe(tags => { | ||||||
|         this.tags = tags.results |         this.tags = tags.results | ||||||
| @@ -103,4 +106,18 @@ export class TagsComponent implements OnInit, ControlValueAccessor { | |||||||
|     this.onChange(this.value) |     this.onChange(this.value) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   clearLastSearchTerm() { | ||||||
|  |     this._lastSearchTerm = null | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   onSearch($event) { | ||||||
|  |     this._lastSearchTerm = $event.term | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   onBlur() { | ||||||
|  |     setTimeout(() => { | ||||||
|  |       this.clearLastSearchTerm() | ||||||
|  |     }, 3000); | ||||||
|  |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -77,6 +77,8 @@ body { | |||||||
|  |  | ||||||
|     .ng-select-container { |     .ng-select-container { | ||||||
|       height: 100%; |       height: 100%; | ||||||
|  |       border-top-right-radius: 0; | ||||||
|  |       border-bottom-right-radius: 0; | ||||||
|  |  | ||||||
|       .ng-value-container .ng-input { |       .ng-value-container .ng-input { | ||||||
|         top: 10px; |         top: 10px; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon