diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 46d7617f6c..1f85b8ddac 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -14,20 +14,23 @@ } } }, - "edit": { - "name": "Name", - "description": "Short Description", - "introductory": "Introductory text (HTML)", - "copyright": "Copyright text (HTML)", - "news": "News (HTML)", + "form": { + "title": "Name", + "description": "Introductory text (HTML)", + "abstract": "Short Description", + "rights": "Copyright text (HTML)", + "tableofcontents": "News (HTML)", "license": "License", "provenance": "Provenance", - "submit": "Submit", - "cancel": "Cancel", - "required": { - "name": "Please enter a collection name" + "errors": { + "title": { + "required": "Please enter a collection name" + } } }, + "edit": { + "head": "Edit Collection" + }, "create": { "head": "Create a Collection", "sub-head": "Create a Collection for Community {{ parent }}" @@ -57,7 +60,7 @@ } }, "edit": { - "head": "Edit collection" + "head": "Edit Community" }, "create": { "head": "Create a Community", diff --git a/src/app/+collection-page/collection-form/collection-form.component.html b/src/app/+collection-page/collection-form/collection-form.component.html deleted file mode 100644 index 85135af15d..0000000000 --- a/src/app/+collection-page/collection-form/collection-form.component.html +++ /dev/null @@ -1,35 +0,0 @@ -
-
- - -
{{ 'collection.edit.required.name' | translate }}
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
diff --git a/src/app/+collection-page/collection-form/collection-form.component.scss b/src/app/+collection-page/collection-form/collection-form.component.scss deleted file mode 100644 index d5811186e7..0000000000 --- a/src/app/+collection-page/collection-form/collection-form.component.scss +++ /dev/null @@ -1,7 +0,0 @@ -@import '../../../styles/variables.scss'; - -// temporary fix for bootstrap 4 beta btn color issue -.btn-secondary { - background-color: $input-bg; - color: $input-color; -} diff --git a/src/app/+collection-page/collection-form/collection-form.component.ts b/src/app/+collection-page/collection-form/collection-form.component.ts index 4238eb3811..03bd9bfda9 100644 --- a/src/app/+collection-page/collection-form/collection-form.component.ts +++ b/src/app/+collection-page/collection-form/collection-form.component.ts @@ -1,41 +1,56 @@ -import { Component, EventEmitter, Output } from '@angular/core'; -import { isNotEmpty } from '../../shared/empty.util'; -import { Location } from '@angular/common'; +import { Component, Input } from '@angular/core'; +import { + DynamicInputModel, + DynamicTextAreaModel +} from '@ng-dynamic-forms/core'; +import { DynamicFormControlModel } from '@ng-dynamic-forms/core/src/model/dynamic-form-control.model'; +import { ResourceType } from '../../core/shared/resource-type'; +import { Collection } from '../../core/shared/collection.model'; +import { ComColFormComponent } from '../../comcol-forms/comcol-form/comcol-form.component'; @Component({ selector: 'ds-collection-form', - styleUrls: ['./collection-form.component.scss'], - templateUrl: './collection-form.component.html' + styleUrls: ['../../comcol-forms/comcol-form.component.scss'], + templateUrl: '../../comcol-forms/comcol-form/comcol-form.component.html' }) -export class CollectionFormComponent { - - name: string; - description: string; - introductory: string; - copyright: string; - news: string; - license: string; - provenance: string; - - nameRequiredError = false; - - @Output() submitted: EventEmitter = new EventEmitter(); - - public constructor(private location: Location) { - - } - - onSubmit(data: any) { - if (isNotEmpty(data.name)) { - this.submitted.emit(data); - this.nameRequiredError = false; - } else { - this.nameRequiredError = true; - } - } - - cancel() { - this.location.back(); - } - +export class CollectionFormComponent extends ComColFormComponent { + @Input() dso: Collection = new Collection(); + type = ResourceType.Collection; + formModel: DynamicFormControlModel[] = [ + new DynamicInputModel({ + id: 'title', + name: 'dc.title', + required: true, + validators: { + required: null + }, + errorMessages: { + required: 'Please enter a name for this title' + }, + }), + new DynamicTextAreaModel({ + id: 'description', + name: 'dc.description', + }), + new DynamicTextAreaModel({ + id: 'abstract', + name: 'dc.description.abstract', + }), + new DynamicTextAreaModel({ + id: 'rights', + name: 'dc.rights', + }), + new DynamicTextAreaModel({ + id: 'tableofcontents', + name: 'dc.description.tableofcontents', + }), + new DynamicTextAreaModel({ + id: 'license', + name: 'dc.rights.license', + }), + new DynamicTextAreaModel({ + id: 'provenance', + name: 'dc.description.provenance', + }), + ]; } diff --git a/src/app/+collection-page/create-collection-page/create-collection-page.component.html b/src/app/+collection-page/create-collection-page/create-collection-page.component.html index 1d1f8deb6c..aa9569b6b8 100644 --- a/src/app/+collection-page/create-collection-page/create-collection-page.component.html +++ b/src/app/+collection-page/create-collection-page/create-collection-page.component.html @@ -1,11 +1,11 @@
- - -

{{ 'collection.create.sub-head' | translate:{ parent: community.name } }}

+ + +

{{ 'collection.create.sub-head' | translate:{ parent: parent.name } }}

- +
diff --git a/src/app/+collection-page/create-collection-page/create-collection-page.component.ts b/src/app/+collection-page/create-collection-page/create-collection-page.component.ts index 1bb4c31596..6ece21c388 100644 --- a/src/app/+collection-page/create-collection-page/create-collection-page.component.ts +++ b/src/app/+collection-page/create-collection-page/create-collection-page.component.ts @@ -1,58 +1,54 @@ -import { Component } from '@angular/core'; -import { Community } from '../../core/shared/community.model'; -import { CommunityDataService } from '../../core/data/community-data.service'; -import { CollectionDataService } from '../../core/data/collection-data.service'; -import { Collection } from '../../core/shared/collection.model'; +import { Component, OnInit } from '@angular/core'; +import {Collection} from '../../core/shared/collection.model'; +import {CollectionDataService} from '../../core/data/collection-data.service'; +import { Observable } from 'rxjs'; import { RouteService } from '../../shared/services/route.service'; import { Router } from '@angular/router'; -import { Observable } from 'rxjs'; -import { take } from 'rxjs/operators'; import { RemoteData } from '../../core/data/remote-data'; -import { isNotEmpty } from '../../shared/empty.util'; -import { ResourceType } from '../../core/shared/resource-type'; +import { isNotEmpty, isNotUndefined } from '../../shared/empty.util'; +import { take } from 'rxjs/operators'; +import { getSucceededRemoteData } from '../../core/shared/operators'; +import {Community} from '../../core/shared/community.model'; +import {CommunityDataService} from '../../core/data/community-data.service'; @Component({ selector: 'ds-create-collection', styleUrls: ['./create-collection-page.component.scss'], templateUrl: './create-collection-page.component.html' }) -export class CreateCollectionPageComponent { +export class CreateCommunityPageComponent implements OnInit { public parentUUID$: Observable; - public communityRDObs: Observable>; + public parentRD$: Observable>; public constructor( - private collectionDataService: CollectionDataService, private communityDataService: CommunityDataService, + private collectionDataService: CollectionDataService, private routeService: RouteService, private router: Router ) { + + } + + ngOnInit(): void { this.parentUUID$ = this.routeService.getQueryParameterValue('parent'); - this.parentUUID$.subscribe((uuid: string) => { - if (isNotEmpty(uuid)) { - this.communityRDObs = this.communityDataService.findById(uuid); + this.parentUUID$.subscribe((parentID: string) => { + if (isNotEmpty(parentID)) { + this.parentRD$ = this.communityDataService.findById(parentID); } }); } - onSubmit(data: any) { + onSubmit(collection: Collection) { this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { - const collection = Object.assign(new Collection(), { - name: data.name, - metadata: [ - { key: 'dc.description', value: data.introductory }, - { key: 'dc.description.abstract', value: data.description }, - { key: 'dc.rights', value: data.copyright }, - { key: 'dc.rights.license', value: data.license } - // TODO: metadata for news and provenance - ], - type: ResourceType.Collection - }); - this.collectionDataService.create(collection, uuid).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.router.navigate(['collections', rd.payload.id]); - } - }); + this.collectionDataService.create(collection, uuid) + .pipe(getSucceededRemoteData()) + .subscribe((collectionRD: RemoteData) => { + if (isNotUndefined(collectionRD)) { + const newUUID = collectionRD.payload.uuid; + this.router.navigate(['/collections/' + newUUID]); + } + }); }); } diff --git a/src/app/+collection-page/edit-collection-page/edit-collection-page.component.html b/src/app/+collection-page/edit-collection-page/edit-collection-page.component.html new file mode 100644 index 0000000000..1dc6442307 --- /dev/null +++ b/src/app/+collection-page/edit-collection-page/edit-collection-page.component.html @@ -0,0 +1,8 @@ +
+
+
+ +
+
+ +
diff --git a/src/app/+collection-page/edit-collection-page/edit-community-page.component.scss b/src/app/+collection-page/edit-collection-page/edit-community-page.component.scss new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/src/app/+collection-page/edit-collection-page/edit-community-page.component.scss @@ -0,0 +1 @@ + diff --git a/src/app/+collection-page/edit-collection-page/edit-community-page.component.spec.ts b/src/app/+collection-page/edit-collection-page/edit-community-page.component.spec.ts new file mode 100644 index 0000000000..84edd47e1d --- /dev/null +++ b/src/app/+collection-page/edit-collection-page/edit-community-page.component.spec.ts @@ -0,0 +1,121 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { CommunityDataService } from '../../core/data/community-data.service'; +import { RouteService } from '../../shared/services/route.service'; +import { ActivatedRoute, Router } from '@angular/router'; +import { TranslateModule } from '@ngx-translate/core'; +import { of as observableOf } from 'rxjs'; +import { RemoteData } from '../../core/data/remote-data'; +import { Community } from '../../core/shared/community.model'; +import { SharedModule } from '../../shared/shared.module'; +import { CommonModule } from '@angular/common'; +import { RouterTestingModule } from '@angular/router/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { EditCommunityPageComponent } from './edit-community-page.component'; +import { ActivatedRouteStub } from '../../shared/testing/active-router-stub'; + +fdescribe('EditCommunityPageComponent', () => { + let comp: EditCommunityPageComponent; + let fixture: ComponentFixture; + let communityDataService: CommunityDataService; + let routeService: RouteService; + let router: Router; + + let community; + let newCommunity; + let communityDataServiceStub; + let routeServiceStub; + let routerStub; + let routeStub; + + function initializeVars() { + community = Object.assign(new Community(), { + uuid: 'a20da287-e174-466a-9926-f66b9300d347', + metadata: [{ + key: 'dc.title', + value: 'test community' + }] + }); + + newCommunity = Object.assign(new Community(), { + uuid: '1ff59938-a69a-4e62-b9a4-718569c55d48', + metadata: [{ + key: 'dc.title', + value: 'new community' + }] + }); + + communityDataServiceStub = { + findById: (uuid) => observableOf(new RemoteData(false, false, true, null, Object.assign(new Community(), { + uuid: uuid, + metadata: [{ + key: 'dc.title', + value: community.name + }] + }))), + update: (com, uuid?) => observableOf(new RemoteData(false, false, true, undefined, newCommunity)) + + }; + + routeServiceStub = { + getQueryParameterValue: (param) => observableOf(community.uuid) + }; + routerStub = { + navigate: (commands) => commands + }; + + routeStub = { + data: observableOf(community) + }; + + } + + beforeEach(async(() => { + initializeVars(); + TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule], + declarations: [EditCommunityPageComponent], + providers: [ + { provide: CommunityDataService, useValue: communityDataServiceStub }, + { provide: RouteService, useValue: routeServiceStub }, + { provide: Router, useValue: routerStub }, + { provide: ActivatedRoute, useValue: routeStub }, + ], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditCommunityPageComponent); + comp = fixture.componentInstance; + fixture.detectChanges(); + communityDataService = (comp as any).communityDataService; + routeService = (comp as any).routeService; + router = (comp as any).router; + }); + + describe('onSubmit', () => { + let data; + beforeEach(() => { + data = Object.assign(new Community(), { + metadata: [{ + key: 'dc.title', + value: 'test' + }] + }); + }); + it('should navigate when successful', () => { + spyOn(router, 'navigate'); + comp.onSubmit(data); + fixture.detectChanges(); + expect(router.navigate).toHaveBeenCalled(); + }); + + it('should not navigate on failure', () => { + spyOn(router, 'navigate'); + spyOn(communityDataService, 'update').and.returnValue(observableOf(new RemoteData(true, true, false, undefined, newCommunity))); + comp.onSubmit(data); + fixture.detectChanges(); + expect(router.navigate).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/src/app/+collection-page/edit-collection-page/edit-community-page.component.ts b/src/app/+collection-page/edit-collection-page/edit-community-page.component.ts new file mode 100644 index 0000000000..236aaff05a --- /dev/null +++ b/src/app/+collection-page/edit-collection-page/edit-community-page.component.ts @@ -0,0 +1,45 @@ +import { Component } from '@angular/core'; +import { Community } from '../../core/shared/community.model'; +import { CommunityDataService } from '../../core/data/community-data.service'; +import { Observable } from 'rxjs'; +import { RouteService } from '../../shared/services/route.service'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RemoteData } from '../../core/data/remote-data'; +import { isNotUndefined } from '../../shared/empty.util'; +import { first, map } from 'rxjs/operators'; +import { getSucceededRemoteData } from '../../core/shared/operators'; + +@Component({ + selector: 'ds-edit-community', + styleUrls: ['./edit-community-page.component.scss'], + templateUrl: './edit-collection-page.component.html' +}) +export class EditCommunityPageComponent { + + public parentUUID$: Observable; + public parentRD$: Observable>; + public communityRD$: Observable>; + + public constructor( + private communityDataService: CommunityDataService, + private routeService: RouteService, + private router: Router, + private route: ActivatedRoute + ) { + } + + ngOnInit(): void { + this.communityRD$ = this.route.data.pipe(first(), map((data) => data.community)); + } + + onSubmit(community: Community) { + this.communityDataService.update(community) + .pipe(getSucceededRemoteData()) + .subscribe((communityRD: RemoteData) => { + if (isNotUndefined(communityRD)) { + const newUUID = communityRD.payload.uuid; + this.router.navigate(['/communities/' + newUUID]); + } + }); + } +} diff --git a/src/app/+community-page/community-form/community-form.component.scss b/src/app/+community-page/community-form/community-form.component.scss deleted file mode 100644 index d5811186e7..0000000000 --- a/src/app/+community-page/community-form/community-form.component.scss +++ /dev/null @@ -1,7 +0,0 @@ -@import '../../../styles/variables.scss'; - -// temporary fix for bootstrap 4 beta btn color issue -.btn-secondary { - background-color: $input-bg; - color: $input-color; -} diff --git a/src/app/+community-page/community-form/community-form.component.ts b/src/app/+community-page/community-form/community-form.component.ts index c470cbbf91..8dbd2d6490 100644 --- a/src/app/+community-page/community-form/community-form.component.ts +++ b/src/app/+community-page/community-form/community-form.component.ts @@ -1,27 +1,21 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { Location } from '@angular/common'; +import { Component, Input, OnInit, Output } from '@angular/core'; import { - DynamicFormService, DynamicInputModel, DynamicTextAreaModel } from '@ng-dynamic-forms/core'; -import { FormGroup } from '@angular/forms'; import { DynamicFormControlModel } from '@ng-dynamic-forms/core/src/model/dynamic-form-control.model'; import { Community } from '../../core/shared/community.model'; import { ResourceType } from '../../core/shared/resource-type'; -import { isNotEmpty } from '../../shared/empty.util'; -import { TranslateService } from '@ngx-translate/core'; - -const LABEL_KEY_PREFIX = 'community.form.'; -const ERROR_KEY_PREFIX = 'community.form.errors.'; +import { ComColFormComponent } from '../../comcol-forms/comcol-form/comcol-form.component'; @Component({ selector: 'ds-community-form', - styleUrls: ['./community-form.component.scss'], - templateUrl: './community-form.component.html' + styleUrls: ['../../comcol-forms/comcol-form.component.scss'], + templateUrl: '../../comcol-forms/comcol-form/comcol-form.component.html' }) -export class CommunityFormComponent implements OnInit { - @Input() community: Community = new Community(); +export class CommunityFormComponent extends ComColFormComponent { + @Input() dso: Community = new Community(); + type = ResourceType.Community; formModel: DynamicFormControlModel[] = [ new DynamicInputModel({ id: 'title', @@ -51,57 +45,4 @@ export class CommunityFormComponent implements OnInit { name: 'dc.description.tableofcontents', }), ]; - - formGroup: FormGroup; - - @Output() submitForm: EventEmitter = new EventEmitter(); - - public constructor(private location: Location, - private formService: DynamicFormService, - private translate: TranslateService) { - } - - ngOnInit(): void { - this.formModel.forEach( - (fieldModel: DynamicInputModel) => { - fieldModel.value = this.community.findMetadata(fieldModel.name); - } - ); - this.formGroup = this.formService.createFormGroup(this.formModel); - this.updateFieldTranslations(); - this.translate.onLangChange - .subscribe(() => { - this.updateFieldTranslations(); - }); - } - - onSubmit() { - const metadata = this.formModel.map( - (fieldModel: DynamicInputModel) => { - return { key: fieldModel.name, value: fieldModel.value } - } - ); - const filteredOldMetadata = this.community.metadata.filter((filter) => !metadata.map((md) => md.key).includes(filter.key)); - const filteredNewMetadata = metadata.filter((md) => isNotEmpty(md.value)); - const newMetadata = [...filteredOldMetadata, ...filteredNewMetadata]; - const updatedCommunity = Object.assign({}, this.community, { - metadata: newMetadata, - type: ResourceType.Community - }); - this.submitForm.emit(updatedCommunity); - } - - private updateFieldTranslations() { - this.formModel.forEach( - (fieldModel: DynamicInputModel) => { - fieldModel.label = this.translate.instant(LABEL_KEY_PREFIX + fieldModel.id); - if (isNotEmpty(fieldModel.validators)) { - fieldModel.errorMessages = {}; - Object.keys(fieldModel.validators).forEach((key) => { - fieldModel.errorMessages[key] = this.translate.instant(ERROR_KEY_PREFIX + fieldModel.id + '.' + key); - }); - } - } - ); - } } diff --git a/src/app/+community-page/create-community-page/create-community-page.component.ts b/src/app/+community-page/create-community-page/create-community-page.component.ts index 8871d33547..98156f5a8a 100644 --- a/src/app/+community-page/create-community-page/create-community-page.component.ts +++ b/src/app/+community-page/create-community-page/create-community-page.component.ts @@ -1,54 +1,21 @@ -import { Component, OnInit } from '@angular/core'; +import { Component } from '@angular/core'; import { Community } from '../../core/shared/community.model'; import { CommunityDataService } from '../../core/data/community-data.service'; -import { Observable } from 'rxjs'; import { RouteService } from '../../shared/services/route.service'; import { Router } from '@angular/router'; -import { RemoteData } from '../../core/data/remote-data'; -import { isNotEmpty, isNotUndefined } from '../../shared/empty.util'; -import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { map, take } from 'rxjs/operators'; -import { getSucceededRemoteData } from '../../core/shared/operators'; +import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component'; @Component({ selector: 'ds-create-community', styleUrls: ['./create-community-page.component.scss'], templateUrl: './create-community-page.component.html' }) -export class CreateCommunityPageComponent implements OnInit { - - public parentUUID$: Observable; - public parentRD$: Observable>; - +export class CreateCommunityPageComponent extends CreateComColPageComponent { public constructor( - private communityDataService: CommunityDataService, - private routeService: RouteService, - private router: Router + protected communityDataService: CommunityDataService, + protected routeService: RouteService, + protected router: Router ) { - + super(communityDataService, communityDataService, routeService, router); } - - ngOnInit(): void { - this.parentUUID$ = this.routeService.getQueryParameterValue('parent'); - this.parentUUID$.subscribe((parentID: string) => { - if (isNotEmpty(parentID)) { - this.parentRD$ = this.communityDataService.findById(parentID); - } - }); - } - - onSubmit(community: Community) { - this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { - this.communityDataService.create(community, uuid) - .pipe(getSucceededRemoteData()) - .subscribe((communityRD: RemoteData) => { - if (isNotUndefined(communityRD)) { - const newUUID = communityRD.payload.uuid; - this.router.navigate(['/communities/' + newUUID]); - } - }); - }); - } - - } diff --git a/src/app/+community-page/community-form/community-form.component.html b/src/app/comcol-forms/comcol-form/comcol-form.component.html similarity index 66% rename from src/app/+community-page/community-form/community-form.component.html rename to src/app/comcol-forms/comcol-form/comcol-form.component.html index c47f077022..720ad0c1cf 100644 --- a/src/app/+community-page/community-form/community-form.component.html +++ b/src/app/comcol-forms/comcol-form/comcol-form.component.html @@ -1,3 +1,3 @@ \ No newline at end of file + [formId]="'comcol-form-id'" + [formModel]="formModel" (submitForm)="onSubmit()"> diff --git a/src/app/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/comcol-forms/comcol-form/comcol-form.component.ts new file mode 100644 index 0000000000..d49e197f5d --- /dev/null +++ b/src/app/comcol-forms/comcol-form/comcol-form.component.ts @@ -0,0 +1,77 @@ +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { Location } from '@angular/common'; +import { + DynamicFormService, + DynamicInputModel +} from '@ng-dynamic-forms/core'; +import { FormGroup } from '@angular/forms'; +import { DynamicFormControlModel } from '@ng-dynamic-forms/core/src/model/dynamic-form-control.model'; +import { TranslateService } from '@ngx-translate/core'; +import { DSpaceObject } from '../../core/shared/dspace-object.model'; +import { isNotEmpty } from '../../shared/empty.util'; +import { ResourceType } from '../../core/shared/resource-type'; + +@Component({ + selector: 'ds-comcol-form', + // styleUrls: ['./comcol-form.component.scss'], + templateUrl: './comcol-form.component.html' +}) +export class ComColFormComponent implements OnInit { + @Input() dso: T; + type; + LABEL_KEY_PREFIX = this.type + '.form.'; + ERROR_KEY_PREFIX = this.type + '.form.errors.'; + formModel: DynamicFormControlModel[]; + formGroup: FormGroup; + + @Output() submitForm: EventEmitter = new EventEmitter(); + + public constructor(private location: Location, + private formService: DynamicFormService, + private translate: TranslateService) { + } + + ngOnInit(): void { + this.formModel.forEach( + (fieldModel: DynamicInputModel) => { + fieldModel.value = this.dso.findMetadata(fieldModel.name); + } + ); + this.formGroup = this.formService.createFormGroup(this.formModel); + this.updateFieldTranslations(); + this.translate.onLangChange + .subscribe(() => { + this.updateFieldTranslations(); + }); + } + + onSubmit() { + const metadata = this.formModel.map( + (fieldModel: DynamicInputModel) => { + return { key: fieldModel.name, value: fieldModel.value } + } + ); + const filteredOldMetadata = this.dso.metadata.filter((filter) => !metadata.map((md) => md.key).includes(filter.key)); + const filteredNewMetadata = metadata.filter((md) => isNotEmpty(md.value)); + const newMetadata = [...filteredOldMetadata, ...filteredNewMetadata]; + const updatedDSO = Object.assign({}, this.dso, { + metadata: newMetadata, + type: ResourceType.Community + }); + this.submitForm.emit(updatedDSO); + } + + private updateFieldTranslations() { + this.formModel.forEach( + (fieldModel: DynamicInputModel) => { + fieldModel.label = this.translate.instant(this.LABEL_KEY_PREFIX + fieldModel.id); + if (isNotEmpty(fieldModel.validators)) { + fieldModel.errorMessages = {}; + Object.keys(fieldModel.validators).forEach((key) => { + fieldModel.errorMessages[key] = this.translate.instant(this.ERROR_KEY_PREFIX + fieldModel.id + '.' + key); + }); + } + } + ); + } +} diff --git a/src/app/comcol-forms/create-comcol-page/create-comcol-page.component.ts b/src/app/comcol-forms/create-comcol-page/create-comcol-page.component.ts new file mode 100644 index 0000000000..e36f45ad18 --- /dev/null +++ b/src/app/comcol-forms/create-comcol-page/create-comcol-page.component.ts @@ -0,0 +1,55 @@ +import { Component, OnInit } from '@angular/core'; +import { Community } from '../../core/shared/community.model'; +import { CommunityDataService } from '../../core/data/community-data.service'; +import { Observable } from 'rxjs'; +import { RouteService } from '../../shared/services/route.service'; +import { Router } from '@angular/router'; +import { RemoteData } from '../../core/data/remote-data'; +import { isNotEmpty, isNotUndefined } from '../../shared/empty.util'; +import { take } from 'rxjs/operators'; +import { getSucceededRemoteData } from '../../core/shared/operators'; +import { DSpaceObject } from '../../core/shared/dspace-object.model'; +import { DataService } from '../../core/data/data.service'; + +@Component({ + selector: 'ds-create-community', + styleUrls: ['./create-community-page.component.scss'], + templateUrl: './create-community-page.component.html' +}) +export class CreateComColPageComponent implements OnInit { + protected frontendURL: string; + public parentUUID$: Observable; + public parentRD$: Observable>; + + public constructor( + protected dsoDataService: DataService, + protected parentoDataService: CommunityDataService, + protected routeService: RouteService, + protected router: Router + ) { + + } + + ngOnInit(): void { + this.parentUUID$ = this.routeService.getQueryParameterValue('parent'); + this.parentUUID$.subscribe((parentID: string) => { + if (isNotEmpty(parentID)) { + this.parentRD$ = this.parentoDataService.findById(parentID); + } + }); + } + + onSubmit(dso: T) { + this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { + this.dsoDataService.create(dso, uuid) + .pipe(getSucceededRemoteData()) + .subscribe((dsoRD: RemoteData) => { + if (isNotUndefined(dsoRD)) { + const newUUID = dsoRD.payload.uuid; + this.router.navigate([frontendURL + newUUID]); + } + }); + }); + } + +}