mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	feat(date.component): adding suggestions to frontend
This commit is contained in:
		| @@ -12,4 +12,10 @@ | |||||||
|   </div> |   </div> | ||||||
|   <div class="invalid-feedback" i18n>Invalid date.</div> |   <div class="invalid-feedback" i18n>Invalid date.</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"> | ||||||
|  |     <span i18n>Suggestions:</span>  | ||||||
|  |     <ng-container *ngFor="let s of getSuggestions()"> | ||||||
|  |       <a (click)="onSuggestionClick(s)" [routerLink]="[]">{{s}}</a>  | ||||||
|  |     </ng-container> | ||||||
|  |   </small> | ||||||
| </div> | </div> | ||||||
|   | |||||||
| @@ -1,8 +1,10 @@ | |||||||
| import { Component, forwardRef, OnInit } from '@angular/core' | import { Component, forwardRef, Input, OnInit } from '@angular/core' | ||||||
| import { NG_VALUE_ACCESSOR } from '@angular/forms' | import { NG_VALUE_ACCESSOR } from '@angular/forms' | ||||||
| import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap' | import { | ||||||
|  |   NgbDateParserFormatter, | ||||||
|  |   NgbDateStruct, | ||||||
|  | } from '@ng-bootstrap/ng-bootstrap' | ||||||
| import { SettingsService } from 'src/app/services/settings.service' | import { SettingsService } from 'src/app/services/settings.service' | ||||||
| import { LocalizedDateParserFormatter } from 'src/app/utils/ngb-date-parser-formatter' |  | ||||||
| import { AbstractInputComponent } from '../abstract-input' | import { AbstractInputComponent } from '../abstract-input' | ||||||
|  |  | ||||||
| @Component({ | @Component({ | ||||||
| @@ -28,6 +30,40 @@ export class DateComponent | |||||||
|     super() |     super() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   @Input() | ||||||
|  |   suggestions: Date[] | ||||||
|  |  | ||||||
|  |   getSuggestions() { | ||||||
|  |     if (this.suggestions == null) return [] | ||||||
|  |  | ||||||
|  |     return this.suggestions | ||||||
|  |       .map((s) => new Date(s)) // required to call the date functions below | ||||||
|  |       .filter( | ||||||
|  |         (d) => | ||||||
|  |           this.value === null || // if value is not set, take all suggestions | ||||||
|  |           d.toISOString().slice(0, 10) != this.value // otherwise filter out the current value | ||||||
|  |       ) | ||||||
|  |       .map((s) => | ||||||
|  |         this.ngbDateParserFormatter.format({ | ||||||
|  |           year: s.getFullYear(), | ||||||
|  |           month: s.getMonth() + 1, // month of Date is zero based | ||||||
|  |           day: s.getDate(), | ||||||
|  |         }) | ||||||
|  |       ) | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   onSuggestionClick(dateString: string) { | ||||||
|  |     const parsedNgDate = this.ngbDateParserFormatter.parse(dateString) | ||||||
|  |     this.writeValue(this.formatDateAsYYYYMMDD(parsedNgDate)) | ||||||
|  |     this.onChange(this.value) | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   formatDateAsYYYYMMDD(date: NgbDateStruct) { | ||||||
|  |     const monthPrefix = date.month > 9 ? '' : '0' | ||||||
|  |     const dayPrefix = date.day > 9 ? '' : '0' | ||||||
|  |     return `${date.year}-${monthPrefix}${date.month}-${dayPrefix}${date.day}` | ||||||
|  |   } | ||||||
|  |  | ||||||
|   ngOnInit(): void { |   ngOnInit(): void { | ||||||
|     super.ngOnInit() |     super.ngOnInit() | ||||||
|     this.placeholder = this.settings.getLocalizedDateInputFormat() |     this.placeholder = this.settings.getLocalizedDateInputFormat() | ||||||
|   | |||||||
| @@ -74,7 +74,8 @@ | |||||||
|  |  | ||||||
|                         <app-input-text #inputTitle i18n-title title="Title" formControlName="title" (keyup)="titleKeyUp($event)" [error]="error?.title"></app-input-text> |                         <app-input-text #inputTitle i18n-title title="Title" formControlName="title" (keyup)="titleKeyUp($event)" [error]="error?.title"></app-input-text> | ||||||
|                         <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_date" [error]="error?.created_date"></app-input-date> |                         <app-input-date i18n-title title="Date created" formControlName="created_date" [suggestions]="suggestions?.dates" | ||||||
|  |                             [error]="error?.created_date"></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($event)" [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" | ||||||
|   | |||||||
| @@ -6,4 +6,6 @@ export interface PaperlessDocumentSuggestions { | |||||||
|   document_types?: number[] |   document_types?: number[] | ||||||
|  |  | ||||||
|   storage_paths?: number[] |   storage_paths?: number[] | ||||||
|  |  | ||||||
|  |   dates?: Date[] | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matthias Eck
					Matthias Eck