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()