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

60 lines
2.1 KiB
TypeScript
Raw Normal View History

2016-03-14 20:20:29 +08:00
///<reference path="../../browser.d.ts"/>
2016-03-13 18:28:29 +08:00
import {Component, OnInit} from 'angular2/core';
import {AuthenticationService} from "../model/authentication.service";
2016-03-20 23:54:30 +08:00
import {Router, Location, RouteParams} from "angular2/router";
import {GalleryService} from "./gallery.service";
import {Directory} from "../../../common/entities/Directory";
import {Message} from "../../../common/entities/Message";
2016-03-21 03:05:51 +08:00
import {GalleryDirectoryComponent} from "./directory/directory.gallery.component";
import {GalleryGridComponent} from "./grid/grid.gallery.component";
import {MATERIAL_DIRECTIVES} from "ng2-material/all";
import {SidenavService} from "ng2-material/all";
2016-03-13 18:28:29 +08:00
@Component({
selector: 'gallery',
2016-03-20 23:54:30 +08:00
templateUrl: 'app/gallery/gallery.component.html',
styleUrls: ['app/gallery/gallery.component.css'],
directives:[GalleryGridComponent,
GalleryDirectoryComponent,
MATERIAL_DIRECTIVES],
providers: [SidenavService]
2016-03-13 18:28:29 +08:00
})
export class GalleryComponent implements OnInit{
2016-03-26 23:25:48 +08:00
currentDirectory:Directory = new Directory(-1,"","/",new Date(),[],[]);
2016-03-20 23:54:30 +08:00
constructor(private _galleryService:GalleryService,
private _params: RouteParams,
private _authService: AuthenticationService,
private _router: Router,
public sidenav: SidenavService) {
}
ngOnInit(){
if (!this._authService.isAuthenticated()) {
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(['Login']);
2016-03-20 23:54:30 +08:00
return;
}
2016-03-28 03:21:47 +08:00
let directoryName = this._params.get('directory');
console.log(this._params);
console.log(directoryName);
2016-03-20 23:54:30 +08:00
directoryName = directoryName ? directoryName : "";
this._galleryService.getDirectory(directoryName).then(( message:Message<Directory>) => {
if(message.error){
2016-03-20 23:54:30 +08:00
//TODO: implement
return;
}
2016-03-26 23:25:48 +08:00
this.currentDirectory = message.result;
2016-03-20 23:54:30 +08:00
});
}
public showSideNav(){
this.sidenav.show("menu");
}
2016-03-13 18:28:29 +08:00
}