mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge branch 'master' into Virtual-metadata-on-item-delete
This commit is contained in:
@@ -570,6 +570,8 @@
|
||||
|
||||
"error.validation.pattern": "This input is restricted by the current pattern: {{ pattern }}.",
|
||||
|
||||
"error.validation.filerequired": "The file upload is mandatory",
|
||||
|
||||
|
||||
|
||||
"footer.copyright": "copyright © 2002-{{ year }}",
|
||||
|
@@ -1325,7 +1325,7 @@ export const mockUploadConfigResponse = {
|
||||
},
|
||||
self: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/bitstream-metadata'
|
||||
},
|
||||
required: false,
|
||||
required: true,
|
||||
maxSize: 536870912,
|
||||
name: 'upload',
|
||||
type: 'submissionupload',
|
||||
@@ -1336,6 +1336,10 @@ export const mockUploadConfigResponse = {
|
||||
self: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/upload'
|
||||
};
|
||||
|
||||
// Clone the object and change one property
|
||||
export const mockUploadConfigResponseNotRequired = JSON.parse(JSON.stringify(mockUploadConfigResponse));
|
||||
mockUploadConfigResponseNotRequired.required = false;
|
||||
|
||||
export const mockAccessConditionOptions = [
|
||||
{
|
||||
name: 'openaccess',
|
||||
|
@@ -5,6 +5,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
import { createSuccessfulRemoteDataObject$, createTestComponent } from '../../../shared/testing/utils';
|
||||
import { SubmissionObjectState } from '../../objects/submission-objects.reducer';
|
||||
import { SubmissionService } from '../../submission.service';
|
||||
import { SubmissionServiceStub } from '../../../shared/testing/submission-service-stub';
|
||||
import { SectionsService } from '../sections.service';
|
||||
@@ -18,7 +19,7 @@ import {
|
||||
mockSubmissionId,
|
||||
mockSubmissionState,
|
||||
mockUploadConfigResponse,
|
||||
mockUploadFiles
|
||||
mockUploadConfigResponseNotRequired, mockUploadFiles,
|
||||
} from '../../../shared/mocks/mock-submission';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { CommonModule } from '@angular/common';
|
||||
@@ -31,7 +32,6 @@ import { cold, hot } from 'jasmine-marbles';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
import { ResourcePolicy } from '../../../core/shared/resource-policy.model';
|
||||
import { ResourcePolicyService } from '../../../core/data/resource-policy.service';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { ConfigData } from '../../../core/config/config-data';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { Group } from '../../../core/eperson/models/group.model';
|
||||
@@ -65,17 +65,7 @@ function getMockResourcePolicyService(): ResourcePolicyService {
|
||||
});
|
||||
}
|
||||
|
||||
const sectionObject: SectionDataObject = {
|
||||
config: 'https://dspace7.4science.it/or2018/api/config/submissionforms/upload',
|
||||
mandatory: true,
|
||||
data: {
|
||||
files: []
|
||||
},
|
||||
errors: [],
|
||||
header: 'submit.progressbar.describe.upload',
|
||||
id: 'upload',
|
||||
sectionType: SectionsType.Upload
|
||||
};
|
||||
let sectionObject: SectionDataObject;
|
||||
|
||||
describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
|
||||
@@ -90,10 +80,28 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
let uploadsConfigService: any;
|
||||
let bitstreamService: any;
|
||||
|
||||
const submissionId = mockSubmissionId;
|
||||
const collectionId = mockSubmissionCollectionId;
|
||||
const submissionState = Object.assign({}, mockSubmissionState[mockSubmissionId]);
|
||||
const mockCollection = Object.assign(new Collection(), {
|
||||
let submissionId: string;
|
||||
let collectionId: string;
|
||||
let submissionState: SubmissionObjectState;
|
||||
let mockCollection: Collection;
|
||||
let mockDefaultAccessCondition: ResourcePolicy;
|
||||
|
||||
beforeEach(async(() => {
|
||||
sectionObject = {
|
||||
config: 'https://dspace7.4science.it/or2018/api/config/submissionforms/upload',
|
||||
mandatory: true,
|
||||
data: {
|
||||
files: []
|
||||
},
|
||||
errors: [],
|
||||
header: 'submit.progressbar.describe.upload',
|
||||
id: 'upload',
|
||||
sectionType: SectionsType.Upload
|
||||
};
|
||||
submissionId = mockSubmissionId;
|
||||
collectionId = mockSubmissionCollectionId;
|
||||
submissionState = Object.assign({}, mockSubmissionState[mockSubmissionId]) as any;
|
||||
mockCollection = Object.assign(new Collection(), {
|
||||
name: 'Community 1-Collection 1',
|
||||
id: collectionId,
|
||||
metadata: [
|
||||
@@ -106,14 +114,14 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
defaultAccessConditions: collectionId + '/defaultAccessConditions'
|
||||
}
|
||||
});
|
||||
const mockDefaultAccessCondition = Object.assign(new ResourcePolicy(), {
|
||||
|
||||
mockDefaultAccessCondition = Object.assign(new ResourcePolicy(), {
|
||||
name: null,
|
||||
groupUUID: '11cc35e5-a11d-4b64-b5b9-0052a5d15509',
|
||||
id: 20,
|
||||
uuid: 'resource-policy-20'
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
@@ -215,6 +223,7 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
expect(comp.collectionName).toBe(mockCollection.name);
|
||||
expect(comp.availableAccessConditionOptions.length).toBe(4);
|
||||
expect(comp.availableAccessConditionOptions).toEqual(mockUploadConfigResponse.accessConditionOptions as any);
|
||||
expect(comp.required$.getValue()).toBe(true);
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(compAsAny.availableGroups.size).toBe(2);
|
||||
expect(compAsAny.availableGroups).toEqual(expectedGroupsMap);
|
||||
@@ -254,6 +263,7 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
expect(comp.collectionName).toBe(mockCollection.name);
|
||||
expect(comp.availableAccessConditionOptions.length).toBe(4);
|
||||
expect(comp.availableAccessConditionOptions).toEqual(mockUploadConfigResponse.accessConditionOptions as any);
|
||||
expect(comp.required$.getValue()).toBe(true);
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(compAsAny.availableGroups.size).toBe(2);
|
||||
expect(compAsAny.availableGroups).toEqual(expectedGroupsMap);
|
||||
@@ -263,17 +273,67 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
|
||||
});
|
||||
|
||||
it('should the properly section status', () => {
|
||||
bitstreamService.getUploadedFileList.and.returnValue(hot('-a-b', {
|
||||
it('should properly read the section status when required is true', () => {
|
||||
submissionServiceStub.getSubmissionObject.and.returnValue(observableOf(submissionState));
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
|
||||
resourcePolicyService.findByHref.and.returnValue(createSuccessfulRemoteDataObject$(mockDefaultAccessCondition));
|
||||
|
||||
uploadsConfigService.getConfigByHref.and.returnValue(observableOf(
|
||||
new ConfigData(new PageInfo(), mockUploadConfigResponse as any)
|
||||
));
|
||||
|
||||
groupService.findById.and.returnValues(
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup)),
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup))
|
||||
);
|
||||
|
||||
bitstreamService.getUploadedFileList.and.returnValue(cold('-a-b', {
|
||||
a: [],
|
||||
b: mockUploadFiles
|
||||
}));
|
||||
|
||||
comp.onSectionInit();
|
||||
|
||||
expect(comp.required$.getValue()).toBe(true);
|
||||
|
||||
expect(compAsAny.getSectionStatus()).toBeObservable(cold('-c-d', {
|
||||
c: false,
|
||||
d: true
|
||||
}));
|
||||
});
|
||||
|
||||
it('should properly read the section status when required is false', () => {
|
||||
submissionServiceStub.getSubmissionObject.and.returnValue(observableOf(submissionState));
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
|
||||
resourcePolicyService.findByHref.and.returnValue(createSuccessfulRemoteDataObject$(mockDefaultAccessCondition));
|
||||
|
||||
uploadsConfigService.getConfigByHref.and.returnValue(observableOf(
|
||||
new ConfigData(new PageInfo(), mockUploadConfigResponseNotRequired as any)
|
||||
));
|
||||
|
||||
groupService.findById.and.returnValues(
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup)),
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup))
|
||||
);
|
||||
|
||||
bitstreamService.getUploadedFileList.and.returnValue(cold('-a-b', {
|
||||
a: [],
|
||||
b: mockUploadFiles
|
||||
}));
|
||||
|
||||
comp.onSectionInit();
|
||||
|
||||
expect(comp.required$.getValue()).toBe(false);
|
||||
|
||||
expect(compAsAny.getSectionStatus()).toBeObservable(cold('-c-d', {
|
||||
c: true,
|
||||
d: true
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectorRef, Component, Inject } from '@angular/core';
|
||||
|
||||
import { combineLatest, Observable, Subscription } from 'rxjs';
|
||||
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription} from 'rxjs';
|
||||
import { distinctUntilChanged, filter, find, flatMap, map, reduce, take, tap } from 'rxjs/operators';
|
||||
|
||||
import { SectionModelComponent } from '../models/section.model';
|
||||
@@ -104,6 +104,12 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
|
||||
*/
|
||||
protected availableGroups: Map<string, Group[]>; // Groups for any policy
|
||||
|
||||
/**
|
||||
* Is the upload required
|
||||
* @type {boolean}
|
||||
*/
|
||||
public required$ = new BehaviorSubject<boolean>(true);
|
||||
|
||||
/**
|
||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||
* @type {Array}
|
||||
@@ -172,6 +178,7 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
|
||||
}),
|
||||
flatMap(() => config$),
|
||||
flatMap((config: SubmissionUploadsModel) => {
|
||||
this.required$.next(config.required);
|
||||
this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : [];
|
||||
|
||||
this.collectionPolicyType = this.availableAccessConditionOptions.length > 0
|
||||
@@ -221,7 +228,7 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
|
||||
}),
|
||||
|
||||
// retrieve submission's bitstreams from state
|
||||
combineLatest(this.configMetadataForm$,
|
||||
observableCombineLatest(this.configMetadataForm$,
|
||||
this.bitstreamService.getUploadedFileList(this.submissionId, this.sectionData.id)).pipe(
|
||||
filter(([configMetadataForm, fileList]: [SubmissionFormsModel, any[]]) => {
|
||||
return isNotEmpty(configMetadataForm) && isNotUndefined(fileList)
|
||||
@@ -273,8 +280,13 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
|
||||
* the section status
|
||||
*/
|
||||
protected getSectionStatus(): Observable<boolean> {
|
||||
return this.bitstreamService.getUploadedFileList(this.submissionId, this.sectionData.id).pipe(
|
||||
map((fileList: any[]) => (isNotUndefined(fileList) && fileList.length > 0)));
|
||||
// if not mandatory, always true
|
||||
// if mandatory, at least one file is required
|
||||
return observableCombineLatest(this.required$,
|
||||
this.bitstreamService.getUploadedFileList(this.submissionId, this.sectionData.id),
|
||||
(required,fileList: any[]) => {
|
||||
return (!required || (isNotUndefined(fileList) && fileList.length > 0));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user