mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #2810 from DSpace/backport-2647-to-dspace-7_x
[Port dspace-7_x] File edit component updated to work for forms without access conditions.
This commit is contained in:
@@ -80,6 +80,9 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
|||||||
const fileData: any = mockUploadFiles[0];
|
const fileData: any = mockUploadFiles[0];
|
||||||
const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex);
|
const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex);
|
||||||
|
|
||||||
|
let noAccessConditionsMock = Object.assign({}, mockFileFormData);
|
||||||
|
delete noAccessConditionsMock.accessConditions;
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -299,6 +302,28 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
|||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should update Bitstream data properly when access options are omitted', fakeAsync(() => {
|
||||||
|
compAsAny.formRef = {formGroup: null};
|
||||||
|
compAsAny.fileData = fileData;
|
||||||
|
compAsAny.pathCombiner = pathCombiner;
|
||||||
|
formService.validateAllFormFields.and.callFake(() => null);
|
||||||
|
formService.isValid.and.returnValue(of(true));
|
||||||
|
formService.getFormData.and.returnValue(of(noAccessConditionsMock));
|
||||||
|
const response = [
|
||||||
|
Object.assign(mockSubmissionObject, {
|
||||||
|
sections: {
|
||||||
|
upload: {
|
||||||
|
files: mockUploadFiles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
];
|
||||||
|
operationsService.jsonPatchByResourceID.and.returnValue(of(response));
|
||||||
|
comp.saveBitstreamData();
|
||||||
|
tick();
|
||||||
|
expect(uploadService.updateFileData).toHaveBeenCalled();
|
||||||
|
}));
|
||||||
|
|
||||||
it('should not save Bitstream File data properly when form is not valid', fakeAsync(() => {
|
it('should not save Bitstream File data properly when form is not valid', fakeAsync(() => {
|
||||||
compAsAny.formRef = {formGroup: null};
|
compAsAny.formRef = {formGroup: null};
|
||||||
compAsAny.pathCombiner = pathCombiner;
|
compAsAny.pathCombiner = pathCombiner;
|
||||||
|
@@ -416,56 +416,58 @@ export class SubmissionSectionUploadFileEditComponent
|
|||||||
this.operationsBuilder.remove(this.pathCombiner.getPath(path));
|
this.operationsBuilder.remove(this.pathCombiner.getPath(path));
|
||||||
});
|
});
|
||||||
const accessConditionsToSave = [];
|
const accessConditionsToSave = [];
|
||||||
formData.accessConditions
|
if (formData.hasOwnProperty('accessConditions')) {
|
||||||
.map((accessConditions) => accessConditions.accessConditionGroup)
|
formData.accessConditions
|
||||||
.filter((accessCondition) => isNotEmpty(accessCondition))
|
.filter((accessConditions) => isNotNull(accessConditions))
|
||||||
.forEach((accessCondition) => {
|
.map((accessConditions) => accessConditions.accessConditionGroup)
|
||||||
let accessConditionOpt;
|
.filter((accessCondition) => isNotEmpty(accessCondition))
|
||||||
|
.forEach((accessCondition) => {
|
||||||
|
let accessConditionOpt;
|
||||||
|
|
||||||
this.availableAccessConditionOptions
|
this.availableAccessConditionOptions
|
||||||
.filter((element) => isNotNull(accessCondition.name) && element.name === accessCondition.name[0].value)
|
.filter((element) => isNotNull(accessCondition.name) && element.name === accessCondition.name[0].value)
|
||||||
.forEach((element) => accessConditionOpt = element);
|
.forEach((element) => accessConditionOpt = element);
|
||||||
|
|
||||||
if (accessConditionOpt) {
|
if (accessConditionOpt) {
|
||||||
const currentAccessCondition = Object.assign({}, accessCondition);
|
const currentAccessCondition = Object.assign({}, accessCondition);
|
||||||
currentAccessCondition.name = this.retrieveValueFromField(accessCondition.name);
|
currentAccessCondition.name = this.retrieveValueFromField(accessCondition.name);
|
||||||
|
|
||||||
/* When start and end date fields are deactivated, their values may be still present in formData,
|
/* When start and end date fields are deactivated, their values may be still present in formData,
|
||||||
therefore it is necessary to delete them if they're not allowed by the current access condition option. */
|
therefore it is necessary to delete them if they're not allowed by the current access condition option. */
|
||||||
if (!accessConditionOpt.hasStartDate) {
|
if (!accessConditionOpt.hasStartDate) {
|
||||||
delete currentAccessCondition.startDate;
|
delete currentAccessCondition.startDate;
|
||||||
} else if (accessCondition.startDate) {
|
} else if (accessCondition.startDate) {
|
||||||
const startDate = this.retrieveValueFromField(accessCondition.startDate);
|
const startDate = this.retrieveValueFromField(accessCondition.startDate);
|
||||||
// Clamp the start date to the maximum, if any, since the
|
// Clamp the start date to the maximum, if any, since the
|
||||||
// datepicker sometimes exceeds it.
|
// datepicker sometimes exceeds it.
|
||||||
let startDateDate = new Date(startDate);
|
let startDateDate = new Date(startDate);
|
||||||
if (accessConditionOpt.maxStartDate) {
|
if (accessConditionOpt.maxStartDate) {
|
||||||
const maxStartDateDate = new Date(accessConditionOpt.maxStartDate);
|
const maxStartDateDate = new Date(accessConditionOpt.maxStartDate);
|
||||||
if (startDateDate > maxStartDateDate) {
|
if (startDateDate > maxStartDateDate) {
|
||||||
startDateDate = maxStartDateDate;
|
startDateDate = maxStartDateDate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
currentAccessCondition.startDate = dateToISOFormat(startDateDate);
|
||||||
}
|
}
|
||||||
currentAccessCondition.startDate = dateToISOFormat(startDateDate);
|
if (!accessConditionOpt.hasEndDate) {
|
||||||
}
|
delete currentAccessCondition.endDate;
|
||||||
if (!accessConditionOpt.hasEndDate) {
|
} else if (accessCondition.endDate) {
|
||||||
delete currentAccessCondition.endDate;
|
const endDate = this.retrieveValueFromField(accessCondition.endDate);
|
||||||
} else if (accessCondition.endDate) {
|
// Clamp the end date to the maximum, if any, since the
|
||||||
const endDate = this.retrieveValueFromField(accessCondition.endDate);
|
// datepicker sometimes exceeds it.
|
||||||
// Clamp the end date to the maximum, if any, since the
|
let endDateDate = new Date(endDate);
|
||||||
// datepicker sometimes exceeds it.
|
if (accessConditionOpt.maxEndDate) {
|
||||||
let endDateDate = new Date(endDate);
|
|
||||||
if (accessConditionOpt.maxEndDate) {
|
|
||||||
const maxEndDateDate = new Date(accessConditionOpt.maxEndDate);
|
const maxEndDateDate = new Date(accessConditionOpt.maxEndDate);
|
||||||
if (endDateDate > maxEndDateDate) {
|
if (endDateDate > maxEndDateDate) {
|
||||||
endDateDate = maxEndDateDate;
|
endDateDate = maxEndDateDate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
currentAccessCondition.endDate = dateToISOFormat(endDateDate);
|
||||||
}
|
}
|
||||||
currentAccessCondition.endDate = dateToISOFormat(endDateDate);
|
accessConditionsToSave.push(currentAccessCondition);
|
||||||
}
|
}
|
||||||
accessConditionsToSave.push(currentAccessCondition);
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (isNotEmpty(accessConditionsToSave)) {
|
if (isNotEmpty(accessConditionsToSave)) {
|
||||||
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user