73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
import ko = require('knockout');
|
|
import hasher = require('hasher');
|
|
import crossroads = require('crossroads');
|
|
import NProgress = require('nprogress');
|
|
import stairs = require('stairs');
|
|
|
|
|
|
export interface IPage
|
|
{
|
|
pattern: string;
|
|
component: string;
|
|
}
|
|
|
|
|
|
|
|
class IndexController
|
|
{
|
|
public Page = ko.observable<IPage>({ pattern: '', component: '' });
|
|
|
|
private progress: KnockoutComputed<void>;
|
|
|
|
|
|
constructor()
|
|
{
|
|
crossroads.normalizeFn = crossroads.NORM_AS_OBJECT;
|
|
|
|
this.addPage(':rest*:', 'mode', -Infinity);
|
|
this.addPage('settings', 'settings');
|
|
this.addPage('firmware', 'firmware');
|
|
|
|
hasher.initialized.add((hash: string) => crossroads.parse(hash));
|
|
hasher.changed.add((hash: string) => crossroads.parse(hash));
|
|
hasher.init();
|
|
|
|
NProgress.configure({
|
|
parent: '#progress'
|
|
});
|
|
|
|
var instance = stairs.Stairs.instance();
|
|
var initialProgress = true;
|
|
|
|
this.progress = ko.computed(() =>
|
|
{
|
|
if (instance.Saving())
|
|
NProgress.start()
|
|
else
|
|
{
|
|
// Only show the progress bar initially, not for later refreshes
|
|
if (initialProgress && instance.Loading())
|
|
NProgress.start();
|
|
else
|
|
{
|
|
NProgress.done();
|
|
initialProgress = false;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
private addPage(pattern: string, pageName: string, priority?: number): void
|
|
{
|
|
var page: IPage = { pattern: pattern, component: 'page-' + pageName };
|
|
ko.components.register(page.component, { require: 'components/' + page.component });
|
|
crossroads.addRoute(pattern, () =>
|
|
{
|
|
this.Page(page);
|
|
}, priority);
|
|
}
|
|
}
|
|
|
|
|
|
ko.applyBindings(new IndexController()); |