diff --git a/package.json b/package.json index 7755f3d3d0..ae4b37d6fc 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "https": "1.0.0", "js-cookie": "2.2.0", "js.clone": "0.0.3", + "json-loader": "^0.5.7", "jsonschema": "1.2.2", "jwt-decode": "^2.2.0", "methods": "1.1.2", diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 5ff9a0336e..7e99d842b7 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -96,6 +96,7 @@ import { EndpointMockingRestService } from './dspace-rest-v2/endpoint-mocking-re import { ENV_CONFIG, GLOBAL_CONFIG, GlobalConfig } from '../../config'; export const restServiceFactory = (cfg: GlobalConfig, mocks: MockResponseMap, http: HttpClient) => { + console.log('REST SERVICE FACTORY'); if (ENV_CONFIG.production) { return new DSpaceRESTv2Service(http); } else { @@ -127,7 +128,6 @@ const PROVIDERS = [ DSOResponseParsingService, { provide: MOCK_RESPONSE_MAP, useValue: mockResponseMap }, { provide: DSpaceRESTv2Service, useFactory: restServiceFactory, deps: [GLOBAL_CONFIG, MOCK_RESPONSE_MAP, HttpClient]}, - DSpaceRESTv2Service, DynamicFormLayoutService, DynamicFormService, DynamicFormValidationService, diff --git a/src/app/core/dspace-rest-v2/endpoint-mocking-rest.service.ts b/src/app/core/dspace-rest-v2/endpoint-mocking-rest.service.ts index 91ce479f40..400a5fe7ba 100644 --- a/src/app/core/dspace-rest-v2/endpoint-mocking-rest.service.ts +++ b/src/app/core/dspace-rest-v2/endpoint-mocking-rest.service.ts @@ -39,6 +39,7 @@ export class EndpointMockingRestService extends DSpaceRESTv2Service { get(absoluteURL: string): Observable { const mockData = this.getMockData(absoluteURL); if (isEmpty(mockData)) { + console.log(absoluteURL); return super.get(absoluteURL); } else { return this.toMockResponse$(mockData); diff --git a/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts b/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts index 9a1bf4239b..3d4249ab5d 100644 --- a/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts +++ b/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts @@ -1,10 +1,10 @@ import { InjectionToken } from '@angular/core'; -import mockSuggestResponse from './mock-suggest-response.json'; +import mockSubmissionResponse from './mock-submission-response.json'; export class MockResponseMap extends Map {}; export const MOCK_RESPONSE_MAP: InjectionToken = new InjectionToken('mockResponseMap'); export const mockResponseMap: MockResponseMap = new Map([ - [ '/discover/suggestions', mockSuggestResponse ] + [ 'workspaceitems', mockSubmissionResponse ] ]); diff --git a/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json b/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json new file mode 100644 index 0000000000..0c20d30038 --- /dev/null +++ b/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json @@ -0,0 +1,377 @@ +{ + "id": 733, + "errors": [ + { + "message": "error.validation.required", + "paths": [ + "/sections/traditionalpageone/dc.title", + "/sections/traditionalpageone/dc.date.issued" + ] + } + ], + "lastModified": "2019-06-25T13:44:29.178+0000", + "sections": { + "license": { + "url": null, + "acceptanceDate": null, + "granted": false + }, + "upload": { + "files": [] + }, + "collection": "51715dd3-5590-49f2-b227-6a663c849921", + "traditionalpagetwo": {}, + "traditionalpageone": {} + }, + "type": "workspaceitem", + "_links": { + "collection": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/submission/workspaceitems/733/collection" + }, + "item": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/submission/workspaceitems/733/item" + }, + "submissionDefinition": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/submission/workspaceitems/733/submissionDefinition" + }, + "submitter": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/submission/workspaceitems/733/submitter" + }, + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/submission/workspaceitems/733" + } + }, + "_embedded": { + "submitter": { + "id": "335647b6-8a52-4ecb-a8c1-7ebabb199bda", + "uuid": "335647b6-8a52-4ecb-a8c1-7ebabb199bda", + "name": "dspacedemo+admin@gmail.com", + "handle": null, + "metadata": { + "eperson.firstname": [ + { + "value": "Demo", + "language": null, + "authority": null, + "confidence": -1, + "place": 0 + } + ], + "eperson.language": [ + { + "value": "en", + "language": null, + "authority": null, + "confidence": -1, + "place": 0 + } + ], + "eperson.lastname": [ + { + "value": "Site Administrator", + "language": null, + "authority": null, + "confidence": -1, + "place": 0 + } + ] + }, + "netid": null, + "lastActive": "2019-06-25T13:44:28.616+0000", + "canLogIn": true, + "email": "dspacedemo+admin@gmail.com", + "requireCertificate": false, + "selfRegistered": false, + "type": "eperson", + "_links": { + "groups": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/eperson/epersons/335647b6-8a52-4ecb-a8c1-7ebabb199bda/groups" + }, + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/eperson/epersons/335647b6-8a52-4ecb-a8c1-7ebabb199bda" + } + }, + "_embedded": { + "groups": null + } + }, + "item": { + "id": "0b692d3b-70b9-415f-a56d-e557f026accc", + "uuid": "0b692d3b-70b9-415f-a56d-e557f026accc", + "name": null, + "handle": null, + "metadata": {}, + "inArchive": false, + "discoverable": true, + "withdrawn": false, + "lastModified": "2019-06-25T13:44:29.160+0000", + "type": "item", + "_links": { + "bitstreams": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc/bitstreams" + }, + "owningCollection": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc/owningCollection" + }, + "relationships": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc/relationships" + }, + "templateItemOf": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc/templateItemOf" + }, + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc" + } + }, + "_embedded": { + "relationships": { + "_embedded": { + "relationships": [] + }, + "page": { + "number": 0, + "size": 0, + "totalPages": 1, + "totalElements": 0 + }, + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc/relationships" + } + } + }, + "owningCollection": null, + "templateItemOf": null, + "bitstreams": { + "_embedded": { + "bitstreams": [] + }, + "page": { + "number": 0, + "size": 0, + "totalPages": 1, + "totalElements": 0 + }, + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/items/0b692d3b-70b9-415f-a56d-e557f026accc/bitstreams" + } + } + } + } + }, + "submissionDefinition": { + "id": "traditional", + "name": "traditional", + "type": "submissiondefinition", + "isDefault": true, + "_links": { + "collections": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissiondefinitions/traditional/collections" + }, + "sections": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissiondefinitions/traditional/sections" + }, + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissiondefinitions/traditional" + } + }, + "_embedded": { + "collections": { + "_embedded": { + "collections": [] + }, + "page": { + "number": 0, + "size": 0, + "totalPages": 1, + "totalElements": 0 + }, + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissiondefinitions/traditional/collections" + } + } + }, + "sections": { + "_embedded": { + "sections": [ + { + "id": "collection", + "mandatory": true, + "sectionType": "collection", + "visibility": { + "main": "HIDDEN", + "other": "HIDDEN" + }, + "type": "submissionsection", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionsections/collection" + } + } + }, + { + "id": "relationships", + "header": "submit.progressbar.relationships", + "mandatory": true, + "sectionType": "relationships", + "type": "submissionsection", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionsections/relationships" + } + } + }, + { + "id": "traditionalpageone", + "header": "submit.progressbar.describe.stepone", + "mandatory": true, + "sectionType": "submission-form", + "type": "submissionsection", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionsections/traditionalpageone" + }, + "config": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionforms/traditionalpageone" + } + } + }, + { + "id": "traditionalpagetwo", + "header": "submit.progressbar.describe.steptwo", + "mandatory": true, + "sectionType": "submission-form", + "type": "submissionsection", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionsections/traditionalpagetwo" + }, + "config": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionforms/traditionalpagetwo" + } + } + }, + { + "id": "upload", + "header": "submit.progressbar.upload", + "mandatory": true, + "sectionType": "upload", + "type": "submissionsection", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionsections/upload" + }, + "config": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionuploads/upload" + } + } + }, + { + "id": "license", + "header": "submit.progressbar.license", + "mandatory": true, + "sectionType": "license", + "visibility": { + "main": null, + "other": "READONLY" + }, + "type": "submissionsection", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissionsections/license" + } + } + } + ] + }, + "page": { + "number": 0, + "size": 20, + "totalPages": 1, + "totalElements": 5 + }, + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/config/submissiondefinitions/traditional/sections" + } + } + } + } + }, + "collection": { + "id": "51715dd3-5590-49f2-b227-6a663c849921", + "uuid": "51715dd3-5590-49f2-b227-6a663c849921", + "name": "1-step Workflow collection", + "handle": "123456789/500", + "metadata": { + "dc.description": [ + { + "value": "Start a new submission.", + "language": null, + "authority": null, + "confidence": -1, + "place": 0 + } + ], + "dc.title": [ + { + "value": "1-step Workflow collection", + "language": null, + "authority": null, + "confidence": -1, + "place": 0 + } + ] + }, + "type": "collection", + "_links": { + "license": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/collections/51715dd3-5590-49f2-b227-6a663c849921/license" + }, + "defaultAccessConditions": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/collections/51715dd3-5590-49f2-b227-6a663c849921/defaultAccessConditions" + }, + "logo": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/collections/51715dd3-5590-49f2-b227-6a663c849921/logo" + }, + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/collections/51715dd3-5590-49f2-b227-6a663c849921" + } + }, + "_embedded": { + "logo": null, + "defaultAccessConditions": { + "_embedded": { + "defaultAccessConditions": [ + { + "id": 3649, + "name": null, + "groupUUID": "f2c7eb75-aec0-4604-ab7f-6676723818ad", + "action": "DEFAULT_BITSTREAM_READ", + "type": "resourcePolicy", + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/authz/resourcePolicies/3649" + } + } + } + ] + }, + "page": { + "number": 0, + "size": 20, + "totalPages": 1, + "totalElements": 1 + }, + "_links": { + "self": { + "href": "https://dspace7.4science.cloud/dspace-spring-rest/api/core/collections/51715dd3-5590-49f2-b227-6a663c849921/defaultAccessConditions" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/app/submission/sections/relationships/section-relationships.component.html b/src/app/submission/sections/relationships/section-relationships.component.html new file mode 100644 index 0000000000..f736fdc308 --- /dev/null +++ b/src/app/submission/sections/relationships/section-relationships.component.html @@ -0,0 +1,49 @@ +import { ChangeDetectorRef, Component, Inject } from '@angular/core'; + +import { Observable } from 'rxjs'; + +import { FormBuilderService } from '../../../shared/form/builder/form-builder.service'; +import { FormService } from '../../../shared/form/form.service'; +import { SectionModelComponent } from '../models/section.model'; +import { SectionDataObject } from '../models/section-data.model'; +import { renderSectionFor } from '../sections-decorator'; +import { SectionsType } from '../sections-type'; +import { SubmissionService } from '../../submission.service'; +import { SectionsService } from '../sections.service'; +import { CollectionDataService } from '../../../core/data/collection-data.service'; +import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; + +/** + * This component represents a section that contains a Form. + */ +@Component({ + selector: 'ds-submission-section-relationships', + styleUrls: ['./section-relationships.component.scss'], + templateUrl: './section-relationships.component.html', +}) +@renderSectionFor(SectionsType.Relationships) +export class SubmissionSectionRelationshipComponent extends SectionModelComponent { + constructor(protected changeDetectorRef: ChangeDetectorRef, + protected collectionDataService: CollectionDataService, + protected formBuilderService: FormBuilderService, + protected formService: FormService, + protected operationsBuilder: JsonPatchOperationsBuilder, + protected sectionService: SectionsService, + protected submissionService: SubmissionService, + @Inject('collectionIdProvider') public injectedCollectionId: string, + @Inject('sectionDataProvider') public injectedSectionData: SectionDataObject, + @Inject('submissionIdProvider') public injectedSubmissionId: string) { + super(injectedCollectionId, injectedSectionData, injectedSubmissionId); + } + + protected getSectionStatus(): Observable { + return undefined; + } + + protected onSectionDestroy(): void { + } + + protected onSectionInit(): void { + } + +} diff --git a/src/app/submission/sections/relationships/section-relationships.component.scss b/src/app/submission/sections/relationships/section-relationships.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/submission/sections/relationships/section-relationships.component.ts b/src/app/submission/sections/relationships/section-relationships.component.ts new file mode 100644 index 0000000000..f736fdc308 --- /dev/null +++ b/src/app/submission/sections/relationships/section-relationships.component.ts @@ -0,0 +1,49 @@ +import { ChangeDetectorRef, Component, Inject } from '@angular/core'; + +import { Observable } from 'rxjs'; + +import { FormBuilderService } from '../../../shared/form/builder/form-builder.service'; +import { FormService } from '../../../shared/form/form.service'; +import { SectionModelComponent } from '../models/section.model'; +import { SectionDataObject } from '../models/section-data.model'; +import { renderSectionFor } from '../sections-decorator'; +import { SectionsType } from '../sections-type'; +import { SubmissionService } from '../../submission.service'; +import { SectionsService } from '../sections.service'; +import { CollectionDataService } from '../../../core/data/collection-data.service'; +import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; + +/** + * This component represents a section that contains a Form. + */ +@Component({ + selector: 'ds-submission-section-relationships', + styleUrls: ['./section-relationships.component.scss'], + templateUrl: './section-relationships.component.html', +}) +@renderSectionFor(SectionsType.Relationships) +export class SubmissionSectionRelationshipComponent extends SectionModelComponent { + constructor(protected changeDetectorRef: ChangeDetectorRef, + protected collectionDataService: CollectionDataService, + protected formBuilderService: FormBuilderService, + protected formService: FormService, + protected operationsBuilder: JsonPatchOperationsBuilder, + protected sectionService: SectionsService, + protected submissionService: SubmissionService, + @Inject('collectionIdProvider') public injectedCollectionId: string, + @Inject('sectionDataProvider') public injectedSectionData: SectionDataObject, + @Inject('submissionIdProvider') public injectedSubmissionId: string) { + super(injectedCollectionId, injectedSectionData, injectedSubmissionId); + } + + protected getSectionStatus(): Observable { + return undefined; + } + + protected onSectionDestroy(): void { + } + + protected onSectionInit(): void { + } + +} diff --git a/src/app/submission/sections/sections-type.ts b/src/app/submission/sections/sections-type.ts index 02e0ba478b..34ecafe42b 100644 --- a/src/app/submission/sections/sections-type.ts +++ b/src/app/submission/sections/sections-type.ts @@ -1,4 +1,5 @@ export enum SectionsType { + Relationships = 'relationships', SubmissionForm = 'submission-form', Upload = 'upload', License = 'license', diff --git a/src/app/submission/submission.service.ts b/src/app/submission/submission.service.ts index 82185a8eae..9a71c18d09 100644 --- a/src/app/submission/submission.service.ts +++ b/src/app/submission/submission.service.ts @@ -60,6 +60,8 @@ export class SubmissionService { */ protected timer$: Observable; + private workspaceLinkPath = 'workspaceitems'; + private workflowLinkPath = 'workflowitems'; /** * Initialize service variables * @param {GlobalConfig} EnvConfig @@ -98,7 +100,7 @@ export class SubmissionService { * observable of SubmissionObject */ createSubmission(): Observable { - return this.restService.postToEndpoint('workspaceitems', {}).pipe( + return this.restService.postToEndpoint(this.workspaceLinkPath, {}).pipe( map((workspaceitem: SubmissionObject) => workspaceitem[0]), catchError(() => observableOf({}))) } @@ -116,7 +118,7 @@ export class SubmissionService { let headers = new HttpHeaders(); headers = headers.append('Content-Type', 'text/uri-list'); options.headers = headers; - return this.restService.postToEndpoint('workflowitems', selfUrl, null, options) as Observable; + return this.restService.postToEndpoint(this.workspaceLinkPath, selfUrl, null, options) as Observable; } /** @@ -306,9 +308,9 @@ export class SubmissionService { getSubmissionObjectLinkName(): string { const url = this.router.routerState.snapshot.url; if (url.startsWith('/workspaceitems') || url.startsWith('/submit')) { - return 'workspaceitems'; + return this.workspaceLinkPath; } else if (url.startsWith('/workflowitems')) { - return 'workflowitems'; + return this.workflowLinkPath; } else { return 'edititems'; } @@ -323,10 +325,10 @@ export class SubmissionService { getSubmissionScope(): SubmissionScopeType { let scope: SubmissionScopeType; switch (this.getSubmissionObjectLinkName()) { - case 'workspaceitems': + case this.workspaceLinkPath: scope = SubmissionScopeType.WorkspaceItem; break; - case 'workflowitems': + case this.workflowLinkPath: scope = SubmissionScopeType.WorkflowItem; break; } diff --git a/src/app/submission/submit/submission-submit.component.ts b/src/app/submission/submit/submission-submit.component.ts index dbfd2f5a40..448ccf97e2 100644 --- a/src/app/submission/submit/submission-submit.component.ts +++ b/src/app/submission/submit/submission-submit.component.ts @@ -56,7 +56,7 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit { * * @param {ChangeDetectorRef} changeDetectorRef * @param {NotificationsService} notificationsService - * @param {SubmissionService} submissioService + * @param {SubmissionService} submissionService * @param {Router} router * @param {TranslateService} translate * @param {ViewContainerRef} viewContainerRef @@ -64,7 +64,7 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit { constructor(private changeDetectorRef: ChangeDetectorRef, private notificationsService: NotificationsService, private router: Router, - private submissioService: SubmissionService, + private submissionService: SubmissionService, private translate: TranslateService, private viewContainerRef: ViewContainerRef) { } @@ -75,7 +75,7 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit { ngOnInit() { // NOTE execute the code on the browser side only, otherwise it is executed twice this.subs.push( - this.submissioService.createSubmission() + this.submissionService.createSubmission() .subscribe((submissionObject: SubmissionObject) => { // NOTE new submission is created on the browser side only if (isNotNull(submissionObject)) { diff --git a/yarn.lock b/yarn.lock index 9a4f96e805..f702cecf5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5582,6 +5582,11 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0= +json-loader@^0.5.7: + version "0.5.7" + resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d" + integrity sha512-QLPs8Dj7lnf3e3QYS1zkCo+4ZwqOiF9d/nZnYozTISxXWCfNs9yuky5rJw4/W34s7POaNlbZmQGaB5NiXCbP4w== + json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"