mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	Add back plus button which retains filter text
This commit is contained in:
		
							parent
							
								
									026c213ea4
								
							
						
					
					
						commit
						ec4ec41552
					
				@ -1,6 +1,6 @@
 | 
			
		||||
<div class="form-group paperless-input-select">
 | 
			
		||||
  <label [for]="inputId">{{title}}</label>
 | 
			
		||||
  <div>
 | 
			
		||||
    <div [class.input-group]="allowCreateNew">
 | 
			
		||||
      <ng-select *ngIf="allowCreateNew; else noAddTag" name="inputId" [(ngModel)]="value"
 | 
			
		||||
        [disabled]="disabled"
 | 
			
		||||
        [style.color]="textColor"
 | 
			
		||||
@ -10,7 +10,11 @@
 | 
			
		||||
        [addTag]="addItemRef"
 | 
			
		||||
        bindLabel="name"
 | 
			
		||||
        bindValue="id"
 | 
			
		||||
      (blur)="onTouched()">
 | 
			
		||||
        (change)="onChange(value)"
 | 
			
		||||
        (search)="onSearch($event)"
 | 
			
		||||
        (focus)="clearLastSearchTerm()"
 | 
			
		||||
        (clear)="clearLastSearchTerm()"
 | 
			
		||||
        (blur)="onBlur()">
 | 
			
		||||
      </ng-select>
 | 
			
		||||
      <ng-template #noAddTag>
 | 
			
		||||
        <ng-select name="inputId" [(ngModel)]="value"
 | 
			
		||||
@ -21,9 +25,20 @@
 | 
			
		||||
          [items]="items"
 | 
			
		||||
          bindLabel="name"
 | 
			
		||||
          bindValue="id"
 | 
			
		||||
        (blur)="onTouched()">
 | 
			
		||||
          (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="getSuggestions().length > 0">
 | 
			
		||||
 | 
			
		||||
@ -39,6 +39,8 @@ export class SelectComponent extends AbstractInputComponent<number> {
 | 
			
		||||
 | 
			
		||||
  public addItemRef: (name) => void
 | 
			
		||||
 | 
			
		||||
  private _lastSearchTerm: string
 | 
			
		||||
 | 
			
		||||
  get allowCreateNew(): boolean {
 | 
			
		||||
    return this.createNew.observers.length > 0
 | 
			
		||||
  }
 | 
			
		||||
@ -52,7 +54,28 @@ export class SelectComponent extends AbstractInputComponent<number> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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">
 | 
			
		||||
  <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"
 | 
			
		||||
      [multiple]="true"
 | 
			
		||||
      [closeOnSelect]="false"
 | 
			
		||||
@ -10,7 +10,10 @@
 | 
			
		||||
      [addTag]="createTagRef"
 | 
			
		||||
      addTagText="Add tag"
 | 
			
		||||
      (change)="onChange(value)"
 | 
			
		||||
      (blur)="onTouched()">
 | 
			
		||||
      (search)="onSearch($event)"
 | 
			
		||||
      (focus)="clearLastSearchTerm()"
 | 
			
		||||
      (clear)="clearLastSearchTerm()"
 | 
			
		||||
      (blur)="onBlur()">
 | 
			
		||||
 | 
			
		||||
      <ng-template ng-label-tmp let-item="item">
 | 
			
		||||
        <span class="tag-wrap tag-wrap-delete" (click)="removeTag(item.id)">
 | 
			
		||||
@ -26,6 +29,14 @@
 | 
			
		||||
        </div>
 | 
			
		||||
      </ng-template>
 | 
			
		||||
    </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>
 | 
			
		||||
  <small class="form-text text-muted" *ngIf="hint">{{hint}}</small>
 | 
			
		||||
  <small *ngIf="getSuggestions().length > 0">
 | 
			
		||||
 | 
			
		||||
@ -59,6 +59,8 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
			
		||||
 | 
			
		||||
  public createTagRef: (name) => void
 | 
			
		||||
 | 
			
		||||
  private _lastSearchTerm: string
 | 
			
		||||
 | 
			
		||||
  getTag(id) {
 | 
			
		||||
    if (this.tags) {
 | 
			
		||||
      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'})
 | 
			
		||||
    modal.componentInstance.dialogMode = 'create'
 | 
			
		||||
    if (name) modal.componentInstance.object = { name: name }
 | 
			
		||||
    else if (this._lastSearchTerm) modal.componentInstance.object = { name: this._lastSearchTerm }
 | 
			
		||||
    modal.componentInstance.success.subscribe(newTag => {
 | 
			
		||||
      this.tagService.listAll().subscribe(tags => {
 | 
			
		||||
        this.tags = tags.results
 | 
			
		||||
@ -103,4 +106,18 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
			
		||||
    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 {
 | 
			
		||||
      height: 100%;
 | 
			
		||||
      border-top-right-radius: 0;
 | 
			
		||||
      border-bottom-right-radius: 0;
 | 
			
		||||
 | 
			
		||||
      .ng-value-container .ng-input {
 | 
			
		||||
        top: 10px;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user