mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Merge pull request #1367 from Eckii24/feat/date-suggestions
Adding date suggestions to the documents details view
This commit is contained in:
@@ -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>
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user