Finished refactoring, guards, docs, tests

This commit is contained in:
lotte
2019-01-02 16:51:41 +01:00
parent e0ed960d4c
commit 1ebd6f0e86
41 changed files with 600 additions and 553 deletions

View File

@@ -0,0 +1,73 @@
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 '../../services/route.service';
import { Router } from '@angular/router';
import { RemoteData } from '../../../core/data/remote-data';
import { isNotEmpty, isNotUndefined } from '../../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';
import { NormalizedDSpaceObject } from '../../../core/cache/models/normalized-dspace-object.model';
/**
* Component representing the create page for communities and collections
*/
@Component({
selector: 'ds-create-comcol',
template: ''
})
export class CreateComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
/**
* Frontend endpoint where for this type of DSP
*/
protected frontendURL: string;
/**
* The provided UUID for the parent community
*/
public parentUUID$: Observable<string>;
/**
* The parent community of the object that is to be created
*/
public parentRD$: Observable<RemoteData<Community>>;
public constructor(
protected dsoDataService: DataService<TNormalized, TDomain>,
protected parentDataService: 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.parentDataService.findById(parentID);
}
});
}
/**
* @param {TDomain} dso The updated version of the DSO
* Creates a new DSO based on the submitted user data and navigates to the new object's home page
*/
onSubmit(dso: TDomain) {
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
this.dsoDataService.create(dso, uuid)
.pipe(getSucceededRemoteData())
.subscribe((dsoRD: RemoteData<TDomain>) => {
if (isNotUndefined(dsoRD)) {
const newUUID = dsoRD.payload.uuid;
this.router.navigate([this.frontendURL + newUUID]);
}
});
});
}
}