Skip to content

Commit dbf9d29

Browse files
committed
[DURACOM-235] Refactored creation in order to navigate to created object page
1 parent b689b9f commit dbf9d29

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

src/app/collection-page/create-collection-page/create-collection-page.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ <h2 id="sub-header" class="border-bottom pb-2">{{'collection.create.sub-head' |
66
</div>
77
<ds-collection-form (submitForm)="onSubmit($event)"
88
[isCreation]="true"
9-
(back)="navigateToHome()"
10-
(finish)="navigateToNewPage()"></ds-collection-form>
9+
(back)="navigateToHome()"></ds-collection-form>
1110
</div>

src/app/community-page/create-community-page/create-community-page.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ <h2 *ngIf="parent" id="sub-header" class="border-bottom pb-2">{{ 'community.crea
99
</div>
1010
<ds-community-form (submitForm)="onSubmit($event)"
1111
[isCreation]="true"
12-
(back)="navigateToHome()"
13-
(finish)="navigateToNewPage()"></ds-community-form>
12+
(back)="navigateToHome()"></ds-community-form>
1413
</div>

src/app/shared/comcol/comcol-forms/create-comcol-page/create-comcol-page.component.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { TranslateService } from '@ngx-translate/core';
44
import { Observable } from 'rxjs';
5-
import { mergeMap, take } from 'rxjs/operators';
5+
import { map, mergeMap, take, tap } from 'rxjs/operators';
66
import { ComColDataService } from '../../../../core/data/comcol-data.service';
77
import { CommunityDataService } from '../../../../core/data/community-data.service';
88
import { RemoteData } from '../../../../core/data/remote-data';
@@ -16,6 +16,8 @@ import { RequestParam } from '../../../../core/cache/models/request-param.model'
1616
import { RequestService } from '../../../../core/data/request.service';
1717
import { Collection } from '../../../../core/shared/collection.model';
1818
import { 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

Comments
 (0)