[DURACOM-235] Refactored creation in order to navigate to created object page

This commit is contained in:
Giuseppe Digilio
2024-05-14 18:15:47 +02:00
parent b689b9f8a5
commit dbf9d29980
3 changed files with 32 additions and 19 deletions

View File

@@ -6,6 +6,5 @@
</div>
<ds-collection-form (submitForm)="onSubmit($event)"
[isCreation]="true"
(back)="navigateToHome()"
(finish)="navigateToNewPage()"></ds-collection-form>
(back)="navigateToHome()"></ds-collection-form>
</div>

View File

@@ -9,6 +9,5 @@
</div>
<ds-community-form (submitForm)="onSubmit($event)"
[isCreation]="true"
(back)="navigateToHome()"
(finish)="navigateToNewPage()"></ds-community-form>
(back)="navigateToHome()"></ds-community-form>
</div>

View File

@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { mergeMap, take } from 'rxjs/operators';
import { map, mergeMap, take, tap } from 'rxjs/operators';
import { ComColDataService } from '../../../../core/data/comcol-data.service';
import { CommunityDataService } from '../../../../core/data/community-data.service';
import { RemoteData } from '../../../../core/data/remote-data';
@@ -16,6 +16,8 @@ import { RequestParam } from '../../../../core/cache/models/request-param.model'
import { RequestService } from '../../../../core/data/request.service';
import { Collection } from '../../../../core/shared/collection.model';
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
import { of } from 'rxjs/internal/observable/of';
import { getHomePageRoute } from '../../../../app-routing-paths';
/**
* Component representing the create page for communities and collections
@@ -87,21 +89,34 @@ export class CreateComColPageComponent<TDomain extends Collection | Community> i
return this.dsoDataService.create(dso, ...params)
.pipe(getFirstSucceededRemoteDataPayload()
);
}))
.subscribe((dsoRD: TDomain) => {
}),
mergeMap((dsoRD: TDomain) => {
if (isNotUndefined(dsoRD)) {
this.newUUID = dsoRD.uuid;
if (uploader.queue.length > 0) {
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
return this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(
take(1),
tap((href: string) => {
uploader.options.url = href;
uploader.uploadAll();
});
} else {
uploader.onCompleteAll = () => {
this.navigateToNewPage();
}
this.dsoDataService.refreshCache(dsoRD);
}
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
};
uploader.uploadAll();
}),
map(() => false)
);
} else {
this.dsoDataService.refreshCache(dsoRD);
return of(true);
}
}
})
).subscribe((notify: boolean) => {
if (notify) {
this.navigateToNewPage();
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
}
});
}
@@ -109,7 +124,7 @@ export class CreateComColPageComponent<TDomain extends Collection | Community> i
* Navigate to home page
*/
navigateToHome() {
this.router.navigate(['/home']);
this.router.navigate([getHomePageRoute()]);
}
/**