Skip to content

Commit 8bdd2d2

Browse files
authored
Merge pull request DSpace#2135 from mwoodiupui/embargo-date
Don't allow the date picker to exceed the maximum start or end date for an access option
2 parents 38d7412 + 74a0820 commit 8bdd2d2

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/app/shared/mocks/submission.mock.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,11 +1668,7 @@ export const mockFileFormData = {
16681668
],
16691669
endDate: [
16701670
{
1671-
value: {
1672-
year: 2019,
1673-
month: 1,
1674-
day: 16
1675-
},
1671+
value: new Date('2019-01-16'),
16761672
language: null,
16771673
authority: null,
16781674
display: {
@@ -1694,19 +1690,15 @@ export const mockFileFormData = {
16941690
value: 'embargo',
16951691
language: null,
16961692
authority: null,
1697-
display: 'lease',
1693+
display: 'embargo',
16981694
confidence: -1,
16991695
place: 0,
17001696
otherInformation: null
17011697
}
17021698
],
17031699
startDate: [
17041700
{
1705-
value: {
1706-
year: 2019,
1707-
month: 1,
1708-
day: 16
1709-
},
1701+
value: new Date('2019-01-16'),
17101702
language: null,
17111703
authority: null,
17121704
display: {

src/app/submission/sections/upload/file/edit/section-upload-file-edit.component.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
1+
import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { UntypedFormControl } from '@angular/forms';
33

44
import {
@@ -66,7 +66,8 @@ import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynami
6666
styleUrls: ['./section-upload-file-edit.component.scss'],
6767
templateUrl: './section-upload-file-edit.component.html',
6868
})
69-
export class SubmissionSectionUploadFileEditComponent implements OnInit {
69+
export class SubmissionSectionUploadFileEditComponent
70+
implements OnInit, OnDestroy {
7071

7172
/**
7273
* The FormComponent reference
@@ -435,13 +436,31 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit {
435436
delete currentAccessCondition.startDate;
436437
} else if (accessCondition.startDate) {
437438
const startDate = this.retrieveValueFromField(accessCondition.startDate);
438-
currentAccessCondition.startDate = dateToISOFormat(startDate);
439+
// Clamp the start date to the maximum, if any, since the
440+
// datepicker sometimes exceeds it.
441+
let startDateDate = new Date(startDate);
442+
if (accessConditionOpt.maxStartDate) {
443+
const maxStartDateDate = new Date(accessConditionOpt.maxStartDate);
444+
if (startDateDate > maxStartDateDate) {
445+
startDateDate = maxStartDateDate;
446+
}
447+
}
448+
currentAccessCondition.startDate = dateToISOFormat(startDateDate);
439449
}
440450
if (!accessConditionOpt.hasEndDate) {
441451
delete currentAccessCondition.endDate;
442452
} else if (accessCondition.endDate) {
443453
const endDate = this.retrieveValueFromField(accessCondition.endDate);
444-
currentAccessCondition.endDate = dateToISOFormat(endDate);
454+
// Clamp the end date to the maximum, if any, since the
455+
// datepicker sometimes exceeds it.
456+
let endDateDate = new Date(endDate);
457+
if (accessConditionOpt.maxEndDate) {
458+
const maxEndDateDate = new Date(accessConditionOpt.maxEndDate);
459+
if (endDateDate > maxEndDateDate) {
460+
endDateDate = maxEndDateDate;
461+
}
462+
}
463+
currentAccessCondition.endDate = dateToISOFormat(endDateDate);
445464
}
446465
accessConditionsToSave.push(currentAccessCondition);
447466
}

0 commit comments

Comments
 (0)