From f4f22118ab77ea25dac792c0c7d56ce19b936289 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Thu, 13 Jan 2022 22:41:30 +0100 Subject: [PATCH] improving metadata config --- .../model/database/sql/GalleryManager.ts | 6 +- .../model/diagnostics/ConfigDiagnostics.ts | 7 +- .../model/threading/DiskMangerWorker.ts | 21 ++++- src/common/config/public/ClientConfig.ts | 8 +- src/common/config/public/Config.ts | 3 +- src/frontend/app/app.module.ts | 8 +- src/frontend/app/pipes/GPXFilesFilterPipe.ts | 4 + src/frontend/app/pipes/PhotoFilterPipe.ts | 14 +++ .../app/ui/gallery/gallery.component.html | 90 +++++++------------ .../app/ui/gallery/gallery.component.ts | 12 ++- .../settings-entry.component.ts | 2 +- .../metafile.settings.component.html | 38 ++++---- .../unit/model/sql/IndexingManager.spec.ts | 16 +++- 13 files changed, 135 insertions(+), 94 deletions(-) create mode 100644 src/frontend/app/pipes/PhotoFilterPipe.ts diff --git a/src/backend/model/database/sql/GalleryManager.ts b/src/backend/model/database/sql/GalleryManager.ts index 4f48102d..f5d5110d 100644 --- a/src/backend/model/database/sql/GalleryManager.ts +++ b/src/backend/model/database/sql/GalleryManager.ts @@ -242,7 +242,11 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager { .leftJoinAndSelect('directory.directories', 'directories') .leftJoinAndSelect('directory.media', 'media'); - if (Config.Client.MetaFile.enabled === true) { + // TODO: do better filtering + // NOTE: it should not cause an issue as it also do not shave to the DB + if (Config.Client.MetaFile.gpx === true || + Config.Client.MetaFile.pg2conf === true || + Config.Client.MetaFile.markdown === true) { query.leftJoinAndSelect('directory.metaFile', 'metaFile'); } diff --git a/src/backend/model/diagnostics/ConfigDiagnostics.ts b/src/backend/model/diagnostics/ConfigDiagnostics.ts index 5a2bb863..c71de4ba 100644 --- a/src/backend/model/diagnostics/ConfigDiagnostics.ts +++ b/src/backend/model/diagnostics/ConfigDiagnostics.ts @@ -65,8 +65,7 @@ export class ConfigDiagnostics { static async testMetaFileConfig(metaFileConfig: ClientMetaFileConfig, config: IPrivateConfig): Promise { - // TODO: now we have metadata for pg2conf files too not only gpx that also runs without map - if (metaFileConfig.enabled === true && + if (metaFileConfig.gpx === true && config.Client.Map.enabled === false) { throw new Error('*.gpx meta files are not supported without MAP'); } @@ -275,9 +274,9 @@ export class ConfigDiagnostics { await ConfigDiagnostics.testMetaFileConfig(Config.Client.MetaFile, Config); } catch (ex) { const err: Error = ex; - NotificationManager.warning('Meta file support error, switching off..', err.toString()); + NotificationManager.warning('Meta file support error, switching off gpx..', err.toString()); Logger.warn(LOG_TAG, 'Meta file support error, switching off..', err.toString()); - Config.Client.MetaFile.enabled = false; + Config.Client.MetaFile.gpx = false; } try { diff --git a/src/backend/model/threading/DiskMangerWorker.ts b/src/backend/model/threading/DiskMangerWorker.ts index 5d218bc6..5726e389 100644 --- a/src/backend/model/threading/DiskMangerWorker.ts +++ b/src/backend/model/threading/DiskMangerWorker.ts @@ -174,10 +174,11 @@ export class DiskMangerWorker { } } else if (DiskMangerWorker.isMetaFile(fullFilePath)) { - if (Config.Client.MetaFile.enabled === false || settings.noMetaFile === true || settings.previewOnly === true) { + if (!DiskMangerWorker.isEnabledMetaFile(fullFilePath) || + settings.noMetaFile === true || + settings.previewOnly === true) { continue; } - directory.metaFile.push({ name: file, directory: null, @@ -197,6 +198,22 @@ export class DiskMangerWorker { return SupportedFormats.WithDots.MetaFiles.indexOf(extension) !== -1; } + private static isEnabledMetaFile(fullPath: string): boolean { + const extension = path.extname(fullPath).toLowerCase(); + + switch (extension) { + case '.gpx': + return Config.Client.MetaFile.gpx; + case '.md': + return Config.Client.MetaFile.markdown; + case '.pg2conf': + return Config.Client.MetaFile.pg2conf; + } + + return false; + } + + } export interface DirectoryScanSettings { diff --git a/src/common/config/public/ClientConfig.ts b/src/common/config/public/ClientConfig.ts index dcf3f938..ca143bb7 100644 --- a/src/common/config/public/ClientConfig.ts +++ b/src/common/config/public/ClientConfig.ts @@ -154,8 +154,12 @@ export class ClientMediaConfig { @SubConfigClass() export class ClientMetaFileConfig { - @ConfigProperty() - enabled: boolean = true; + @ConfigProperty({description: 'Reads *.gpx files and renders them on the map'}) + gpx: boolean = true; + @ConfigProperty({description: 'Reads *.md files in a directory and shows the next to the map'}) + markdown: boolean = true; + @ConfigProperty({description: 'Reads *.pg2conf files'}) + pg2conf: boolean = true; } @SubConfigClass() diff --git a/src/common/config/public/Config.ts b/src/common/config/public/Config.ts index 71bf6acc..1422d6ab 100644 --- a/src/common/config/public/Config.ts +++ b/src/common/config/public/Config.ts @@ -2,6 +2,7 @@ import {ClientConfig} from './ClientConfig'; import {WebConfigClass} from 'typeconfig/src/decorators/class/WebConfigClass'; import {WebConfigClassBuilder} from 'typeconfig/src/decorators/builders/WebConfigClassBuilder'; import {ConfigProperty} from 'typeconfig/src/decorators/property/ConfigPropoerty'; +import {IWebConfigClass} from 'typeconfig/common'; /** @@ -20,7 +21,7 @@ declare namespace ServerInject { export const ConfigInject: ClientClass; } -export let Config = WebConfigClassBuilder.attachInterface(new ClientClass()); +export let Config: IWebConfigClass & ClientClass = WebConfigClassBuilder.attachInterface(new ClientClass()); if (typeof ServerInject !== 'undefined' && typeof ServerInject.ConfigInject !== 'undefined') { diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts index 0c367ba4..3e6140ef 100644 --- a/src/frontend/app/app.module.ts +++ b/src/frontend/app/app.module.ts @@ -106,11 +106,12 @@ import {AlbumsService} from './ui/albums/albums.service'; import {GallerySearchQueryBuilderComponent} from './ui/gallery/search/query-builder/query-bulder.gallery.component'; import {SavedSearchPopupComponent} from './ui/albums/saved-search-popup/saved-search-popup.component'; import {AlbumsSettingsComponent} from './ui/settings/albums/albums.settings.component'; -import { MarkdownModule } from 'ngx-markdown'; +import {MarkdownModule} from 'ngx-markdown'; import {GalleryBlogComponent} from './ui/gallery/blog/blog.gallery.component'; import {MDFilesFilterPipe} from './pipes/MDFilesFilterPipe'; import {FileDTOToPathPipe} from './pipes/FileDTOToPathPipe'; import {BlogService} from './ui/gallery/blog/blog.service'; +import {PhotoFilterPipe} from './pipes/PhotoFilterPipe'; @Injectable() export class MyHammerConfig extends HammerGestureConfig { @@ -177,7 +178,7 @@ Marker.prototype.options.icon = iconDefault; LoadingBarModule, LeafletModule, LeafletMarkerClusterModule, - MarkdownModule.forRoot({ loader: HttpClient }), + MarkdownModule.forRoot({loader: HttpClient}), ], declarations: [AppComponent, LoginComponent, @@ -250,7 +251,8 @@ Marker.prototype.options.icon = iconDefault; GPXFilesFilterPipe, MDFilesFilterPipe, StringifySearchQuery, - FileDTOToPathPipe + FileDTOToPathPipe, + PhotoFilterPipe ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: CSRFInterceptor, multi: true}, diff --git a/src/frontend/app/pipes/GPXFilesFilterPipe.ts b/src/frontend/app/pipes/GPXFilesFilterPipe.ts index 973c8201..cc13d76e 100644 --- a/src/frontend/app/pipes/GPXFilesFilterPipe.ts +++ b/src/frontend/app/pipes/GPXFilesFilterPipe.ts @@ -1,10 +1,14 @@ import {Pipe, PipeTransform} from '@angular/core'; import {FileDTO} from '../../../common/entities/FileDTO'; +import {Config} from '../../../common/config/public/Config'; @Pipe({name: 'gpxFiles'}) export class GPXFilesFilterPipe implements PipeTransform { transform(metaFiles: FileDTO[]): FileDTO[] | null { + if (!Config.Client.MetaFile.gpx) { + return []; + } if (!metaFiles) { return null; } diff --git a/src/frontend/app/pipes/PhotoFilterPipe.ts b/src/frontend/app/pipes/PhotoFilterPipe.ts new file mode 100644 index 00000000..28b63132 --- /dev/null +++ b/src/frontend/app/pipes/PhotoFilterPipe.ts @@ -0,0 +1,14 @@ +import {Pipe, PipeTransform} from '@angular/core'; +import {MediaDTO, MediaDTOUtils} from '../../../common/entities/MediaDTO'; +import {PhotoDTO} from '../../../common/entities/PhotoDTO'; + + +@Pipe({name: 'photosOnly'}) +export class PhotoFilterPipe implements PipeTransform { + transform(media: MediaDTO[]): PhotoDTO[] | null { + if (!media) { + return null; + } + return media.filter((m: MediaDTO): boolean => MediaDTOUtils.isPhoto(m)) as PhotoDTO[]; + } +} diff --git a/src/frontend/app/ui/gallery/gallery.component.html b/src/frontend/app/ui/gallery/gallery.component.html index 11897b92..e63156f4 100644 --- a/src/frontend/app/ui/gallery/gallery.component.html +++ b/src/frontend/app/ui/gallery/gallery.component.html @@ -28,78 +28,52 @@
- + - - + + + - - - - -
- - + + - - - -
- + + +
+ + - - - - - + + + +
+ - - -
- - - - - - - -
- - - - -
+ *ngIf="(!ContentWrapper.directory || + ContentWrapper.directory.isPartial == true) + && !ContentWrapper.searchResult + && !ContentWrapper.error">
diff --git a/src/frontend/app/ui/gallery/gallery.component.ts b/src/frontend/app/ui/gallery/gallery.component.ts index d6ca391a..9ff5ce72 100644 --- a/src/frontend/app/ui/gallery/gallery.component.ts +++ b/src/frontend/app/ui/gallery/gallery.component.ts @@ -1,7 +1,7 @@ import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {AuthenticationService} from '../../model/network/authentication.service'; import {ActivatedRoute, Params, Router} from '@angular/router'; -import {GalleryService} from './gallery.service'; +import {ContentWrapperWithError, GalleryService} from './gallery.service'; import {GalleryGridComponent} from './grid/grid.gallery.component'; import {Config} from '../../../../common/config/public/Config'; import {ParentDirectoryDTO, SubDirectoryDTO} from '../../../../common/entities/DirectoryDTO'; @@ -32,6 +32,7 @@ export class GalleryComponent implements OnInit, OnDestroy { public showRandomPhotoBuilder = false; public blogOpen = false; + config = Config; public directories: SubDirectoryDTO[] = []; public isPhotoWithLocation = false; public countDown: { day: number, hour: number, minute: number, second: number } = null; @@ -56,6 +57,15 @@ export class GalleryComponent implements OnInit, OnDestroy { PageHelper.showScrollY(); } + get Content(): SearchResultDTO | ParentDirectoryDTO { + const cont = (this.ContentWrapper.searchResult || this.ContentWrapper.directory); + return cont ? cont : {} as any; + } + + get ContentWrapper(): ContentWrapperWithError { + return this.galleryService.content.value; + } + updateTimer(t: number): void { if (this.shareService.sharingSubject.value == null) { return; diff --git a/src/frontend/app/ui/settings/_abstract/settings-entry/settings-entry.component.ts b/src/frontend/app/ui/settings/_abstract/settings-entry/settings-entry.component.ts index a1c39ce9..04a6dc0b 100644 --- a/src/frontend/app/ui/settings/_abstract/settings-entry/settings-entry.component.ts +++ b/src/frontend/app/ui/settings/_abstract/settings-entry/settings-entry.component.ts @@ -31,7 +31,7 @@ export class SettingsEntryComponent implements ControlValueAccessor, Validator, @Input() options: { key: number | string, value: number | string }[]; @Input() simplifiedMode = false; @Input() allowSpaces = false; - @Input() description: boolean; + @Input() description: string; state: { isEnumType: boolean, isConfigType: boolean, diff --git a/src/frontend/app/ui/settings/metafiles/metafile.settings.component.html b/src/frontend/app/ui/settings/metafiles/metafile.settings.component.html index e8b6b393..f3aff70b 100644 --- a/src/frontend/app/ui/settings/metafiles/metafile.settings.component.html +++ b/src/frontend/app/ui/settings/metafiles/metafile.settings.component.html @@ -2,27 +2,31 @@
{{Name}} -
- - -
- Reads and show *.gpx files on the map and *.md files (blogs) in the gallery.  + + + + + + + + +