mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -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:
		| @@ -1,33 +1,36 @@ | ||||
| <div class="form-group paperless-input-select"> | ||||
|   <label [for]="inputId">{{title}}</label> | ||||
|   <div [class.input-group]="showPlusButton()"> | ||||
|     <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)" | ||||
|       (blur)="onTouched()"> | ||||
|     </ng-select> | ||||
|  | ||||
|     <div *ngIf="showPlusButton()" class="input-group-append"> | ||||
|       <button class="btn btn-outline-secondary" type="button" (click)="createNew.emit()"> | ||||
|         <svg class="buttonicon" fill="currentColor"> | ||||
|           <use xlink:href="assets/bootstrap-icons.svg#plus" /> | ||||
|         </svg> | ||||
|       </button> | ||||
|     <div [class.input-group]="allowCreateNew"> | ||||
|       <ng-select name="inputId" [(ngModel)]="value" | ||||
|         [disabled]="disabled" | ||||
|         [style.color]="textColor" | ||||
|         [style.background]="backgroundColor" | ||||
|         [clearable]="allowNull" | ||||
|         [items]="items" | ||||
|         [addTag]="allowCreateNew && addItemRef" | ||||
|         bindLabel="name" | ||||
|         bindValue="id" | ||||
|         (change)="onChange(value)" | ||||
|         (search)="onSearch($event)" | ||||
|         (focus)="clearLastSearchTerm()" | ||||
|         (clear)="clearLastSearchTerm()" | ||||
|         (blur)="onBlur()"> | ||||
|       </ng-select> | ||||
|       <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> | ||||
|   </div> | ||||
|   <small *ngIf="hint" class="form-text text-muted">{{hint}}</small> | ||||
|   <small *ngIf="getSuggestions().length > 0"> | ||||
|     <span i18n>Suggestions:</span>  | ||||
|     <ng-container *ngFor="let s of getSuggestions()"> | ||||
|       <a (click)="value = s.id; onChange(value)" [routerLink]="">{{s.name}}</a>  | ||||
|     </ng-container> | ||||
|      | ||||
|      | ||||
|  | ||||
|  | ||||
|   </small> | ||||
| </div> | ||||
|   | ||||
| @@ -16,6 +16,7 @@ export class SelectComponent extends AbstractInputComponent<number> { | ||||
|  | ||||
|   constructor() { | ||||
|     super() | ||||
|     this.addItemRef = this.addItem.bind(this) | ||||
|    } | ||||
|  | ||||
|   @Input() | ||||
| @@ -34,9 +35,13 @@ export class SelectComponent extends AbstractInputComponent<number> { | ||||
|   suggestions: number[] | ||||
|  | ||||
|   @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 | ||||
|   } | ||||
|  | ||||
| @@ -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" | ||||
|       [clearSearchOnAdd]="true" | ||||
|       [hideSelected]="true" | ||||
|       [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)"> | ||||
| @@ -39,8 +44,8 @@ | ||||
|     <ng-container *ngFor="let tag of getSuggestions()"> | ||||
|       <a (click)="addTag(tag.id)" [routerLink]="">{{tag.name}}</a>  | ||||
|     </ng-container> | ||||
|      | ||||
|      | ||||
|  | ||||
|  | ||||
|   </small> | ||||
|  | ||||
| </div> | ||||
|   | ||||
| @@ -17,8 +17,9 @@ import { TagService } from 'src/app/services/rest/tag.service'; | ||||
| }) | ||||
| 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[]) => {}; | ||||
|  | ||||
| @@ -56,6 +57,10 @@ export class TagsComponent implements OnInit, ControlValueAccessor { | ||||
|  | ||||
|   tags: PaperlessTag[] | ||||
|  | ||||
|   public createTagRef: (name) => void | ||||
|  | ||||
|   private _lastSearchTerm: string | ||||
|  | ||||
|   getTag(id) { | ||||
|     if (this.tags) { | ||||
|       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'}) | ||||
|     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 | ||||
| @@ -99,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); | ||||
|   } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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-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" | ||||
|                             (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" | ||||
|                             (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> | ||||
|  | ||||
|                     </ng-template> | ||||
|   | ||||
| @@ -128,9 +128,10 @@ export class DocumentDetailComponent implements OnInit { | ||||
|     this.documentForm.patchValue(doc) | ||||
|   } | ||||
|  | ||||
|   createDocumentType() { | ||||
|   createDocumentType(newName: string) { | ||||
|     var modal = this.modalService.open(DocumentTypeEditDialogComponent, {backdrop: 'static'}) | ||||
|     modal.componentInstance.dialogMode = 'create' | ||||
|     if (newName) modal.componentInstance.object = { name: newName } | ||||
|     modal.componentInstance.success.subscribe(newDocumentType => { | ||||
|       this.documentTypeService.listAll().subscribe(documentTypes => { | ||||
|         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'}) | ||||
|     modal.componentInstance.dialogMode = 'create' | ||||
|     if (newName) modal.componentInstance.object = { name: newName } | ||||
|     modal.componentInstance.success.subscribe(newCorrespondent => { | ||||
|       this.correspondentService.listAll().subscribe(correspondents => { | ||||
|         this.correspondents = correspondents.results | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonas Winkler
					Jonas Winkler