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 b727731 commit 1e0859d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 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/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class HomeComponent implements OnInit, OnDestroy {
this.swellService.getObject(name)
.then( object => {
this.swellService.setObjectName(object.id, name)
this.router.navigate(['/pad', object.id]);
this.router.navigate(['/pad', name]);
})
.catch( err => {
this.launchError = true;
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
5 changes: 3 additions & 2 deletions src/app/components/pad/pad.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class PadComponent implements OnInit, OnDestroy, AfterViewInit {

private objectSubscription: Subscription;
object: any;

name: string;

constructor(
private route: ActivatedRoute,
Expand All @@ -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);
});
}

Expand Down
43 changes: 25 additions & 18 deletions src/app/services/pad.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

}

});

}

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 @@ -155,6 +155,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 1e0859d

Please sign in to comment.