From 4e6922054ec40ff4d57ae4f505b679872f3d3f21 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 8 Jan 2023 11:31:47 +0100 Subject: [PATCH] Adding Album Reset Job and renaming DB reset to Gallery reset job --- src/backend/model/database/AlbumManager.ts | 10 +++++++ src/backend/model/database/PreviewManager.ts | 26 ++++++++++++----- src/backend/model/jobs/JobRepository.ts | 22 +++++++------- src/backend/model/jobs/jobs/AlbumResetJob.ts | 24 +++++++++++++++ src/backend/model/jobs/jobs/DBResetJob.ts | 29 ------------------- .../model/jobs/jobs/GalleryResetJob.ts | 24 +++++++++++++++ src/common/config/private/PrivateConfig.ts | 2 +- src/common/config/public/ClientConfig.ts | 7 ++++- src/common/entities/job/JobDTO.ts | 3 +- src/frontend/app/model/backendtext.service.ts | 6 ++-- .../app/ui/settings/settings.service.ts | 2 +- .../settings/template/template.component.html | 2 +- 12 files changed, 103 insertions(+), 54 deletions(-) create mode 100644 src/backend/model/jobs/jobs/AlbumResetJob.ts delete mode 100644 src/backend/model/jobs/jobs/DBResetJob.ts create mode 100644 src/backend/model/jobs/jobs/GalleryResetJob.ts diff --git a/src/backend/model/database/AlbumManager.ts b/src/backend/model/database/AlbumManager.ts index 53aa5b91..5ced81f6 100644 --- a/src/backend/model/database/AlbumManager.ts +++ b/src/backend/model/database/AlbumManager.ts @@ -7,6 +7,7 @@ import {SearchQueryDTO} from '../../../common/entities/SearchQueryDTO'; import {SavedSearchEntity} from './enitites/album/SavedSearchEntity'; import {Logger} from '../../Logger'; import {IObjectManager} from './IObjectManager'; +import {DirectoryEntity} from './enitites/DirectoryEntity'; const LOG_TAG = '[AlbumManager]'; @@ -110,4 +111,13 @@ export class AlbumManager implements IObjectManager { } this.isDBValid = true; } + + async deleteAll() { + const connection = await SQLConnection.getConnection(); + await connection + .getRepository(AlbumBaseEntity) + .createQueryBuilder('album') + .delete() + .execute(); + } } diff --git a/src/backend/model/database/PreviewManager.ts b/src/backend/model/database/PreviewManager.ts index 5fcbc2cb..9809abbc 100644 --- a/src/backend/model/database/PreviewManager.ts +++ b/src/backend/model/database/PreviewManager.ts @@ -13,6 +13,7 @@ import * as path from 'path'; import {Utils} from '../../../common/Utils'; import {PreviewPhotoDTO} from '../../../common/entities/PhotoDTO'; import {IObjectManager} from './IObjectManager'; +import {Logger} from '../../Logger'; const LOG_TAG = '[PreviewManager]'; @@ -121,7 +122,6 @@ export class PreviewManager implements IObjectManager { PreviewManager.setSorting(query); return query; }; - let previewMedia = null; if ( Config.Preview.SearchQuery && @@ -130,16 +130,26 @@ export class PreviewManager implements IObjectManager { text: '', } as TextSearch) ) { - const previewFilterQuery = await - ObjectManagers.getInstance().SearchManager.prepareAndBuildWhereQuery(Config.Preview.SearchQuery); - previewMedia = await previewQuery() - .andWhere(previewFilterQuery) - .limit(1) - .getOne(); + try { + const previewFilterQuery = await + ObjectManagers.getInstance().SearchManager.prepareAndBuildWhereQuery(Config.Preview.SearchQuery); + previewMedia = await previewQuery() + .andWhere(previewFilterQuery) + .limit(1) + .getOne(); + } catch (e) { + Logger.error('Cant get album preview using:', JSON.stringify(album.searchQuery), JSON.stringify(Config.Preview.SearchQuery)); + throw e; + } } if (!previewMedia) { - previewMedia = await previewQuery().limit(1).getOne(); + try { + previewMedia = await previewQuery().limit(1).getOne(); + } catch (e) { + Logger.error('Cant get album preview using:', JSON.stringify(album.searchQuery)); + throw e; + } } return previewMedia || null; } diff --git a/src/backend/model/jobs/JobRepository.ts b/src/backend/model/jobs/JobRepository.ts index 58a4d703..9521daef 100644 --- a/src/backend/model/jobs/JobRepository.ts +++ b/src/backend/model/jobs/JobRepository.ts @@ -1,13 +1,14 @@ -import { IJob } from './jobs/IJob'; -import { IndexingJob } from './jobs/IndexingJob'; -import { DBRestJob } from './jobs/DBResetJob'; -import { VideoConvertingJob } from './jobs/VideoConvertingJob'; -import { PhotoConvertingJob } from './jobs/PhotoConvertingJob'; -import { ThumbnailGenerationJob } from './jobs/ThumbnailGenerationJob'; -import { TempFolderCleaningJob } from './jobs/TempFolderCleaningJob'; -import { PreviewFillingJob } from './jobs/PreviewFillingJob'; -import { PreviewRestJob } from './jobs/PreviewResetJob'; +import {IJob} from './jobs/IJob'; +import {IndexingJob} from './jobs/IndexingJob'; +import {GalleryRestJob} from './jobs/GalleryResetJob'; +import {VideoConvertingJob} from './jobs/VideoConvertingJob'; +import {PhotoConvertingJob} from './jobs/PhotoConvertingJob'; +import {ThumbnailGenerationJob} from './jobs/ThumbnailGenerationJob'; +import {TempFolderCleaningJob} from './jobs/TempFolderCleaningJob'; +import {PreviewFillingJob} from './jobs/PreviewFillingJob'; +import {PreviewRestJob} from './jobs/PreviewResetJob'; import {GPXCompressionJob} from './jobs/GPXCompressionJob'; +import {AlbumRestJob} from './jobs/AlbumResetJob'; export class JobRepository { private static instance: JobRepository = null; @@ -33,7 +34,7 @@ export class JobRepository { } JobRepository.Instance.register(new IndexingJob()); -JobRepository.Instance.register(new DBRestJob()); +JobRepository.Instance.register(new GalleryRestJob()); JobRepository.Instance.register(new PreviewFillingJob()); JobRepository.Instance.register(new PreviewRestJob()); JobRepository.Instance.register(new VideoConvertingJob()); @@ -41,3 +42,4 @@ JobRepository.Instance.register(new PhotoConvertingJob()); JobRepository.Instance.register(new ThumbnailGenerationJob()); JobRepository.Instance.register(new GPXCompressionJob()); JobRepository.Instance.register(new TempFolderCleaningJob()); +JobRepository.Instance.register(new AlbumRestJob()); diff --git a/src/backend/model/jobs/jobs/AlbumResetJob.ts b/src/backend/model/jobs/jobs/AlbumResetJob.ts new file mode 100644 index 00000000..93967743 --- /dev/null +++ b/src/backend/model/jobs/jobs/AlbumResetJob.ts @@ -0,0 +1,24 @@ +import {ObjectManagers} from '../../ObjectManagers'; +import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {Job} from './Job'; + +export class AlbumRestJob extends Job { + public readonly Name = DefaultsJobs[DefaultsJobs['Album Reset']]; + public readonly ConfigTemplate: ConfigTemplateEntry[] = null; + protected readonly IsInstant = true; + + public get Supported(): boolean { + return true; + } + + protected async init(): Promise { + // abstract function + } + + protected async step(): Promise { + this.Progress.Left = 1; + this.Progress.Processed++; + await ObjectManagers.getInstance().AlbumManager.deleteAll(); + return false; + } +} diff --git a/src/backend/model/jobs/jobs/DBResetJob.ts b/src/backend/model/jobs/jobs/DBResetJob.ts deleted file mode 100644 index 627821ff..00000000 --- a/src/backend/model/jobs/jobs/DBResetJob.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { ObjectManagers } from '../../ObjectManagers'; -import { Config } from '../../../../common/config/private/Config'; -import { - ConfigTemplateEntry, - DefaultsJobs, -} from '../../../../common/entities/job/JobDTO'; -import { Job } from './Job'; -import { DatabaseType } from '../../../../common/config/private/PrivateConfig'; - -export class DBRestJob extends Job { - public readonly Name = DefaultsJobs[DefaultsJobs['Database Reset']]; - public readonly ConfigTemplate: ConfigTemplateEntry[] = null; - protected readonly IsInstant = true; - - public get Supported(): boolean { - return true; - } - - protected async init(): Promise { - // abstract function - } - - protected async step(): Promise { - this.Progress.Left = 1; - this.Progress.Processed++; - await ObjectManagers.getInstance().IndexingManager.resetDB(); - return false; - } -} diff --git a/src/backend/model/jobs/jobs/GalleryResetJob.ts b/src/backend/model/jobs/jobs/GalleryResetJob.ts new file mode 100644 index 00000000..00fa74e4 --- /dev/null +++ b/src/backend/model/jobs/jobs/GalleryResetJob.ts @@ -0,0 +1,24 @@ +import {ObjectManagers} from '../../ObjectManagers'; +import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {Job} from './Job'; + +export class GalleryRestJob extends Job { + public readonly Name = DefaultsJobs[DefaultsJobs['Gallery Reset']]; + public readonly ConfigTemplate: ConfigTemplateEntry[] = null; + protected readonly IsInstant = true; + + public get Supported(): boolean { + return true; + } + + protected async init(): Promise { + // abstract function + } + + protected async step(): Promise { + this.Progress.Left = 1; + this.Progress.Processed++; + await ObjectManagers.getInstance().IndexingManager.resetDB(); + return false; + } +} diff --git a/src/common/config/private/PrivateConfig.ts b/src/common/config/private/PrivateConfig.ts index ac2c55d9..1590b6e4 100644 --- a/src/common/config/private/PrivateConfig.ts +++ b/src/common/config/private/PrivateConfig.ts @@ -1049,7 +1049,7 @@ export class ServerConfig extends ClientConfig { job: DefaultsJobs[DefaultsJobs.Indexing], description: $localize`If you add a new folder to your gallery, the site indexes it automatically. If you would like to trigger indexing manually, click index button. (Note: search only works among the indexed directories.)` }, { - job: DefaultsJobs[DefaultsJobs['Database Reset']], + job: DefaultsJobs[DefaultsJobs['Gallery Reset']], hideProgress: true }] } as TAGS diff --git a/src/common/config/public/ClientConfig.ts b/src/common/config/public/ClientConfig.ts index a1c45c7b..11d2eb61 100644 --- a/src/common/config/public/ClientConfig.ts +++ b/src/common/config/public/ClientConfig.ts @@ -4,6 +4,7 @@ import {SortingMethods} from '../../entities/SortingMethods'; import {UserRoles} from '../../entities/UserDTO'; import {ConfigProperty, SubConfigClass} from 'typeconfig/common'; import {SearchQueryDTO} from '../../entities/SearchQueryDTO'; +import { DefaultsJobs } from '../../entities/job/JobDTO'; declare let $localize: (s: TemplateStringsArray) => string; if (typeof $localize === 'undefined') { @@ -855,7 +856,11 @@ export class ClientConfig { @ConfigProperty({ tags: { name: $localize`Album`, - uiIcon: 'grid-two-up' + uiIcon: 'grid-two-up', + uiJob: [ { + job: DefaultsJobs[DefaultsJobs['Album Reset']], + hideProgress: true + }] } as TAGS, }) Album: ClientAlbumConfig = new ClientAlbumConfig(); diff --git a/src/common/entities/job/JobDTO.ts b/src/common/entities/job/JobDTO.ts index d0e1ff68..113728c5 100644 --- a/src/common/entities/job/JobDTO.ts +++ b/src/common/entities/job/JobDTO.ts @@ -4,7 +4,7 @@ export type fieldType = 'string' | 'number' | 'boolean' | 'number-array'; export enum DefaultsJobs { Indexing = 1, - 'Database Reset' = 2, + 'Gallery Reset' = 2, 'Video Converting' = 3, 'Photo Converting' = 4, 'Thumbnail Generation' = 5, @@ -12,6 +12,7 @@ export enum DefaultsJobs { 'Preview Filling' = 7, 'Preview Reset' = 8, 'GPX Compression' = 9, + 'Album Reset' = 10, } export interface ConfigTemplateEntry { diff --git a/src/frontend/app/model/backendtext.service.ts b/src/frontend/app/model/backendtext.service.ts index b45b9f34..738d6e6f 100644 --- a/src/frontend/app/model/backendtext.service.ts +++ b/src/frontend/app/model/backendtext.service.ts @@ -31,8 +31,10 @@ export class BackendtextService { switch (job as DefaultsJobs) { case DefaultsJobs.Indexing: return $localize`Indexing`; - case DefaultsJobs['Database Reset']: - return $localize`Database reset`; + case DefaultsJobs['Gallery Reset']: + return $localize`Gallery reset`; + case DefaultsJobs['Album Reset']: + return $localize`Album reset`; case DefaultsJobs['Thumbnail Generation']: return $localize`Thumbnail generation`; case DefaultsJobs['Photo Converting']: diff --git a/src/frontend/app/ui/settings/settings.service.ts b/src/frontend/app/ui/settings/settings.service.ts index 458f2048..bd06c4e6 100644 --- a/src/frontend/app/ui/settings/settings.service.ts +++ b/src/frontend/app/ui/settings/settings.service.ts @@ -38,7 +38,7 @@ export class SettingsService { this.jobsService.onJobFinish.subscribe((jobName: string) => { if ( jobName === DefaultsJobs[DefaultsJobs.Indexing] || - jobName === DefaultsJobs[DefaultsJobs['Database Reset']] + jobName === DefaultsJobs[DefaultsJobs['Gallery Reset']] ) { this.loadStatistic(); } diff --git a/src/frontend/app/ui/settings/template/template.component.html b/src/frontend/app/ui/settings/template/template.component.html index 3e553d00..1a1a3195 100644 --- a/src/frontend/app/ui/settings/template/template.component.html +++ b/src/frontend/app/ui/settings/template/template.component.html @@ -127,7 +127,7 @@ [soloRun]="true" (jobError)="error=$event" [allowParallelRun]="false" - [danger]="i>0" + [danger]="job.job.includes('Reset')" [jobName]="job.job">