1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/app.component.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2016-03-14 20:20:29 +08:00
///<reference path="../browser.d.ts"/>
2016-03-13 01:11:19 +08:00
2016-03-12 21:57:22 +08:00
import { Component } from 'angular2/core';
2016-03-26 23:25:48 +08:00
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouterLink} from 'angular2/router';
2016-03-12 21:57:22 +08:00
import {LoginComponent} from "./login/login.component";
2016-03-13 18:28:29 +08:00
import {AuthenticationService} from "./model/authentication.service";
import {GalleryComponent} from "./gallery/gallery.component";
import {OnInit} from "angular2/core";
import {User} from "../../common/entities/User";
import {Router, Location} from "angular2/router";
import {HTTP_PROVIDERS} from "angular2/http";
import {UserService} from "./model/user.service";
2016-03-20 23:54:30 +08:00
import {GalleryService} from "./gallery/gallery.service";
2016-03-27 02:24:12 +08:00
import {GeneratedUrl} from "angular2/src/router/rules/route_paths/route_path";
2016-03-12 21:57:22 +08:00
@Component({
selector: 'pi-gallery2-app',
template: `<router-outlet></router-outlet>`,
2016-03-28 03:21:47 +08:00
directives: [ROUTER_DIRECTIVES, RouterLink],
2016-03-12 21:57:22 +08:00
providers: [
HTTP_PROVIDERS,
2016-03-13 05:19:24 +08:00
ROUTER_PROVIDERS,
UserService,
2016-03-20 23:54:30 +08:00
GalleryService,
AuthenticationService
2016-03-12 21:57:22 +08:00
]
})
@RouteConfig([
{
path: '/login',
name: 'Login',
component: LoginComponent,
useAsDefault: true
2016-03-28 03:21:47 +08:00
},
2016-03-13 18:28:29 +08:00
{
2016-03-28 03:21:47 +08:00
path: '/gallery',
name: 'GalleryBase',
component: GalleryComponent
},
{
regex: 'gallery/([\w]*)',
2016-03-13 18:28:29 +08:00
name: 'Gallery',
2016-03-27 02:24:12 +08:00
serializer: (params): GeneratedUrl => {
2016-03-28 03:21:47 +08:00
return new GeneratedUrl(`gallery/${params['directory']}`, {})
2016-03-27 02:24:12 +08:00
},
2016-03-13 18:28:29 +08:00
component: GalleryComponent
2016-03-12 21:57:22 +08:00
}
])
2016-03-13 18:28:29 +08:00
export class AppComponent implements OnInit{
constructor(private _router: Router, private _location:Location, private _authenticationService: AuthenticationService){
2016-03-28 03:21:47 +08:00
2016-03-13 18:28:29 +08:00
}
2016-03-13 01:11:19 +08:00
2016-03-13 18:28:29 +08:00
ngOnInit() {
this._authenticationService.OnAuthenticated.on((user:User) =>
{
2016-03-28 03:21:47 +08:00
// this._location.replaceState('/'); // clears browser history so they can't navigate with back button
this._router.navigate(["GalleryBase"]);
2016-03-13 18:28:29 +08:00
});
2016-03-13 01:11:19 +08:00
}
2016-03-12 21:57:22 +08:00
}