@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
22import { Router } from '@angular/router' ;
33import { TranslateService } from '@ngx-translate/core' ;
44import { Observable } from 'rxjs' ;
5- import { mergeMap , take } from 'rxjs/operators' ;
5+ import { map , mergeMap , take , tap } from 'rxjs/operators' ;
66import { ComColDataService } from '../../../../core/data/comcol-data.service' ;
77import { CommunityDataService } from '../../../../core/data/community-data.service' ;
88import { RemoteData } from '../../../../core/data/remote-data' ;
@@ -16,6 +16,8 @@ import { RequestParam } from '../../../../core/cache/models/request-param.model'
1616import { RequestService } from '../../../../core/data/request.service' ;
1717import { Collection } from '../../../../core/shared/collection.model' ;
1818import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service' ;
19+ import { of } from 'rxjs/internal/observable/of' ;
20+ import { getHomePageRoute } from '../../../../app-routing-paths' ;
1921
2022/**
2123 * Component representing the create page for communities and collections
@@ -83,33 +85,46 @@ export class CreateComColPageComponent<TDomain extends Collection | Community> i
8385 this . parentUUID$ . pipe (
8486 take ( 1 ) ,
8587 mergeMap ( ( uuid : string ) => {
86- const params = uuid ? [ new RequestParam ( 'parent' , uuid ) ] : [ ] ;
87- return this . dsoDataService . create ( dso , ...params )
88- . pipe ( getFirstSucceededRemoteDataPayload ( )
89- ) ;
90- } ) )
91- . subscribe ( ( dsoRD : TDomain ) => {
88+ const params = uuid ? [ new RequestParam ( 'parent' , uuid ) ] : [ ] ;
89+ return this . dsoDataService . create ( dso , ...params )
90+ . pipe ( getFirstSucceededRemoteDataPayload ( )
91+ ) ;
92+ } ) ,
93+ mergeMap ( ( dsoRD : TDomain ) => {
9294 if ( isNotUndefined ( dsoRD ) ) {
9395 this . newUUID = dsoRD . uuid ;
9496 if ( uploader . queue . length > 0 ) {
95- this . dsoDataService . getLogoEndpoint ( this . newUUID ) . pipe ( take ( 1 ) ) . subscribe ( ( href : string ) => {
96- uploader . options . url = href ;
97- uploader . uploadAll ( ) ;
98- } ) ;
97+ return this . dsoDataService . getLogoEndpoint ( this . newUUID ) . pipe (
98+ take ( 1 ) ,
99+ tap ( ( href : string ) => {
100+ uploader . options . url = href ;
101+ uploader . onCompleteAll = ( ) => {
102+ this . navigateToNewPage ( ) ;
103+ this . notificationsService . success ( null , this . translate . get ( this . type . value + '.create.notifications.success' ) ) ;
104+ } ;
105+ uploader . uploadAll ( ) ;
106+ } ) ,
107+ map ( ( ) => false )
108+ ) ;
99109 } else {
100- this . navigateToNewPage ( ) ;
110+ this . dsoDataService . refreshCache ( dsoRD ) ;
111+ return of ( true ) ;
101112 }
102- this . dsoDataService . refreshCache ( dsoRD ) ;
103113 }
114+ } )
115+ ) . subscribe ( ( notify : boolean ) => {
116+ if ( notify ) {
117+ this . navigateToNewPage ( ) ;
104118 this . notificationsService . success ( null , this . translate . get ( this . type . value + '.create.notifications.success' ) ) ;
105- } ) ;
119+ }
120+ } ) ;
106121 }
107122
108123 /**
109124 * Navigate to home page
110125 */
111126 navigateToHome ( ) {
112- this . router . navigate ( [ '/home' ] ) ;
127+ this . router . navigate ( [ getHomePageRoute ( ) ] ) ;
113128 }
114129
115130 /**
0 commit comments