A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
feat(date.component): adding suggestions to frontend
Matthias Eckc52d18da1f59
diff --git a/src-ui/src/app/components/common/input/date/date.component.html b/src-ui/src/app/components/common/input/date/date.component.htmlindex e742ead9b..926429a8d 100644--- a/src-ui/src/app/components/common/input/date/date.component.html+++ b/src-ui/src/app/components/common/input/date/date.component.html@@ -12,4 +12,10 @@</div><div class="invalid-feedback" i18n>Invalid date.</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)="onSuggestionClick(s)" [routerLink]="[]">{{s}}</a> + </ng-container>+ </small></div>diff --git a/src-ui/src/app/components/common/input/date/date.component.ts b/src-ui/src/app/components/common/input/date/date.component.tsindex 44e7c7513..cf475df5e 100644--- a/src-ui/src/app/components/common/input/date/date.component.ts+++ b/src-ui/src/app/components/common/input/date/date.component.ts@@ -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 { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap'+import {+ NgbDateParserFormatter,+ NgbDateStruct,+} from '@ng-bootstrap/ng-bootstrap'import { SettingsService } from 'src/app/services/settings.service'-import { LocalizedDateParserFormatter } from 'src/app/utils/ngb-date-parser-formatter'import { AbstractInputComponent } from '../abstract-input'@Component({@@ -28,6 +30,40 @@ export class DateComponentsuper()}+ @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 {super.ngOnInit()this.placeholder = this.settings.getLocalizedDateInputFormat()diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.htmlindex 6c8fc463f..ea191e55c 100644--- a/src-ui/src/app/components/document-detail/document-detail.component.html+++ b/src-ui/src/app/components/document-detail/document-detail.component.html@@ -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-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"(createNew)="createCorrespondent($event)" [suggestions]="suggestions?.correspondents"></app-input-select><app-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true"diff --git a/src-ui/src/app/data/paperless-document-suggestions.ts b/src-ui/src/app/data/paperless-document-suggestions.tsindex 47d480985..9f976d71b 100644--- a/src-ui/src/app/data/paperless-document-suggestions.ts+++ b/src-ui/src/app/data/paperless-document-suggestions.ts@@ -6,4 +6,6 @@ export interface PaperlessDocumentSuggestions {document_types?: number[]storage_paths?: number[]++ dates?: Date[]}