diff --git a/src/app/app.module.ts b/src/app/app.module.ts index c492a1f..bc7198f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -62,7 +62,7 @@ import { PadContainerComponent } from './components/pad/pad-container/pad-contai const appRoutes: Routes = [ { path: '', component: LandingComponent }, { path: 'home', component: HomeComponent }, - { path: 'pad/:id', component: PadComponent }, + { path: 'pad/:name', component: PadComponent }, { path: 'login', component: LoginComponent }, { path: '**', component: NotFoundComponent } ]; diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index 965a06a..f24e0e9 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -43,9 +43,11 @@ export class HomeComponent implements OnInit, OnDestroy { } launchPad() { - this.swellService.getObject(this.padid.value) + let name = this.padid.value; + this.swellService.getObject(name) .then( object => { - this.router.navigate(['/pad', object.id]); + this.swellService.setObjectName(object.id, name) + this.router.navigate(['/pad', name]); }) .catch( err => { this.launchError = true; diff --git a/src/app/components/pad/pad.component.html b/src/app/components/pad/pad.component.html index e769ae9..bbd8edf 100644 --- a/src/app/components/pad/pad.component.html +++ b/src/app/components/pad/pad.component.html @@ -2,7 +2,7 @@ -

Pad {{object?.id}}

+

Pad {{name}}

diff --git a/src/app/components/pad/pad.component.ts b/src/app/components/pad/pad.component.ts index f4fa22e..340185f 100644 --- a/src/app/components/pad/pad.component.ts +++ b/src/app/components/pad/pad.component.ts @@ -15,7 +15,7 @@ export class PadComponent implements OnInit, OnDestroy, AfterViewInit { private objectSubscription: Subscription; object: any; - + name: string; constructor( private route: ActivatedRoute, @@ -29,7 +29,8 @@ export class PadComponent implements OnInit, OnDestroy, AfterViewInit { }); this.route.paramMap.subscribe( params => { - this.padService.init(params.get('id')); + this.name = params.get('name'); + this.padService.init(this.name); }); } diff --git a/src/app/services/pad.service.ts b/src/app/services/pad.service.ts index 8b5a1a1..9de2eb2 100644 --- a/src/app/services/pad.service.ts +++ b/src/app/services/pad.service.ts @@ -42,25 +42,32 @@ export class PadService { * with this service. Hence, changes in session would happen * after destroying the view and cleaning the service. * - * @param objectId + * @param name */ - init(objectId) { - - if (this.editor.hasDocument()) { - this.editor.clean(); - } - - if (this.session) { - this.loadObject(objectId); - } else { - // we must wait for the swell session - this.swellService.session$.pipe(first( val => val != null)) - .subscribe(session => { - this.session = session; - this.loadObject(objectId); - }); - - } + init(name) { + // get the id from the name + this.swellService.getObjectNames(name) + .then( response => { + let names_json = JSON.parse(JSON.stringify(response)); + let objectId = names_json['waveId']['domain'].concat('/').concat(names_json['waveId']['id']); + + if (this.editor.hasDocument()) { + this.editor.clean(); + } + + if (this.session) { + this.loadObject(objectId); + } else { + // we must wait for the swell session + this.swellService.session$.pipe(first( val => val != null)) + .subscribe(session => { + this.session = session; + this.loadObject(objectId); + }); + + } + + }); } diff --git a/src/app/services/swell.service.ts b/src/app/services/swell.service.ts index 6dbc177..9aa990f 100644 --- a/src/app/services/swell.service.ts +++ b/src/app/services/swell.service.ts @@ -147,6 +147,19 @@ export class SwellService { }); } + setObjectName(objectId, name) { + this.api.setObjectName( + { + id: objectId, + name: name + }) + } + + getObjectNames(name) { + return this.api.getObjectNames({ name: name }) + .then( response => { return response } ); + } + /** * Propagate session info