mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 11:33:04 +00:00
27 lines
917 B
TypeScript
27 lines
917 B
TypeScript
import { Pipe, PipeTransform } from '@angular/core';
|
|
import { AbstractControl } from '@angular/forms';
|
|
import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap/datepicker/ngb-date-struct';
|
|
import { AccessesConditionOption } from '../../../core/config/models/config-accesses-conditions-options.model';
|
|
|
|
@Pipe({
|
|
// eslint-disable-next-line @angular-eslint/pipe-prefix
|
|
name: 'maxEndDate',
|
|
pure: false
|
|
})
|
|
export class ControlMaxEndDatePipe implements PipeTransform {
|
|
transform(control: AbstractControl, dropdownOptions: AccessesConditionOption[]): NgbDateStruct | null {
|
|
const { itemName } = control.value;
|
|
const item = dropdownOptions.find((x) => x.name === itemName);
|
|
if (!item?.hasEndDate) {
|
|
return null;
|
|
}
|
|
const date = new Date(item.maxEndDate);
|
|
return {
|
|
year: date.getFullYear(),
|
|
month: date.getMonth() + 1,
|
|
day: date.getDate()
|
|
} as NgbDateStruct;
|
|
}
|
|
|
|
}
|