refactoring continued

This commit is contained in:
lotte
2019-01-02 07:44:38 +01:00
parent a35dffbe95
commit e0ed960d4c
4 changed files with 73 additions and 54 deletions

View File

@@ -1,55 +1,26 @@
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 { Component } from '@angular/core';
import { CommunityDataService } from '../../core/data/community-data.service';
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 {Community} from '../../core/shared/community.model';
import {CommunityDataService} from '../../core/data/community-data.service';
import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component';
import { NormalizedCollection } from '../../core/cache/models/normalized-collection.model';
import { Collection } from '../../core/shared/collection.model';
import { CollectionDataService } from '../../core/data/collection-data.service';
@Component({
selector: 'ds-create-collection',
styleUrls: ['./create-collection-page.component.scss'],
templateUrl: './create-collection-page.component.html'
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<Collection, NormalizedCollection> {
protected frontendURL = 'collections';
public constructor(
private communityDataService: CommunityDataService,
private collectionDataService: CollectionDataService,
private routeService: RouteService,
private router: Router
protected communityDataService: CommunityDataService,
protected collectionDataService: CollectionDataService,
protected routeService: RouteService,
protected router: Router
) {
super(collectionDataService, 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(collection: Collection) {
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
this.collectionDataService.create(collection, uuid)
.pipe(getSucceededRemoteData())
.subscribe((collectionRD: RemoteData<Community>) => {
if (isNotUndefined(collectionRD)) {
const newUUID = collectionRD.payload.uuid;
this.router.navigate(['/collections/' + newUUID]);
}
});
});
}
}