mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	Merge pull request #818 from shamoon/fix/issue-817
Support passing current term from tag / document type / correspondent search field to 'create new' dialog
This commit is contained in:
		
						commit
						acc317ddfd
					
				@ -1,20 +1,23 @@
 | 
				
			|||||||
<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 [class.input-group]="showPlusButton()">
 | 
					    <div [class.input-group]="allowCreateNew">
 | 
				
			||||||
      <ng-select name="inputId" [(ngModel)]="value"
 | 
					      <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]="allowCreateNew && addItemRef"
 | 
				
			||||||
        bindLabel="name"
 | 
					        bindLabel="name"
 | 
				
			||||||
        bindValue="id"
 | 
					        bindValue="id"
 | 
				
			||||||
        (change)="onChange(value)"
 | 
					        (change)="onChange(value)"
 | 
				
			||||||
      (blur)="onTouched()">
 | 
					        (search)="onSearch($event)"
 | 
				
			||||||
 | 
					        (focus)="clearLastSearchTerm()"
 | 
				
			||||||
 | 
					        (clear)="clearLastSearchTerm()"
 | 
				
			||||||
 | 
					        (blur)="onBlur()">
 | 
				
			||||||
      </ng-select>
 | 
					      </ng-select>
 | 
				
			||||||
 | 
					      <div *ngIf="allowCreateNew" class="input-group-append">
 | 
				
			||||||
    <div *ngIf="showPlusButton()" class="input-group-append">
 | 
					        <button class="btn btn-outline-secondary" type="button" (click)="addItem()">
 | 
				
			||||||
      <button class="btn btn-outline-secondary" type="button" (click)="createNew.emit()">
 | 
					 | 
				
			||||||
          <svg class="buttonicon" fill="currentColor">
 | 
					          <svg class="buttonicon" fill="currentColor">
 | 
				
			||||||
            <use xlink:href="assets/bootstrap-icons.svg#plus" />
 | 
					            <use xlink:href="assets/bootstrap-icons.svg#plus" />
 | 
				
			||||||
          </svg>
 | 
					          </svg>
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,7 @@ export class SelectComponent extends AbstractInputComponent<number> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  constructor() {
 | 
					  constructor() {
 | 
				
			||||||
    super()
 | 
					    super()
 | 
				
			||||||
 | 
					    this.addItemRef = this.addItem.bind(this)
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Input()
 | 
					  @Input()
 | 
				
			||||||
@ -34,9 +35,13 @@ export class SelectComponent extends AbstractInputComponent<number> {
 | 
				
			|||||||
  suggestions: number[]
 | 
					  suggestions: number[]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Output()
 | 
					  @Output()
 | 
				
			||||||
  createNew = new EventEmitter()
 | 
					  createNew = new EventEmitter<string>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  showPlusButton(): boolean {
 | 
					  public addItemRef: (name) => void
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private _lastSearchTerm: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  get allowCreateNew(): boolean {
 | 
				
			||||||
    return this.createNew.observers.length > 0
 | 
					    return this.createNew.observers.length > 0
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,4 +53,29 @@ export class SelectComponent extends AbstractInputComponent<number> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  addItem(name: string) {
 | 
				
			||||||
 | 
					    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);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,8 +7,13 @@
 | 
				
			|||||||
      [closeOnSelect]="false"
 | 
					      [closeOnSelect]="false"
 | 
				
			||||||
      [clearSearchOnAdd]="true"
 | 
					      [clearSearchOnAdd]="true"
 | 
				
			||||||
      [hideSelected]="true"
 | 
					      [hideSelected]="true"
 | 
				
			||||||
 | 
					      [addTag]="createTagRef"
 | 
				
			||||||
 | 
					      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)">
 | 
				
			||||||
 | 
				
			|||||||
@ -17,8 +17,9 @@ import { TagService } from 'src/app/services/rest/tag.service';
 | 
				
			|||||||
})
 | 
					})
 | 
				
			||||||
export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
					export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(private tagService: TagService, private modalService: NgbModal) { }
 | 
					  constructor(private tagService: TagService, private modalService: NgbModal) {
 | 
				
			||||||
 | 
					    this.createTagRef = this.createTag.bind(this)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onChange = (newValue: number[]) => {};
 | 
					  onChange = (newValue: number[]) => {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -56,6 +57,10 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  tags: PaperlessTag[]
 | 
					  tags: PaperlessTag[]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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)
 | 
				
			||||||
@ -74,9 +79,11 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createTag() {
 | 
					  createTag(name: string = null) {
 | 
				
			||||||
    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 }
 | 
				
			||||||
 | 
					    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
 | 
				
			||||||
@ -99,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);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -60,9 +60,9 @@
 | 
				
			|||||||
                        <app-input-number i18n-title title="Archive serial number" [error]="error?.archive_serial_number" formControlName='archive_serial_number'></app-input-number>
 | 
					                        <app-input-number i18n-title title="Archive serial number" [error]="error?.archive_serial_number" formControlName='archive_serial_number'></app-input-number>
 | 
				
			||||||
                        <app-input-date i18n-title title="Date created" formControlName="created" [error]="error?.created"></app-input-date>
 | 
					                        <app-input-date i18n-title title="Date created" formControlName="created" [error]="error?.created"></app-input-date>
 | 
				
			||||||
                        <app-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true"
 | 
					                        <app-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true"
 | 
				
			||||||
                            (createNew)="createCorrespondent()" [suggestions]="suggestions?.correspondents"></app-input-select>
 | 
					                            (createNew)="createCorrespondent($event)" [suggestions]="suggestions?.correspondents"></app-input-select>
 | 
				
			||||||
                        <app-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true"
 | 
					                        <app-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true"
 | 
				
			||||||
                            (createNew)="createDocumentType()" [suggestions]="suggestions?.document_types"></app-input-select>
 | 
					                            (createNew)="createDocumentType($event)" [suggestions]="suggestions?.document_types"></app-input-select>
 | 
				
			||||||
                        <app-input-tags formControlName="tags" [suggestions]="suggestions?.tags"></app-input-tags>
 | 
					                        <app-input-tags formControlName="tags" [suggestions]="suggestions?.tags"></app-input-tags>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    </ng-template>
 | 
					                    </ng-template>
 | 
				
			||||||
 | 
				
			|||||||
@ -128,9 +128,10 @@ export class DocumentDetailComponent implements OnInit {
 | 
				
			|||||||
    this.documentForm.patchValue(doc)
 | 
					    this.documentForm.patchValue(doc)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createDocumentType() {
 | 
					  createDocumentType(newName: string) {
 | 
				
			||||||
    var modal = this.modalService.open(DocumentTypeEditDialogComponent, {backdrop: 'static'})
 | 
					    var modal = this.modalService.open(DocumentTypeEditDialogComponent, {backdrop: 'static'})
 | 
				
			||||||
    modal.componentInstance.dialogMode = 'create'
 | 
					    modal.componentInstance.dialogMode = 'create'
 | 
				
			||||||
 | 
					    if (newName) modal.componentInstance.object = { name: newName }
 | 
				
			||||||
    modal.componentInstance.success.subscribe(newDocumentType => {
 | 
					    modal.componentInstance.success.subscribe(newDocumentType => {
 | 
				
			||||||
      this.documentTypeService.listAll().subscribe(documentTypes => {
 | 
					      this.documentTypeService.listAll().subscribe(documentTypes => {
 | 
				
			||||||
        this.documentTypes = documentTypes.results
 | 
					        this.documentTypes = documentTypes.results
 | 
				
			||||||
@ -139,9 +140,10 @@ export class DocumentDetailComponent implements OnInit {
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createCorrespondent() {
 | 
					  createCorrespondent(newName: string) {
 | 
				
			||||||
    var modal = this.modalService.open(CorrespondentEditDialogComponent, {backdrop: 'static'})
 | 
					    var modal = this.modalService.open(CorrespondentEditDialogComponent, {backdrop: 'static'})
 | 
				
			||||||
    modal.componentInstance.dialogMode = 'create'
 | 
					    modal.componentInstance.dialogMode = 'create'
 | 
				
			||||||
 | 
					    if (newName) modal.componentInstance.object = { name: newName }
 | 
				
			||||||
    modal.componentInstance.success.subscribe(newCorrespondent => {
 | 
					    modal.componentInstance.success.subscribe(newCorrespondent => {
 | 
				
			||||||
      this.correspondentService.listAll().subscribe(correspondents => {
 | 
					      this.correspondentService.listAll().subscribe(correspondents => {
 | 
				
			||||||
        this.correspondents = correspondents.results
 | 
					        this.correspondents = correspondents.results
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user