Skip to content

Commit

Permalink
Align pad URL with pad title
Browse files Browse the repository at this point in the history
Rename the paramether in the route fron `id` to `name` to have
friendly urls. Use the name in the route to call `getObjectNames` which
allow us to get the id. The result need an ugly parsing to get the id,
due to the format of the response. See:
SwellRT#1 (comment)

Closes SwellRT#1.
  • Loading branch information
Ana06 committed Jul 13, 2018
1 parent c20f237 commit 353a8b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
];
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/pad/pad.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<button mat-icon-button (click)="sideDrawer.toggle()">
<mat-icon>menu</mat-icon>
</button>
<h1 class="example-app-name">Pad {{object?.id}}</h1>
<h1 class="example-app-name">Pad {{name}}</h1>
</mat-toolbar>


Expand Down
13 changes: 10 additions & 3 deletions src/app/components/pad/pad.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class PadComponent implements OnInit, OnDestroy {

objectId;

name: string;

constructor(
private route: ActivatedRoute,
private router: Router,
Expand All @@ -33,17 +35,22 @@ export class PadComponent implements OnInit, OnDestroy {
});

// we init the pad service with the object id param iff session is ready.
let id: string;
this.sessionSubscription = this.route.paramMap.pipe( switchMap( (params: ParamMap) => {

id = params.get('id');
this.name = params.get('name');
return this.swellService.session$;

})).subscribe( session => {

if (session) {
this.session = session;
this.padService.init(id);

this.swellService.getObjectNames(this.name)
.then( response => {
let names_json = JSON.parse(JSON.stringify(response));
let id = names_json['waveId']['domain'].concat('/').concat(names_json['waveId']['id']);
this.padService.init(id);
});
}

});
Expand Down
5 changes: 5 additions & 0 deletions src/app/services/swell.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ export class SwellService {
})
}

getObjectNames(name) {
return this.api.getObjectNames({ name: name })
.then( response => { return response } );
}


/**
* Propagate session info
Expand Down

0 comments on commit 353a8b1

Please sign in to comment.