65240: Add community/collection logo on create/edit pages

This commit is contained in:
Kristof De Langhe
2019-10-01 14:42:25 +02:00
parent 2789996000
commit a2695edbac
18 changed files with 300 additions and 36 deletions

View File

@@ -5,11 +5,12 @@ import { Observable } from 'rxjs';
import { RouteService } from '../../../core/services/route.service';
import { Router } from '@angular/router';
import { RemoteData } from '../../../core/data/remote-data';
import { isNotEmpty, isNotUndefined } from '../../empty.util';
import { hasValue, 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 { ComColDataService } from '../../../core/data/comcol-data.service';
/**
* Component representing the create page for communities and collections
@@ -34,8 +35,13 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
*/
public parentRD$: Observable<RemoteData<Community>>;
/**
* The UUID of the newly created object
*/
private newUUID: string;
public constructor(
protected dsoDataService: DataService<TDomain>,
protected dsoDataService: ComColDataService<TDomain>,
protected parentDataService: CommunityDataService,
protected routeService: RouteService,
protected router: Router
@@ -53,20 +59,39 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
}
/**
* @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
* @param event The event returned by the community/collection form. Contains the new dso and logo uploader
*/
onSubmit(dso: TDomain) {
onSubmit(event) {
const dso = event.dso;
const uploader = event.uploader;
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]);
this.newUUID = dsoRD.payload.uuid;
if (uploader.queue.length > 0) {
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
uploader.options.url = href;
uploader.uploadAll();
});
} else {
this.navigateToNewPage();
}
}
});
});
}
/**
* Navigate to the page of the newly created object
*/
navigateToNewPage() {
if (hasValue(this.newUUID)) {
this.router.navigate([this.frontendURL + this.newUUID]);
}
}
}