mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 06:53:03 +00:00
Merge pull request #2631 from vNovski/CST-12044-visualize-the-primary-bitstream
CST-12044 visualize the primary bitstream & CST-12043 primary bitstream flag
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<ds-form *ngIf="formModel"
|
||||
#formRef="formComponent"
|
||||
[formId]="formId"
|
||||
|
@@ -47,6 +47,7 @@ import {
|
||||
} from '../../../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { dateToISOFormat } from '../../../../../shared/date.util';
|
||||
import { of } from 'rxjs';
|
||||
import { DynamicCustomSwitchModel } from '../../../../../shared/form/builder/ds-dynamic-form-ui/models/custom-switch/custom-switch.model';
|
||||
|
||||
const jsonPatchOpBuilder: any = jasmine.createSpyObj('jsonPatchOpBuilder', {
|
||||
add: jasmine.createSpy('add'),
|
||||
@@ -78,7 +79,7 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
const fileIndex = '0';
|
||||
const fileId = '123456-test-upload';
|
||||
const fileData: any = mockUploadFiles[0];
|
||||
const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex);
|
||||
const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId);
|
||||
|
||||
let noAccessConditionsMock = Object.assign({}, mockFileFormData);
|
||||
delete noAccessConditionsMock.accessConditions;
|
||||
@@ -186,11 +187,15 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
|
||||
comp.ngOnInit();
|
||||
|
||||
const models = [DynamicCustomSwitchModel, DynamicFormGroupModel, DynamicFormArrayModel];
|
||||
|
||||
expect(comp.formModel).toBeDefined();
|
||||
expect(comp.formModel.length).toBe(2);
|
||||
expect(comp.formModel[0] instanceof DynamicFormGroupModel).toBeTruthy();
|
||||
expect(comp.formModel[1] instanceof DynamicFormArrayModel).toBeTruthy();
|
||||
expect((comp.formModel[1] as DynamicFormArrayModel).groups.length).toBe(2);
|
||||
expect(comp.formModel.length).toBe(models.length);
|
||||
models.forEach((model, i) => {
|
||||
expect(comp.formModel[i] instanceof model).toBeTruthy();
|
||||
});
|
||||
|
||||
expect((comp.formModel[2] as DynamicFormArrayModel).groups.length).toBe(2);
|
||||
const startDateModel = formbuilderService.findById('startDate', comp.formModel);
|
||||
expect(startDateModel.max).toEqual(maxStartDate);
|
||||
const endDateModel = formbuilderService.findById('endDate', comp.formModel);
|
||||
@@ -254,6 +259,7 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
compAsAny.formRef = {formGroup: null};
|
||||
compAsAny.fileData = fileData;
|
||||
compAsAny.pathCombiner = pathCombiner;
|
||||
compAsAny.isPrimary = null;
|
||||
formService.validateAllFormFields.and.callFake(() => null);
|
||||
formService.isValid.and.returnValue(of(true));
|
||||
formService.getFormData.and.returnValue(of(mockFileFormData));
|
||||
@@ -262,6 +268,7 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
Object.assign(mockSubmissionObject, {
|
||||
sections: {
|
||||
upload: {
|
||||
primary: true,
|
||||
files: mockUploadFiles
|
||||
}
|
||||
}
|
||||
@@ -277,23 +284,28 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
comp.saveBitstreamData();
|
||||
tick();
|
||||
|
||||
let path = 'metadata/dc.title';
|
||||
let path = 'primary';
|
||||
expect(uploadService.updatePrimaryBitstreamOperation).toHaveBeenCalledWith(pathCombiner.getPath(path), compAsAny.isPrimary, mockFileFormData.primary[0], compAsAny.fileId);
|
||||
|
||||
const pathFragment = ['files', fileIndex];
|
||||
|
||||
path = 'metadata/dc.title';
|
||||
expect(operationsBuilder.add).toHaveBeenCalledWith(
|
||||
pathCombiner.getPath(path),
|
||||
pathCombiner.getPath([...pathFragment, path]),
|
||||
mockFileFormData.metadata['dc.title'],
|
||||
true
|
||||
);
|
||||
|
||||
path = 'metadata/dc.description';
|
||||
expect(operationsBuilder.add).toHaveBeenCalledWith(
|
||||
pathCombiner.getPath(path),
|
||||
pathCombiner.getPath([...pathFragment, path]),
|
||||
mockFileFormData.metadata['dc.description'],
|
||||
true
|
||||
);
|
||||
|
||||
path = 'accessConditions';
|
||||
expect(operationsBuilder.add).toHaveBeenCalledWith(
|
||||
pathCombiner.getPath(path),
|
||||
pathCombiner.getPath([...pathFragment, path]),
|
||||
accessConditionsToSave,
|
||||
true
|
||||
);
|
||||
|
@@ -28,6 +28,8 @@ import {
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_LAYOUT,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_TYPE_CONFIG,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_TYPE_LAYOUT,
|
||||
BITSTREAM_FORM_PRIMARY,
|
||||
BITSTREAM_FORM_PRIMARY_LAYOUT,
|
||||
BITSTREAM_METADATA_FORM_GROUP_CONFIG,
|
||||
BITSTREAM_METADATA_FORM_GROUP_LAYOUT
|
||||
} from './section-upload-file-edit.model';
|
||||
@@ -42,10 +44,8 @@ import { FormComponent } from '../../../../../shared/form/form.component';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { filter, mergeMap, take } from 'rxjs/operators';
|
||||
import { dateToISOFormat } from '../../../../../shared/date.util';
|
||||
import { SubmissionObject } from '../../../../../core/submission/models/submission-object.model';
|
||||
import {
|
||||
WorkspaceitemSectionUploadObject
|
||||
} from '../../../../../core/submission/models/workspaceitem-section-upload.model';
|
||||
|
||||
|
||||
import { JsonPatchOperationsBuilder } from '../../../../../core/json-patch/builder/json-patch-operations-builder';
|
||||
import {
|
||||
SubmissionJsonPatchOperationsService
|
||||
@@ -57,6 +57,9 @@ import { SectionUploadService } from '../../section-upload.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { DynamicFormControlCondition } from '@ng-dynamic-forms/core/lib/model/misc/dynamic-form-control-relation.model';
|
||||
import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynamic-date-control.model';
|
||||
import { DynamicCustomSwitchModel } from 'src/app/shared/form/builder/ds-dynamic-form-ui/models/custom-switch/custom-switch.model';
|
||||
import { SubmissionObject } from 'src/app/core/submission/models/submission-object.model';
|
||||
import { WorkspaceitemSectionUploadObject } from 'src/app/core/submission/models/workspaceitem-section-upload.model';
|
||||
|
||||
/**
|
||||
* This component represents the edit form for bitstream
|
||||
@@ -74,6 +77,13 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
*/
|
||||
@ViewChild('formRef') public formRef: FormComponent;
|
||||
|
||||
/**
|
||||
* The indicator is the primary bitstream
|
||||
* it will be null if no primary bitstream is set for the ORIGINAL bundle
|
||||
* @type {boolean, null}
|
||||
*/
|
||||
isPrimary: boolean;
|
||||
|
||||
/**
|
||||
* The list of available access condition
|
||||
* @type {Array}
|
||||
@@ -191,6 +201,10 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
* The form model
|
||||
*/
|
||||
public initModelData(formModel: DynamicFormControlModel[]) {
|
||||
|
||||
const primaryBitstreamModel: any = this.formBuilderService.findById('primary', formModel, this.fileIndex);
|
||||
primaryBitstreamModel.value = this.isPrimary || false;
|
||||
|
||||
this.fileData.accessConditions.forEach((accessCondition, index) => {
|
||||
Array.of('name', 'startDate', 'endDate')
|
||||
.filter((key) => accessCondition.hasOwnProperty(key) && isNotEmpty(accessCondition[key]))
|
||||
@@ -291,6 +305,9 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
])
|
||||
});
|
||||
const formModel: DynamicFormControlModel[] = [];
|
||||
|
||||
formModel.push(new DynamicCustomSwitchModel(BITSTREAM_FORM_PRIMARY, BITSTREAM_FORM_PRIMARY_LAYOUT));
|
||||
|
||||
const metadataGroupModelConfig = Object.assign({}, BITSTREAM_METADATA_FORM_GROUP_CONFIG);
|
||||
metadataGroupModelConfig.group = this.formBuilderService.modelFromConfiguration(
|
||||
this.submissionId,
|
||||
@@ -386,10 +403,14 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
return formModel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save bitstream metadata
|
||||
*/
|
||||
saveBitstreamData() {
|
||||
|
||||
const pathFragment = ['files', this.fileIndex];
|
||||
|
||||
// validate form
|
||||
this.formService.validateAllFormFields(this.formRef.formGroup);
|
||||
const saveBitstreamDataSubscription = this.formService.isValid(this.formId).pipe(
|
||||
@@ -398,13 +419,15 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
mergeMap(() => this.formService.getFormData(this.formId)),
|
||||
take(1),
|
||||
mergeMap((formData: any) => {
|
||||
this.uploadService.updatePrimaryBitstreamOperation(this.pathCombiner.getPath('primary'), this.isPrimary, formData.primary[0], this.fileId);
|
||||
|
||||
// collect bitstream metadata
|
||||
Object.keys((formData.metadata))
|
||||
.filter((key) => isNotEmpty(formData.metadata[key]))
|
||||
.forEach((key) => {
|
||||
const metadataKey = key.replace(/_/g, '.');
|
||||
const path = `metadata/${metadataKey}`;
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath(path), formData.metadata[key], true);
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath([...pathFragment, path]), formData.metadata[key], true);
|
||||
});
|
||||
Object.keys((this.fileData.metadata))
|
||||
.filter((key) => isNotEmpty(this.fileData.metadata[key]))
|
||||
@@ -413,7 +436,7 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
.forEach((key) => {
|
||||
const metadataKey = key.replace(/_/g, '.');
|
||||
const path = `metadata/${metadataKey}`;
|
||||
this.operationsBuilder.remove(this.pathCombiner.getPath(path));
|
||||
this.operationsBuilder.remove(this.pathCombiner.getPath([...pathFragment, path]));
|
||||
});
|
||||
const accessConditionsToSave = [];
|
||||
if (formData.hasOwnProperty('accessConditions')) {
|
||||
@@ -469,25 +492,29 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
});
|
||||
}
|
||||
if (isNotEmpty(accessConditionsToSave)) {
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath([...pathFragment, 'accessConditions']), accessConditionsToSave, true);
|
||||
}
|
||||
|
||||
// dispatch a PATCH request to save metadata
|
||||
return this.operationsService.jsonPatchByResourceID(
|
||||
this.submissionService.getSubmissionObjectLinkName(),
|
||||
this.submissionId,
|
||||
this.pathCombiner.rootElement,
|
||||
this.pathCombiner.subRootElement);
|
||||
})
|
||||
// dispatch a PATCH request to save metadata
|
||||
return this.operationsService.jsonPatchByResourceID(
|
||||
this.submissionService.getSubmissionObjectLinkName(),
|
||||
this.submissionId,
|
||||
this.pathCombiner.rootElement,
|
||||
this.pathCombiner.subRootElement);
|
||||
})
|
||||
).subscribe((result: SubmissionObject[]) => {
|
||||
if (result[0].sections[this.sectionId]) {
|
||||
const uploadSection = (result[0].sections[this.sectionId] as WorkspaceitemSectionUploadObject);
|
||||
Object.keys(uploadSection.files)
|
||||
.filter((key) => uploadSection.files[key].uuid === this.fileId)
|
||||
.forEach((key) => this.uploadService.updateFileData(
|
||||
this.submissionId, this.sectionId, this.fileId, uploadSection.files[key])
|
||||
);
|
||||
const section = result[0].sections[this.sectionId];
|
||||
if (!section) {
|
||||
return;
|
||||
}
|
||||
const uploadSection = (section as WorkspaceitemSectionUploadObject);
|
||||
|
||||
this.uploadService.updateFilePrimaryBitstream(this.submissionId, this.sectionId, uploadSection.primary);
|
||||
|
||||
Object.keys(uploadSection.files)
|
||||
.filter((key) => uploadSection.files[key].uuid === this.fileId)
|
||||
.forEach((key) => this.uploadService.updateFileData(
|
||||
this.submissionId, this.sectionId, this.fileId, uploadSection.files[key])
|
||||
);
|
||||
this.isSaving = false;
|
||||
this.activeModal.close();
|
||||
});
|
||||
|
@@ -4,6 +4,7 @@ import {
|
||||
DynamicFormControlLayout,
|
||||
DynamicFormGroupModelConfig,
|
||||
DynamicSelectModelConfig,
|
||||
DynamicSwitchModelConfig,
|
||||
MATCH_ENABLED,
|
||||
OR_OPERATOR,
|
||||
} from '@ng-dynamic-forms/core';
|
||||
@@ -56,6 +57,19 @@ export const BITSTREAM_FORM_ACCESS_CONDITION_TYPE_LAYOUT: DynamicFormControlLayo
|
||||
label: 'col-form-label name-label'
|
||||
}
|
||||
};
|
||||
export const BITSTREAM_FORM_PRIMARY_LAYOUT: DynamicFormControlLayout = {
|
||||
element: {
|
||||
host: 'col-12',
|
||||
container: 'text-right'
|
||||
},
|
||||
};
|
||||
|
||||
export const BITSTREAM_FORM_PRIMARY: DynamicSwitchModelConfig = {
|
||||
id: 'primary',
|
||||
name: 'primary',
|
||||
label: 'bitstream.edit.form.primaryBitstream.label'
|
||||
};
|
||||
|
||||
|
||||
export const BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_CONFIG: DynamicDatePickerModelConfig = {
|
||||
id: 'startDate',
|
||||
|
Reference in New Issue
Block a user