refactoring comcol forms

This commit is contained in:
lotte
2018-12-23 00:07:24 +01:00
committed by Thuur Van de Velde
parent d37a2e051d
commit a35dffbe95
16 changed files with 420 additions and 240 deletions

View File

@@ -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<string>;
public parentRD$: Observable<RemoteData<Community>>;
export class CreateCommunityPageComponent extends CreateComColPageComponent<Community> {
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<Community>) => {
if (isNotUndefined(communityRD)) {
const newUUID = communityRD.payload.uuid;
this.router.navigate(['/communities/' + newUUID]);
}
});
});
}
}