1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

implementing directory navigation

This commit is contained in:
Braun Patrik 2016-03-26 16:25:48 +01:00
parent 95d34b7e46
commit b8963eb3e4
8 changed files with 32 additions and 14 deletions

View File

@ -16,7 +16,7 @@ export class GalleryRouter{
} }
private addDirectoryList() { private addDirectoryList() {
this.app.get(["/api/gallery/:directory","/api/gallery/"], this.app.get(["/api/gallery/:directory","/api/gallery/","/api/gallery//"],
AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
GalleryMWs.listDirectory, GalleryMWs.listDirectory,
RenderingMWs.renderResult RenderingMWs.renderResult

View File

@ -1,5 +1,3 @@
/// <reference path="../typings/main.d.ts"/>
export class Utils { export class Utils {
static clone<T>(object:T):T { static clone<T>(object:T):T {
@ -7,4 +5,18 @@ export class Utils {
} }
static concatUrls(...args:Array<string>){
let url = "";
for(let i = 0 ; i < args.length; i++){
if(args[i] === "" || typeof args[i] === "undefined") continue;
let part = args[i].replace("\\","/");
if(part === "/" || part === "./") continue;
url += part + "/";
}
return url.substring(0, url.length - 1);
}
} }

View File

@ -1,7 +1,7 @@
///<reference path="../browser.d.ts"/> ///<reference path="../browser.d.ts"/>
import { Component } from 'angular2/core'; import { Component } from 'angular2/core';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouterLink} from 'angular2/router';
import {LoginComponent} from "./login/login.component"; import {LoginComponent} from "./login/login.component";
import {AuthenticationService} from "./model/authentication.service"; import {AuthenticationService} from "./model/authentication.service";
import {GalleryComponent} from "./gallery/gallery.component"; import {GalleryComponent} from "./gallery/gallery.component";
@ -34,7 +34,7 @@ import {GalleryService} from "./gallery/gallery.service";
useAsDefault: true useAsDefault: true
}, },
{ {
path: '/gallery', path: '/gallery/:directory',
name: 'Gallery', name: 'Gallery',
component: GalleryComponent component: GalleryComponent
} }
@ -48,7 +48,7 @@ export class AppComponent implements OnInit{
this._authenticationService.OnAuthenticated.on((user:User) => this._authenticationService.OnAuthenticated.on((user:User) =>
{ {
this._location.replaceState('/'); // clears browser history so they can't navigate with back button this._location.replaceState('/'); // clears browser history so they can't navigate with back button
this._router.navigate(["Gallery"]); this._router.navigate(["Gallery",{directory:"/"}]);
}); });
} }

View File

@ -1 +1 @@
<span>{{directory.name}}</span> <a [routerLink]="['Gallery',{directory: directory.name}]">{{directory.name}}</a>

View File

@ -2,10 +2,12 @@
import {Component, Input, OnInit} from 'angular2/core'; import {Component, Input, OnInit} from 'angular2/core';
import {Directory} from "../../../../common/entities/Directory"; import {Directory} from "../../../../common/entities/Directory";
import {RouterLink} from "angular2/router";
@Component({ @Component({
selector: 'gallery-directory', selector: 'gallery-directory',
templateUrl: 'app/gallery/directory/directory.gallery.component.html' templateUrl: 'app/gallery/directory/directory.gallery.component.html',
directives:[RouterLink]
}) })
export class GalleryDirectoryComponent{ export class GalleryDirectoryComponent{
@Input() directory: Directory; @Input() directory: Directory;

View File

@ -1,8 +1,8 @@
<h1>Gallery</h1> <h1>Gallery</h1>
<div *ngIf="directory" *ngFor="#directory of directory.directories" > <div *ngIf="currentDirectory" *ngFor="#directory of currentDirectory.directories" >
<gallery-directory *ngIf="directory" [directory]="directory" ></gallery-directory> <gallery-directory *ngIf="directory" [directory]="directory" ></gallery-directory>
</div> </div>
<div *ngIf="directory" *ngFor="#photo of directory.photos" > <div *ngIf="currentDirectory" *ngFor="#photo of currentDirectory.photos" >
<gallery-photo *ngIf="photo" [photo]="photo" ></gallery-photo> <gallery-photo *ngIf="photo" [photo]="photo" [directory]="currentDirectory"></gallery-photo>
</div> </div>

View File

@ -17,7 +17,7 @@ import {GalleryDirectoryComponent} from "./directory/directory.gallery.component
}) })
export class GalleryComponent implements OnInit{ export class GalleryComponent implements OnInit{
directory:Directory = new Directory(-1,"","/",new Date(),[],[]); currentDirectory:Directory = new Directory(-1,"","/",new Date(),[],[]);
constructor(private _galleryService:GalleryService, constructor(private _galleryService:GalleryService,
private _params: RouteParams, private _params: RouteParams,
@ -41,7 +41,7 @@ export class GalleryComponent implements OnInit{
return; return;
} }
this.directory = message.result; this.currentDirectory = message.result;
}); });
} }

View File

@ -2,6 +2,8 @@
import {Component, Input, OnInit} from 'angular2/core'; import {Component, Input, OnInit} from 'angular2/core';
import {Photo} from "../../../../common/entities/Photo"; import {Photo} from "../../../../common/entities/Photo";
import {Directory} from "../../../../common/entities/Directory";
import {Utils} from "../../../../common/Utils";
@Component({ @Component({
selector: 'gallery-photo', selector: 'gallery-photo',
@ -9,12 +11,14 @@ import {Photo} from "../../../../common/entities/Photo";
}) })
export class GalleryPhotoComponent{ export class GalleryPhotoComponent{
@Input() photo: Photo; @Input() photo: Photo;
@Input() directory: Directory;
constructor() { constructor() {
} }
getPhotoPath(){ getPhotoPath(){
return "/api/gallery/"+this.photo.name; console.log(Utils.concatUrls("/api/gallery",this.directory.path,this.directory.name,this.photo.name));
return Utils.concatUrls("/api/gallery",this.directory.path,this.directory.name,this.photo.name);
} }
} }