From 14ef03f7fbd195a7deea38203a252b4b51530c5f Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 9 Dec 2018 22:33:52 +0100 Subject: [PATCH] improving routing and searching experience --- common/QueryParams.ts | 2 + frontend/app/app.component.ts | 2 - frontend/app/app.routing.ts | 47 +++++++++++++------ frontend/app/gallery/gallery.component.html | 2 +- frontend/app/gallery/gallery.component.ts | 7 ++- .../photo/photo.grid.gallery.component.html | 2 +- .../search/search.gallery.component.ts | 20 ++++---- 7 files changed, 51 insertions(+), 31 deletions(-) diff --git a/common/QueryParams.ts b/common/QueryParams.ts index 40327348..3a2ca74f 100644 --- a/common/QueryParams.ts +++ b/common/QueryParams.ts @@ -12,6 +12,8 @@ export const QueryParams = { photo: 'p', sharingKey_short: 'sk', sharingKey_long: 'sharingKey', + searchText: 'searchText', + directory: 'directory', knownLastModified: 'knownLastModified', knownLastScanned: 'knownLastScanned' } diff --git a/frontend/app/app.component.ts b/frontend/app/app.component.ts index cc299b98..64f412f5 100644 --- a/frontend/app/app.component.ts +++ b/frontend/app/app.component.ts @@ -4,11 +4,9 @@ import {UserDTO} from '../../common/entities/UserDTO'; import {Router} from '@angular/router'; import {Config} from '../../common/config/public/Config'; import {Title} from '@angular/platform-browser'; -import {NotificationService} from './model/notification.service'; import {ShareService} from './gallery/share.service'; import 'hammerjs'; import {Subscription} from 'rxjs'; -import {QueryService} from './model/query.service'; @Component({ selector: 'app-pi-gallery2', diff --git a/frontend/app/app.routing.ts b/frontend/app/app.routing.ts index 2c273f45..9f039cb4 100644 --- a/frontend/app/app.routing.ts +++ b/frontend/app/app.routing.ts @@ -1,11 +1,42 @@ import {ModuleWithProviders} from '@angular/core'; -import {RouterModule, Routes} from '@angular/router'; +import {RouterModule, Routes, UrlMatchResult, UrlSegment} from '@angular/router'; import {LoginComponent} from './login/login.component'; import {GalleryComponent} from './gallery/gallery.component'; import {AdminComponent} from './admin/admin.component'; import {ShareLoginComponent} from './sharelogin/share-login.component'; import {QueryParams} from '../../common/QueryParams'; +export function galleryMatcherFunction( + segments: UrlSegment[]): UrlMatchResult | null { + + + if (segments.length === 0) { + return null; + } + const path = segments[0].path; + + const posParams: { [key: string]: UrlSegment } = {}; + if (path === 'gallery') { + if (segments.length > 1) { + posParams[QueryParams.gallery.directory] = segments[1]; + } + return {consumed: segments.slice(0, Math.min(segments.length, 2)), posParams}; + } + if (path === 'search') { + if (segments.length > 1) { + posParams[QueryParams.gallery.searchText] = segments[1]; + } + return {consumed: segments.slice(0, Math.min(segments.length, 2)), posParams}; + } + if (path === 'share') { + if (segments.length > 1) { + posParams[QueryParams.gallery.sharingKey_long] = segments[1]; + } + return {consumed: segments.slice(0, Math.min(segments.length, 2)), posParams}; + } + return null; +} + const ROUTES: Routes = [ { path: 'login', @@ -20,19 +51,7 @@ const ROUTES: Routes = [ component: AdminComponent }, { - path: 'gallery/:directory', - component: GalleryComponent - }, - { - path: 'gallery', - component: GalleryComponent - }, - { - path: 'search/:searchText', - component: GalleryComponent - }, - { - path: 'share/:' + QueryParams.gallery.sharingKey_long, + matcher: galleryMatcherFunction, component: GalleryComponent }, {path: '', redirectTo: '/login', pathMatch: 'full'}, diff --git a/frontend/app/gallery/gallery.component.html b/frontend/app/gallery/gallery.component.html index 7dff2914..31082bff 100644 --- a/frontend/app/gallery/gallery.component.html +++ b/frontend/app/gallery/gallery.component.html @@ -13,7 +13,7 @@