2016-03-14 20:20:29 +08:00
|
|
|
///<reference path="../browser.d.ts"/>
|
2016-03-13 01:11:19 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
import {Component, OnInit} from "@angular/core";
|
2016-03-12 21:57:22 +08:00
|
|
|
import {LoginComponent} from "./login/login.component";
|
2016-05-01 00:01:54 +08:00
|
|
|
import {AuthenticationService} from "./model/network/authentication.service.ts";
|
2016-05-09 23:04:56 +08:00
|
|
|
import {GalleryComponent} from "./gallery/gallery.component";
|
2016-03-13 18:28:29 +08:00
|
|
|
import {User} from "../../common/entities/User";
|
2016-05-09 23:04:56 +08:00
|
|
|
import {Router, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from "@angular/router-deprecated";
|
2016-05-04 23:20:21 +08:00
|
|
|
import {HTTP_PROVIDERS} from "@angular/http";
|
2016-05-01 00:01:54 +08:00
|
|
|
import {UserService} from "./model/network/user.service.ts";
|
2016-05-09 23:04:56 +08:00
|
|
|
import {GalleryService} from "./gallery/gallery.service";
|
2016-05-05 04:44:26 +08:00
|
|
|
import {AdminComponent} from "./admin/admin.component";
|
2016-05-09 23:04:56 +08:00
|
|
|
import {NetworkService} from "./model/network/network.service";
|
|
|
|
|
2016-03-12 21:57:22 +08:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'pi-gallery2-app',
|
|
|
|
template: `<router-outlet></router-outlet>`,
|
2016-05-04 23:20:21 +08:00
|
|
|
directives: [ROUTER_DIRECTIVES],
|
2016-03-12 21:57:22 +08:00
|
|
|
providers: [
|
2016-03-19 16:58:27 +08:00
|
|
|
HTTP_PROVIDERS,
|
2016-03-13 05:19:24 +08:00
|
|
|
ROUTER_PROVIDERS,
|
2016-05-05 04:44:26 +08:00
|
|
|
NetworkService,
|
2016-03-19 16:58:27 +08:00
|
|
|
UserService,
|
2016-03-20 23:54:30 +08:00
|
|
|
GalleryService,
|
2016-05-01 16:28:05 +08:00
|
|
|
AuthenticationService]
|
2016-03-12 21:57:22 +08:00
|
|
|
})
|
|
|
|
@RouteConfig([
|
2016-04-10 00:06:29 +08:00
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
redirectTo: ["Login"]
|
|
|
|
},
|
2016-03-12 21:57:22 +08:00
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
name: 'Login',
|
|
|
|
component: LoginComponent,
|
|
|
|
useAsDefault: true
|
2016-03-28 03:21:47 +08:00
|
|
|
},
|
2016-04-26 21:10:05 +08:00
|
|
|
{
|
|
|
|
path: '/admin',
|
|
|
|
name: 'Admin',
|
|
|
|
component: AdminComponent
|
|
|
|
},
|
2016-03-13 18:28:29 +08:00
|
|
|
{
|
2016-03-28 03:21:47 +08:00
|
|
|
path: '/gallery',
|
2016-05-09 23:04:56 +08:00
|
|
|
redirectTo: ["Gallery", {directory: ""}]
|
|
|
|
},
|
|
|
|
{
|
2016-04-10 00:06:29 +08:00
|
|
|
path: '/gallery/:directory',
|
2016-03-13 18:28:29 +08:00
|
|
|
name: 'Gallery',
|
|
|
|
component: GalleryComponent
|
2016-04-10 00:06:29 +08:00
|
|
|
},
|
2016-05-16 17:03:11 +08:00
|
|
|
{
|
|
|
|
path: '/search/:searchText',
|
|
|
|
name: 'Search',
|
|
|
|
component: GalleryComponent
|
|
|
|
},
|
2016-03-12 21:57:22 +08:00
|
|
|
])
|
2016-05-09 23:04:56 +08:00
|
|
|
export class AppComponent implements OnInit {
|
2016-03-13 18:28:29 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
constructor(private _router:Router, private _authenticationService:AuthenticationService) {
|
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() {
|
2016-04-10 00:06:29 +08:00
|
|
|
this._authenticationService.OnAuthenticated.on((user:User) => {
|
|
|
|
if (this._router.isRouteActive(this._router.generate(['Login']))) {
|
|
|
|
console.log("routing");
|
2016-05-09 23:04:56 +08:00
|
|
|
this._router.navigate(["Gallery", {directory: ""}]);
|
2016-04-10 00:06:29 +08:00
|
|
|
}
|
2016-03-13 18:28:29 +08:00
|
|
|
});
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2016-03-19 16:58:27 +08:00
|
|
|
|
2016-03-13 01:11:19 +08:00
|
|
|
}
|
2016-03-12 21:57:22 +08:00
|
|
|
}
|