From b8963eb3e4d4f0a45f798829b2feac1061d2fff4 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Sat, 26 Mar 2016 16:25:48 +0100 Subject: [PATCH] implementing directory navigation --- backend/routes/GalleryRouter.ts | 2 +- common/Utils.ts | 16 ++++++++++++++-- frontend/app/app.component.ts | 6 +++--- .../directory/directory.gallery.component.html | 2 +- .../directory/directory.gallery.component.ts | 4 +++- frontend/app/gallery/gallery.component.html | 6 +++--- frontend/app/gallery/gallery.component.ts | 4 ++-- .../app/gallery/photo/photo.gallery.component.ts | 6 +++++- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/backend/routes/GalleryRouter.ts b/backend/routes/GalleryRouter.ts index c3f48ec3..096f6d85 100644 --- a/backend/routes/GalleryRouter.ts +++ b/backend/routes/GalleryRouter.ts @@ -16,7 +16,7 @@ export class GalleryRouter{ } private addDirectoryList() { - this.app.get(["/api/gallery/:directory","/api/gallery/"], + this.app.get(["/api/gallery/:directory","/api/gallery/","/api/gallery//"], AuthenticationMWs.authenticate, GalleryMWs.listDirectory, RenderingMWs.renderResult diff --git a/common/Utils.ts b/common/Utils.ts index 75e2c819..09e5a1fd 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -1,5 +1,3 @@ -/// - export class Utils { static clone(object:T):T { @@ -7,4 +5,18 @@ export class Utils { } + static concatUrls(...args:Array){ + 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); + } + } diff --git a/frontend/app/app.component.ts b/frontend/app/app.component.ts index 9c1a7a81..2eb6d4ca 100644 --- a/frontend/app/app.component.ts +++ b/frontend/app/app.component.ts @@ -1,7 +1,7 @@ /// 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 {AuthenticationService} from "./model/authentication.service"; import {GalleryComponent} from "./gallery/gallery.component"; @@ -34,7 +34,7 @@ import {GalleryService} from "./gallery/gallery.service"; useAsDefault: true }, { - path: '/gallery', + path: '/gallery/:directory', name: 'Gallery', component: GalleryComponent } @@ -48,7 +48,7 @@ export class AppComponent implements OnInit{ this._authenticationService.OnAuthenticated.on((user:User) => { this._location.replaceState('/'); // clears browser history so they can't navigate with back button - this._router.navigate(["Gallery"]); + this._router.navigate(["Gallery",{directory:"/"}]); }); } diff --git a/frontend/app/gallery/directory/directory.gallery.component.html b/frontend/app/gallery/directory/directory.gallery.component.html index a442264d..afc5310b 100644 --- a/frontend/app/gallery/directory/directory.gallery.component.html +++ b/frontend/app/gallery/directory/directory.gallery.component.html @@ -1 +1 @@ -{{directory.name}} \ No newline at end of file +{{directory.name}} \ No newline at end of file diff --git a/frontend/app/gallery/directory/directory.gallery.component.ts b/frontend/app/gallery/directory/directory.gallery.component.ts index 65b89ab8..a24220af 100644 --- a/frontend/app/gallery/directory/directory.gallery.component.ts +++ b/frontend/app/gallery/directory/directory.gallery.component.ts @@ -2,10 +2,12 @@ import {Component, Input, OnInit} from 'angular2/core'; import {Directory} from "../../../../common/entities/Directory"; +import {RouterLink} from "angular2/router"; @Component({ selector: 'gallery-directory', - templateUrl: 'app/gallery/directory/directory.gallery.component.html' + templateUrl: 'app/gallery/directory/directory.gallery.component.html', + directives:[RouterLink] }) export class GalleryDirectoryComponent{ @Input() directory: Directory; diff --git a/frontend/app/gallery/gallery.component.html b/frontend/app/gallery/gallery.component.html index 648443bc..ea85b8a0 100644 --- a/frontend/app/gallery/gallery.component.html +++ b/frontend/app/gallery/gallery.component.html @@ -1,8 +1,8 @@

Gallery

-
+
-
- +
+
\ No newline at end of file diff --git a/frontend/app/gallery/gallery.component.ts b/frontend/app/gallery/gallery.component.ts index ef7562be..213c3606 100644 --- a/frontend/app/gallery/gallery.component.ts +++ b/frontend/app/gallery/gallery.component.ts @@ -17,7 +17,7 @@ import {GalleryDirectoryComponent} from "./directory/directory.gallery.component }) export class GalleryComponent implements OnInit{ - directory:Directory = new Directory(-1,"","/",new Date(),[],[]); + currentDirectory:Directory = new Directory(-1,"","/",new Date(),[],[]); constructor(private _galleryService:GalleryService, private _params: RouteParams, @@ -41,7 +41,7 @@ export class GalleryComponent implements OnInit{ return; } - this.directory = message.result; + this.currentDirectory = message.result; }); } diff --git a/frontend/app/gallery/photo/photo.gallery.component.ts b/frontend/app/gallery/photo/photo.gallery.component.ts index 600d5a04..7bbe1b8c 100644 --- a/frontend/app/gallery/photo/photo.gallery.component.ts +++ b/frontend/app/gallery/photo/photo.gallery.component.ts @@ -2,6 +2,8 @@ import {Component, Input, OnInit} from 'angular2/core'; import {Photo} from "../../../../common/entities/Photo"; +import {Directory} from "../../../../common/entities/Directory"; +import {Utils} from "../../../../common/Utils"; @Component({ selector: 'gallery-photo', @@ -9,12 +11,14 @@ import {Photo} from "../../../../common/entities/Photo"; }) export class GalleryPhotoComponent{ @Input() photo: Photo; + @Input() directory: Directory; constructor() { } 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); } }