2017-01-19 11:02:37 +00:00
|
|
|
import { RouteBuilder } from './route-builder.service';
|
|
|
|
|
|
|
|
|
2017-01-23 09:57:00 +00:00
|
|
|
export class RouteBuilderImpl implements RouteBuilder {
|
2017-01-19 11:02:37 +00:00
|
|
|
|
2017-01-23 09:57:00 +00:00
|
|
|
public currentProfile: string = 'layout';
|
|
|
|
public profiles: any[] = [
|
|
|
|
// Start with the old pages (if we asked for it).
|
|
|
|
{id: 'old-layout', templatePath: '/static/partials/'},
|
|
|
|
// Fallback back combined new/existing pages.
|
|
|
|
{id: 'layout', templatePath: '/static/partials/'}
|
|
|
|
];
|
2017-01-19 11:02:37 +00:00
|
|
|
|
|
|
|
|
2017-01-23 09:57:00 +00:00
|
|
|
constructor(private routeProvider: ng.route.IRouteProvider, private pages: any) {
|
2017-01-19 11:02:37 +00:00
|
|
|
for (let i = 0; i < this.profiles.length; ++i) {
|
2017-01-23 09:57:00 +00:00
|
|
|
if (this.profiles[i].id == this.currentProfile) {
|
2017-01-19 11:02:37 +00:00
|
|
|
this.profiles = this.profiles.slice(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public otherwise(options: any): void {
|
|
|
|
this.routeProvider.otherwise(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public route(path: string, pagename: string): RouteBuilder {
|
|
|
|
// Lookup the page, matching our lists of profiles.
|
|
|
|
var pair = this.pages.get(pagename, this.profiles);
|
|
|
|
if (!pair) {
|
|
|
|
throw Error('Unknown page: ' + pagename);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the route.
|
|
|
|
var foundProfile = pair[0];
|
|
|
|
var page = pair[1];
|
|
|
|
var templateUrl = foundProfile.templatePath + page.templateName;
|
|
|
|
|
2017-01-20 04:02:57 +00:00
|
|
|
var options = page.flags || {};
|
2017-01-19 11:02:37 +00:00
|
|
|
options['templateUrl'] = templateUrl;
|
|
|
|
options['reloadOnSearch'] = false;
|
|
|
|
options['controller'] = page.controller;
|
|
|
|
|
|
|
|
this.routeProvider.when(path, options);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|