Merge pull request #1367 from Eckii24/feat/date-suggestions

Adding date suggestions to the documents details view
This commit is contained in:
shamoon
2022-08-25 11:47:37 -07:00
committed by GitHub
11 changed files with 114 additions and 34 deletions

View File

@@ -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>&nbsp;
<ng-container *ngFor="let s of getSuggestions()">
<a (click)="onSuggestionClick(s)" [routerLink]="[]">{{s}}</a>&nbsp;
</ng-container>
</small>
</div>

View File

@@ -1,4 +1,4 @@
import { Component, forwardRef, OnInit } from '@angular/core'
import { Component, forwardRef, Input, OnInit } from '@angular/core'
import { NG_VALUE_ACCESSOR } from '@angular/forms'
import {
NgbDateAdapter,
@@ -31,6 +31,28 @@ export class DateComponent
super()
}
@Input()
suggestions: string[]
getSuggestions() {
return this.suggestions == null
? []
: this.suggestions
.map((s) => this.ngbDateParserFormatter.parse(s))
.filter(
(d) =>
this.value === null || // if value is not set, take all suggestions
this.value != this.isoDateAdapter.toModel(d) // otherwise filter out current date
)
.map((s) => this.ngbDateParserFormatter.format(s))
}
onSuggestionClick(dateString: string) {
const parsedDate = this.ngbDateParserFormatter.parse(dateString)
this.writeValue(this.isoDateAdapter.toModel(parsedDate))
this.onChange(this.value)
}
ngOnInit(): void {
super.ngOnInit()
this.placeholder = this.settings.getLocalizedDateInputFormat()

View File

@@ -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"

View File

@@ -6,4 +6,6 @@ export interface PaperlessDocumentSuggestions {
document_types?: number[]
storage_paths?: number[]
dates?: string[] // ISO-formatted date string e.g. 2022-11-03
}