From 012c1bda7f75604bb9cb8fd72d116140775cf310 Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Tue, 25 Aug 2020 07:09:43 -0400 Subject: [PATCH] Changed the app to use the new feature to move comics [#378] * Refactored the MoveComics component. * Removed the old state wiring code. * Changed i18n entries to be feature-specific. --- .../app/library/actions/library.actions.ts | 30 -------- .../library/adaptors/library.adaptor.spec.ts | 68 +------------------ .../app/library/adaptors/library.adaptor.ts | 26 ------- .../consolidate-library.component.html | 36 ++++++++-- .../consolidate-library.component.spec.ts | 45 ++++++------ .../consolidate-library.component.ts | 53 ++++++++++----- .../library/effects/library.effects.spec.ts | 67 +----------------- .../app/library/effects/library.effects.ts | 51 -------------- .../library-admin-page.component.html | 2 +- .../library-admin-page.component.spec.ts | 7 ++ .../library/reducers/library.reducer.spec.ts | 57 ---------------- .../app/library/reducers/library.reducer.ts | 12 ---- .../src/assets/i18n/en/library.json | 60 ++++++++-------- .../src/assets/i18n/es/library.json | 60 ++++++++-------- .../src/assets/i18n/fr/library.json | 60 ++++++++-------- .../src/assets/i18n/pt/library.json | 60 ++++++++-------- 16 files changed, 210 insertions(+), 484 deletions(-) diff --git a/comixed-frontend/src/app/library/actions/library.actions.ts b/comixed-frontend/src/app/library/actions/library.actions.ts index b76885d47..c87b6e7e4 100644 --- a/comixed-frontend/src/app/library/actions/library.actions.ts +++ b/comixed-frontend/src/app/library/actions/library.actions.ts @@ -38,9 +38,6 @@ export enum LibraryActionTypes { ConvertComics = '[LIBRARY] Convert comics to a new archive type', ComicsConverting = '[LIBRARY] Comics converting to a new archive type', ConvertComicsFailed = '[LIBRARY] Failed to convert comics', - MoveComics = '[LIBRARY] Move the library', - ComicsMoved = '[LIBRARY] Library was moved', - MoveComicsFailed = '[LIBRARY] Moving the library failed', ClearImageCache = '[LIBRARY] Clear the image cache', ImageCacheCleared = '[LIBRARY] Image cache cleared', ClearImageCacheFailed = '[LIBRARY] Failed to clear the image cache' @@ -168,30 +165,6 @@ export class LibraryConvertComicsFailed implements Action { constructor() {} } -export class LibraryMoveComics implements Action { - readonly type = LibraryActionTypes.MoveComics; - - constructor( - public payload: { - deletePhysicalFiles: boolean; - directory: string; - renamingRule: string; - } - ) {} -} - -export class LibraryComicsMoved implements Action { - readonly type = LibraryActionTypes.ComicsMoved; - - constructor() {} -} - -export class LibraryMoveComicsFailed implements Action { - readonly type = LibraryActionTypes.MoveComicsFailed; - - constructor() {} -} - export class LibraryClearImageCache implements Action { readonly type = LibraryActionTypes.ClearImageCache; @@ -227,9 +200,6 @@ export type LibraryActions = | LibraryConvertComics | LibraryComicsConverting | LibraryConvertComicsFailed - | LibraryMoveComics - | LibraryComicsMoved - | LibraryMoveComicsFailed | LibraryClearImageCache | LibraryImageCacheCleared | LibraryClearImageCacheFailed; diff --git a/comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts b/comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts index 088e19e81..2d51c8e9c 100644 --- a/comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts +++ b/comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts @@ -47,14 +47,11 @@ import { LibraryClearImageCache, LibraryClearImageCacheFailed, LibraryComicsConverting, - LibraryComicsMoved, LibraryConvertComics, LibraryConvertComicsFailed, LibraryDeleteMultipleComicsFailed, LibraryGetUpdates, LibraryImageCacheCleared, - LibraryMoveComics, - LibraryMoveComicsFailed, LibraryMultipleComicsDeleted, LibraryMultipleComicsUndeleted, LibraryUndeleteMultipleComicsFailed, @@ -81,10 +78,7 @@ describe('LibraryAdaptor', () => { const RENAME_PAGES = true; const DELETE_PAGES = false; const READING_LISTS = [READING_LIST_1, READING_LIST_2]; - const DIRECTORY = '/Users/comixedreader/Documents/comics'; - const RENAMING_RULE = - '$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE [$COVERDATE]'; - const DELETE_ORIGINAL_COMIC = false; + const DELETE_ORIGINAL_COMIC = Math.random() * 100 > 50; let adaptor: LibraryAdaptor; let store: Store; @@ -392,66 +386,6 @@ describe('LibraryAdaptor', () => { }); }); - describe('consolidating the library', () => { - beforeEach(() => { - adaptor.consolidate(true, DIRECTORY, RENAMING_RULE); - }); - - it('fires an action', () => { - expect(store.dispatch).toHaveBeenCalledWith( - new LibraryMoveComics({ - deletePhysicalFiles: true, - directory: DIRECTORY, - renamingRule: RENAMING_RULE - }) - ); - }); - - it('provides updates on consolidating', () => { - adaptor.consolidating$.subscribe(response => - expect(response).toBeTruthy() - ); - }); - - describe('success', () => { - const DELETED_COMICS = [COMICS[2]]; - - beforeEach(() => { - // preload the library - store.dispatch( - new LibraryUpdatesReceived({ - lastComicId: LAST_COMIC_ID, - mostRecentUpdate: MOST_RECENT_UPDATE, - moreUpdates: MORE_UPDATES, - processingCount: PROCESSING_COUNT, - comics: COMICS, - lastReadDates: [], - readingLists: [] - }) - ); - store.dispatch(new LibraryComicsMoved()); - }); - - it('provides updates on consolidating', () => { - adaptor.consolidating$.subscribe(response => - expect(response).toBeFalsy() - ); - }); - }); - - describe('failure', () => { - beforeEach(() => { - store.dispatch(new LibraryMoveComicsFailed()); - }); - - it('provides updates on consolidating', () => { - adaptor.consolidating$.subscribe(response => - expect(response).toBeFalsy() - ); - }); - }); - }); - describe('clearing the image cache', () => { beforeEach(() => { adaptor.clearImageCache(); diff --git a/comixed-frontend/src/app/library/adaptors/library.adaptor.ts b/comixed-frontend/src/app/library/adaptors/library.adaptor.ts index 9603fcda2..dfa056f14 100644 --- a/comixed-frontend/src/app/library/adaptors/library.adaptor.ts +++ b/comixed-frontend/src/app/library/adaptors/library.adaptor.ts @@ -34,7 +34,6 @@ import { LibraryConvertComics, LibraryDeleteMultipleComics, LibraryGetUpdates, - LibraryMoveComics, LibraryReset, LibraryStartRescan, LibraryUndeleteMultipleComics @@ -67,7 +66,6 @@ export class LibraryAdaptor { private _timeout = 60; private _maximum = 100; private _converting$ = new BehaviorSubject(false); - private _consolidating$ = new BehaviorSubject(false); private _clearingImageCache$ = new BehaviorSubject(false); private _deleting$ = new BehaviorSubject(false); @@ -170,9 +168,6 @@ export class LibraryAdaptor { if (state.convertingComics !== this._converting$.getValue()) { this._converting$.next(state.convertingComics); } - if (state.consolidating !== this._consolidating$.getValue()) { - this._consolidating$.next(state.consolidating); - } if (state.clearingImageCache !== this._clearingImageCache$.getValue()) { this._clearingImageCache$.next(state.clearingImageCache); } @@ -329,27 +324,6 @@ export class LibraryAdaptor { return this._converting$.asObservable(); } - consolidate( - deletePhysicalFiles: boolean, - targetDirectory: string, - renamingRule: string - ): void { - this.logger.debug( - `firing action to consolidate library: deletePhysicalFiles=${deletePhysicalFiles}` - ); - this.store.dispatch( - new LibraryMoveComics({ - deletePhysicalFiles: deletePhysicalFiles, - directory: targetDirectory, - renamingRule: renamingRule - }) - ); - } - - get consolidating$(): Observable { - return this._consolidating$.asObservable(); - } - getReadingList(name: string): ReadingList { return this._lists$.getValue().find(list => list.name === name); } diff --git a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html index 21145b75b..3049c0d33 100644 --- a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html +++ b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html @@ -5,11 +5,11 @@ [binary]="true" (onChange)="showDeleteFilesWarning($event)" formControlName="deletePhysicalFiles"> - +
+ class="cx-input-label">{{"library.move-comics.label.target-directory"|translate}}
+ class="cx-input-label">{{"library.move-comics.label.renaming-rule"|translate}}
-

{{"consolidate-library.text.paragraph-1"|translate}}

+

{{"library.move-comics.variables-note"|translate}}

+ +
{{"library.move-comics.variables-example"|translate}}
+ +

{{"library.move-comics.variables-example-note"|translate}}

+ + + + + + + + {{"library.move-comics.label.variable-name"|translate}} + {{"library.move-comics.label.variable-description"|translate}} + + + + + ${{variable}} + {{"library.move-comics.variable." + variable|translate}} + + + +
+
+

{{"library.move-comics.warning-text"|translate}}

diff --git a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts index ea05d2dea..2e9c28157 100644 --- a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts +++ b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts @@ -24,15 +24,10 @@ import { CheckboxModule } from 'primeng/checkbox'; import { TranslateModule } from '@ngx-translate/core'; import { LoggerModule } from '@angular-ru/logger'; import { ButtonModule } from 'primeng/button'; -import { AppState, LibraryAdaptor } from 'app/library'; +import { AppState } from 'app/library'; import { UserModule } from 'app/user/user.module'; import { Store, StoreModule } from '@ngrx/store'; import { EffectsModule } from '@ngrx/effects'; -import { - LIBRARY_FEATURE_KEY, - reducer -} from 'app/library/reducers/library.reducer'; -import { LibraryEffects } from 'app/library/effects/library.effects'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { Confirmation, ConfirmationService, MessageService } from 'primeng/api'; import { ComicsModule } from 'app/comics/comics.module'; @@ -44,6 +39,13 @@ import { MOVE_COMICS_TARGET_DIRECTORY } from 'app/user/models/preferences.constants'; import { RouterTestingModule } from '@angular/router/testing'; +import { + MOVE_COMICS_FEATURE_KEY, + reducer +} from 'app/library/reducers/move-comics.reducer'; +import { MoveComicsEffects } from 'app/library/effects/move-comics.effects'; +import { CoreModule } from 'app/core/core.module'; +import { moveComics } from 'app/library/actions/move-comics.actions'; describe('ConsolidateLibraryComponent', () => { const DIRECTORY = '/Users/comixedreader/Documents/comics'; @@ -53,13 +55,13 @@ describe('ConsolidateLibraryComponent', () => { let component: ConsolidateLibraryComponent; let fixture: ComponentFixture; let confirmationService: ConfirmationService; - let libraryAdaptor: LibraryAdaptor; let authenticationAdaptor: AuthenticationAdaptor; let store: Store; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ + CoreModule, UserModule, ComicsModule, RouterTestingModule, @@ -68,23 +70,23 @@ describe('ConsolidateLibraryComponent', () => { ReactiveFormsModule, TranslateModule, StoreModule.forRoot({}), - StoreModule.forFeature(LIBRARY_FEATURE_KEY, reducer), + StoreModule.forFeature(MOVE_COMICS_FEATURE_KEY, reducer), EffectsModule.forRoot([]), - EffectsModule.forFeature([LibraryEffects]), + EffectsModule.forFeature([MoveComicsEffects]), LoggerModule.forRoot(), CheckboxModule, ButtonModule ], declarations: [ConsolidateLibraryComponent], - providers: [LibraryAdaptor, MessageService, ConfirmationService] + providers: [MessageService, ConfirmationService] }).compileComponents(); fixture = TestBed.createComponent(ConsolidateLibraryComponent); component = fixture.componentInstance; confirmationService = TestBed.get(ConfirmationService); - libraryAdaptor = TestBed.get(LibraryAdaptor); authenticationAdaptor = TestBed.get(AuthenticationAdaptor); store = TestBed.get(Store); + spyOn(store, 'dispatch').and.callThrough(); fixture.detectChanges(); })); @@ -131,7 +133,6 @@ describe('ConsolidateLibraryComponent', () => { spyOn(confirmationService, 'confirm').and.callFake( (confirm: Confirmation) => confirm.accept() ); - spyOn(libraryAdaptor, 'consolidate'); spyOn(authenticationAdaptor, 'setPreference'); }); @@ -154,10 +155,12 @@ describe('ConsolidateLibraryComponent', () => { }); it('calls the library adaptor', () => { - expect(libraryAdaptor.consolidate).toHaveBeenCalledWith( - true, - DIRECTORY, - RENAMING_RULE + expect(store.dispatch).toHaveBeenCalledWith( + moveComics({ + directory: DIRECTORY, + renamingRule: RENAMING_RULE, + deletePhysicalFiles: true + }) ); }); @@ -202,10 +205,12 @@ describe('ConsolidateLibraryComponent', () => { }); it('calls the library adaptor', () => { - expect(libraryAdaptor.consolidate).toHaveBeenCalledWith( - false, - DIRECTORY, - RENAMING_RULE + expect(store.dispatch).toHaveBeenCalledWith( + moveComics({ + directory: DIRECTORY, + renamingRule: RENAMING_RULE, + deletePhysicalFiles: false + }) ); }); diff --git a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts index 5f41ab006..916b71991 100644 --- a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts +++ b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts @@ -19,7 +19,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { LoggerService } from '@angular-ru/logger'; -import { LibraryAdaptor } from 'app/library'; +import { AppState } from 'app/library'; import { Subscription } from 'rxjs'; import { MOVE_COMICS_DELETE_PHYSICAL_FILE, @@ -29,6 +29,12 @@ import { import { AuthenticationAdaptor } from 'app/user'; import { ConfirmationService } from 'primeng/api'; import { TranslateService } from '@ngx-translate/core'; +import { Store } from '@ngrx/store'; +import { + selectMoveComicsStateStarting, + selectMoveComicsStateSuccess +} from 'app/library/selectors/move-comics.selectors'; +import { moveComics } from 'app/library/actions/move-comics.actions'; @Component({ selector: 'app-consolidate-library', @@ -36,28 +42,38 @@ import { TranslateService } from '@ngx-translate/core'; styleUrls: ['./consolidate-library.component.scss'] }) export class ConsolidateLibraryComponent implements OnInit, OnDestroy { + const; + VARIABLES = ['PUBLISHER', 'SERIES', 'VOLUME', 'YEAR', 'ISSUE', 'COVERDATE']; consolidationForm: FormGroup; - consolidatingSubscription: Subscription; - consolidating = false; + successSubscription: Subscription; + success = false; + startingSubscription: Subscription; + starting = false; userSubscription: Subscription; user = null; constructor( private logger: LoggerService, private formBuilder: FormBuilder, - private libraryAdaptor: LibraryAdaptor, private authenticationAdaptor: AuthenticationAdaptor, private confirmationService: ConfirmationService, - private translateService: TranslateService + private translateService: TranslateService, + private store: Store ) { this.consolidationForm = this.formBuilder.group({ deletePhysicalFiles: [''], targetDirectory: ['', Validators.required], renamingRule: [''] }); - this.consolidatingSubscription = this.libraryAdaptor.consolidating$.subscribe( - consolidating => (this.consolidating = consolidating) - ); + this.startingSubscription = this.store + .select(selectMoveComicsStateStarting) + .subscribe(starting => (this.starting = starting)); + this.successSubscription = this.store + .select(selectMoveComicsStateSuccess) + .subscribe(success => (this.success = success)); + this.successSubscription = this.store + .select(selectMoveComicsStateSuccess) + .subscribe(success => (this.success = success)); this.userSubscription = this.authenticationAdaptor.user$.subscribe(() => { this.consolidationForm.controls['deletePhysicalFiles'].setValue( this.authenticationAdaptor.getPreference( @@ -70,7 +86,8 @@ export class ConsolidateLibraryComponent implements OnInit, OnDestroy { ngOnInit() {} ngOnDestroy() { - this.consolidatingSubscription.unsubscribe(); + this.startingSubscription.unsubscribe(); + this.successSubscription.unsubscribe(); } set deletePhysicalFiles(deletePhysicalFiles: boolean) { @@ -82,10 +99,10 @@ export class ConsolidateLibraryComponent implements OnInit, OnDestroy { consolidateLibrary() { this.confirmationService.confirm({ header: this.translateService.instant( - 'consolidate-library.confirm.header' + 'library.move-comics.confirmation-header' ), message: this.translateService.instant( - 'consolidate-library.confirm.message', + 'library.move-comics.confirmation-message', { deletePhysicalFiles: this.consolidationForm.controls[ 'deletePhysicalFiles' @@ -113,10 +130,12 @@ export class ConsolidateLibraryComponent implements OnInit, OnDestroy { MOVE_COMICS_RENAMING_RULE, renamingRule ); - this.libraryAdaptor.consolidate( - deletePhysicalFiles, - targetDirectory, - renamingRule + this.store.dispatch( + moveComics({ + directory: targetDirectory, + renamingRule: renamingRule, + deletePhysicalFiles: deletePhysicalFiles + }) ); } }); @@ -127,10 +146,10 @@ export class ConsolidateLibraryComponent implements OnInit, OnDestroy { this.confirmationService.confirm({ icon: 'fa fa-fw fas fa-skull-crossbones', header: this.translateService.instant( - 'consolidate-library.delete-files-warning.header' + 'library.move-comics.delete-files-warning-header' ), message: this.translateService.instant( - 'consolidate-library.delete-files-warning.message' + 'library.move-comics.delete-files-warning-message' ), reject: () => (this.deletePhysicalFiles = false) }); diff --git a/comixed-frontend/src/app/library/effects/library.effects.spec.ts b/comixed-frontend/src/app/library/effects/library.effects.spec.ts index c3fbe8b17..22a0f26b9 100644 --- a/comixed-frontend/src/app/library/effects/library.effects.spec.ts +++ b/comixed-frontend/src/app/library/effects/library.effects.spec.ts @@ -25,7 +25,6 @@ import { LibraryClearImageCache, LibraryClearImageCacheFailed, LibraryComicsConverting, - LibraryComicsMoved, LibraryConvertComics, LibraryConvertComicsFailed, LibraryDeleteMultipleComics, @@ -33,8 +32,6 @@ import { LibraryGetUpdates, LibraryGetUpdatesFailed, LibraryImageCacheCleared, - LibraryMoveComics, - LibraryMoveComicsFailed, LibraryMultipleComicsDeleted, LibraryMultipleComicsUndeleted, LibraryRescanStarted, @@ -55,8 +52,8 @@ import { MessageService } from 'primeng/api'; import { Observable, of, throwError } from 'rxjs'; import { LibraryEffects } from './library.effects'; import { ClearImageCacheResponse } from 'app/library/models/net/clear-image-cache-response'; -import objectContaining = jasmine.objectContaining; import { UndeleteMultipleComicsResponse } from 'app/library/models/net/undelete-multiple-comics-response'; +import objectContaining = jasmine.objectContaining; describe('LibraryEffects', () => { const COMICS = [COMIC_1, COMIC_3, COMIC_5]; @@ -65,9 +62,6 @@ describe('LibraryEffects', () => { const LAST_READ_DATES = [COMIC_1_LAST_READ_DATE]; const COUNT = 25; const ASCENDING = false; - const DIRECTORY = '/Users/comixedreader/Documents/comics'; - const RENAMING_RULE = - '$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE [$COVERDATE]'; let actions$: Observable; let effects: LibraryEffects; @@ -95,7 +89,6 @@ describe('LibraryEffects', () => { 'LibraryService.undeleteMultipleComics()' ), convertComics: jasmine.createSpy('LibraryService.convertComics()'), - consolidate: jasmine.createSpy('LibraryService.consolidate()'), clearImageCache: jasmine.createSpy( 'LibraryService.clearImageCache()' ) @@ -418,64 +411,6 @@ describe('LibraryEffects', () => { }); }); - describe('consolidating the library', () => { - it('fires an action on success', () => { - const serviceResponse = COMICS; - const action = new LibraryMoveComics({ - deletePhysicalFiles: true, - directory: DIRECTORY, - renamingRule: RENAMING_RULE - }); - const outcome = new LibraryComicsMoved(); - - actions$ = hot('-a', { a: action }); - libraryService.consolidate.and.returnValue(of(serviceResponse)); - - const expected = hot('-b', { b: outcome }); - expect(effects.consolidate$).toBeObservable(expected); - expect(messageService.add).toHaveBeenCalledWith( - objectContaining({ severity: 'info' }) - ); - }); - - it('fires an action on service failure', () => { - const serviceResponse = new HttpErrorResponse({}); - const action = new LibraryMoveComics({ - deletePhysicalFiles: true, - directory: DIRECTORY, - renamingRule: RENAMING_RULE - }); - const outcome = new LibraryMoveComicsFailed(); - - actions$ = hot('-a', { a: action }); - libraryService.consolidate.and.returnValue(throwError(serviceResponse)); - - const expected = hot('-b', { b: outcome }); - expect(effects.consolidate$).toBeObservable(expected); - expect(messageService.add).toHaveBeenCalledWith( - objectContaining({ severity: 'error' }) - ); - }); - - it('fires an action on general failure', () => { - const action = new LibraryMoveComics({ - deletePhysicalFiles: true, - directory: DIRECTORY, - renamingRule: RENAMING_RULE - }); - const outcome = new LibraryMoveComicsFailed(); - - actions$ = hot('-a', { a: action }); - libraryService.consolidate.and.throwError('expected'); - - const expected = hot('-(b|)', { b: outcome }); - expect(effects.consolidate$).toBeObservable(expected); - expect(messageService.add).toHaveBeenCalledWith( - objectContaining({ severity: 'error' }) - ); - }); - }); - describe('consolidating the library', () => { it('fires an action on successful clearing', () => { const serviceResponse = { success: true } as ClearImageCacheResponse; diff --git a/comixed-frontend/src/app/library/effects/library.effects.ts b/comixed-frontend/src/app/library/effects/library.effects.ts index 922e7b112..7484b55ad 100644 --- a/comixed-frontend/src/app/library/effects/library.effects.ts +++ b/comixed-frontend/src/app/library/effects/library.effects.ts @@ -32,7 +32,6 @@ import { LibraryActionTypes, LibraryClearImageCacheFailed, LibraryComicsConverting, - LibraryComicsMoved, LibraryConvertComics, LibraryConvertComicsFailed, LibraryDeleteMultipleComics, @@ -40,8 +39,6 @@ import { LibraryGetUpdates, LibraryGetUpdatesFailed, LibraryImageCacheCleared, - LibraryMoveComics, - LibraryMoveComicsFailed, LibraryMultipleComicsDeleted, LibraryMultipleComicsUndeleted, LibraryRescanStarted, @@ -50,7 +47,6 @@ import { LibraryUndeleteMultipleComicsFailed, LibraryUpdatesReceived } from '../actions/library.actions'; -import { Comic } from 'app/comics'; import { ClearImageCacheResponse } from 'app/library/models/net/clear-image-cache-response'; @Injectable() @@ -310,53 +306,6 @@ export class LibraryEffects { }) ); - @Effect() - consolidate$: Observable = this.actions$.pipe( - ofType(LibraryActionTypes.MoveComics), - tap(action => this.logger.debug('effect: consolidate library:', action)), - map((action: LibraryMoveComics) => action.payload), - switchMap(action => - this.libraryService - .consolidate( - action.deletePhysicalFiles, - action.directory, - action.renamingRule - ) - .pipe( - tap(response => this.logger.debug('received response:', response)), - tap(() => - this.messageService.add({ - severity: 'info', - detail: this.translateService.instant( - 'library-effects.consolidate.success.detail' - ) - }) - ), - map((response: Comic[]) => new LibraryComicsMoved()), - catchError(error => { - this.logger.error('service failure conslidating library:', error); - this.messageService.add({ - severity: 'error', - detail: this.translateService.instant( - 'library-effects.consolidate.error.detail' - ) - }); - return of(new LibraryMoveComicsFailed()); - }) - ) - ), - catchError(error => { - this.logger.error('general failure conslidating library:', error); - this.messageService.add({ - severity: 'error', - detail: this.translateService.instant( - 'general-message.error.general-service-failure' - ) - }); - return of(new LibraryMoveComicsFailed()); - }) - ); - @Effect() clearImageCache$: Observable = this.actions$.pipe( ofType(LibraryActionTypes.ClearImageCache), diff --git a/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.html b/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.html index 7391cb765..4ab8746eb 100644 --- a/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.html +++ b/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.html @@ -31,7 +31,7 @@
- +
diff --git a/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.spec.ts b/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.spec.ts index 2ed28ae81..f2ba5f6c8 100644 --- a/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.spec.ts +++ b/comixed-frontend/src/app/library/pages/library-admin-page/library-admin-page.component.spec.ts @@ -39,6 +39,11 @@ import { CheckboxModule } from 'primeng/checkbox'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { UserModule } from 'app/user/user.module'; import { ComicsModule } from 'app/comics/comics.module'; +import { + MOVE_COMICS_FEATURE_KEY, + reducer +} from 'app/library/reducers/move-comics.reducer'; +import { MoveComicsEffects } from 'app/library/effects/move-comics.effects'; describe('LibraryAdminPageComponent', () => { let component: LibraryAdminPageComponent; @@ -61,7 +66,9 @@ describe('LibraryAdminPageComponent', () => { TranslateModule.forRoot(), LoggerModule.forRoot(), StoreModule.forRoot({}), + StoreModule.forFeature(MOVE_COMICS_FEATURE_KEY, reducer), EffectsModule.forRoot([]), + EffectsModule.forFeature([MoveComicsEffects]), FileSaverModule, ButtonModule, PanelModule, diff --git a/comixed-frontend/src/app/library/reducers/library.reducer.spec.ts b/comixed-frontend/src/app/library/reducers/library.reducer.spec.ts index 1f1b58d60..b672c9e58 100644 --- a/comixed-frontend/src/app/library/reducers/library.reducer.spec.ts +++ b/comixed-frontend/src/app/library/reducers/library.reducer.spec.ts @@ -27,7 +27,6 @@ import { LibraryClearImageCache, LibraryClearImageCacheFailed, LibraryComicsConverting, - LibraryComicsMoved, LibraryConvertComics, LibraryConvertComicsFailed, LibraryDeleteMultipleComics, @@ -35,8 +34,6 @@ import { LibraryGetUpdates, LibraryGetUpdatesFailed, LibraryImageCacheCleared, - LibraryMoveComics, - LibraryMoveComicsFailed, LibraryMultipleComicsDeleted, LibraryMultipleComicsUndeleted, LibraryRescanStarted, @@ -66,9 +63,6 @@ describe('Library Reducer', () => { const ASCENDING = true; const COMIC_COUNT = 2372; const LATEST_UPDATED_DATE = new Date(); - const DIRECTORY = '/Users/comixedreader/Documents/comics'; - const RENAMING_RULE = - '$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE [$COVERDATE]'; const COMIC_IDS = [1, 2, 3, 4]; let state: LibraryState; @@ -126,10 +120,6 @@ describe('Library Reducer', () => { expect(state.convertingComics).toBeFalsy(); }); - it('clears the consolidating library flag', () => { - expect(state.consolidating).toBeFalsy(); - }); - it('has no reading lists', () => { expect(state.readingLists).toEqual([]); }); @@ -412,53 +402,6 @@ describe('Library Reducer', () => { }); }); - describe('when consolidating the library', () => { - beforeEach(() => { - state = reducer( - { ...state, consolidating: false }, - new LibraryMoveComics({ - deletePhysicalFiles: true, - directory: DIRECTORY, - renamingRule: RENAMING_RULE - }) - ); - }); - - it('sets the consolidating library flag', () => { - expect(state.consolidating).toBeTruthy(); - }); - }); - - describe('when the library is consolidated', () => { - beforeEach(() => { - state = reducer( - { - ...state, - consolidating: true, - comics: COMICS - }, - new LibraryComicsMoved() - ); - }); - - it('clears the consolidating library flag', () => { - expect(state.consolidating).toBeFalsy(); - }); - }); - - describe('when consolidation fails', () => { - beforeEach(() => { - state = reducer( - { ...state, consolidating: true }, - new LibraryMoveComicsFailed() - ); - }); - - it('clears the consolidating library flag', () => { - expect(state.consolidating).toBeFalsy(); - }); - }); - describe('clearing the image cache', () => { beforeEach(() => { state = reducer( diff --git a/comixed-frontend/src/app/library/reducers/library.reducer.ts b/comixed-frontend/src/app/library/reducers/library.reducer.ts index 67bb1d384..1a5b32f16 100644 --- a/comixed-frontend/src/app/library/reducers/library.reducer.ts +++ b/comixed-frontend/src/app/library/reducers/library.reducer.ts @@ -37,7 +37,6 @@ export interface LibraryState { startingRescan: boolean; deletingComics: boolean; convertingComics: boolean; - consolidating: boolean; readingLists: ReadingList[]; clearingImageCache: boolean; } @@ -55,7 +54,6 @@ export const initialState: LibraryState = { startingRescan: false, deletingComics: false, convertingComics: false, - consolidating: false, readingLists: [], clearingImageCache: false }; @@ -134,16 +132,6 @@ export function reducer( case LibraryActionTypes.ConvertComicsFailed: return { ...state, convertingComics: false }; - case LibraryActionTypes.MoveComics: - return { ...state, consolidating: true }; - - case LibraryActionTypes.ComicsMoved: { - return { ...state, consolidating: false }; - } - - case LibraryActionTypes.MoveComicsFailed: - return { ...state, consolidating: false }; - case LibraryActionTypes.ClearImageCache: return { ...state, clearingImageCache: true }; diff --git a/comixed-frontend/src/assets/i18n/en/library.json b/comixed-frontend/src/assets/i18n/en/library.json index f60b71d6e..28dbe4191 100644 --- a/comixed-frontend/src/assets/i18n/en/library.json +++ b/comixed-frontend/src/assets/i18n/en/library.json @@ -1,10 +1,36 @@ { "library": { "move-comics": { + "title": "Organize Library", + "label": { + "delete-physical-files": "Delete physical files (WARNING: be sure to backup your library first)", + "target-directory": "The new parent directory for the library", + "renaming-rule": "The file renaming rule (see notes below)", + "variable-name": "Variable Name", + "variable-description": "Description" + }, + "button": { + "start": "Organize Library" + }, + "warning-text": "Organizing your library cannot be stopped once started.", "effects": { "success-detail": "Library consolidation has started...", "error-detail": "Failed to start library consolidation..." - } + }, + "variables-note": "The following list shows the variables that can used in the renaming rules.", + "variables-example": "$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE ($COVERDATE)", + "variables-example-note": "This example organizes a library by publisher, series, volume and then a detailed filename. Note you do NOT need to specify the extension: that is added automatically.", + "variable": { + "PUBLISHER": "The name of the publisher of the comic", + "SERIES": "The name of the series of the comic", + "VOLUME": "The first year this volume of the comic was published", + "ISSUE": "The issue number for this isue", + "COVERDATE": "The coverdate for this issue" + }, + "delete-files-warning-header": "Delete Physical Files", + "delete-files-warning-message": "Deleting physical files cannot be undone. Are you SURE you want to do this?", + "confirmation-header": "Organize Library", + "confirmation-message": "Are you sure you want to {deletePhysicalFiles, select, true{delete comic files marked for deletion and} other{}} organizing the library?" } }, "library-effects": { @@ -80,14 +106,6 @@ "detail": "Failed to convert comics." } }, - "consolidate": { - "success": { - "detail": "Library successfully consolidated." - }, - "error": { - "detail": "There was an error consolidating the library." - } - }, "clear-image-cache": { "success": { "detail": "Image cache {success, select, true{successfully} other{failed to be}} cleared..." @@ -428,27 +446,6 @@ } } }, - "consolidate-library": { - "label": { - "delete-physical-files": "Delete The Physical Comic Files.", - "target-directory": "Target directory", - "renaming-rule": "The renaming rule" - }, - "button": { - "start": "Start Consolidation" - }, - "delete-files-warning": { - "header": "Delete Files Warning", - "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" - }, - "confirm": { - "header": "Consolidate Library", - "message": "Are you sure you want to consolidate the library and {deletePhysicalFiles, select, true{delete} other{not delete}} the comic files?" - }, - "text": { - "paragraph-1": "Consolidating the library involves the following actions: deleting comic files marked for deletion." - } - }, "library-admin-page": { "title": "ComiXed: Library Administration", "rescan": { @@ -468,9 +465,6 @@ "buttons": { "export-library": "Export Library" } - }, - "consolidate": { - "header": "Consolidate Library Files" } }, "account-preferences": { diff --git a/comixed-frontend/src/assets/i18n/es/library.json b/comixed-frontend/src/assets/i18n/es/library.json index 2461ed597..71afe0cfb 100644 --- a/comixed-frontend/src/assets/i18n/es/library.json +++ b/comixed-frontend/src/assets/i18n/es/library.json @@ -1,10 +1,36 @@ { "library": { "move-comics": { + "title": "Organize Library", + "label": { + "delete-physical-files": "Delete physical files (WARNING: be sure to backup your library first)", + "target-directory": "The new parent directory for the library", + "renaming-rule": "The file renaming rule (see notes below)", + "variable-name": "Variable Name", + "variable-description": "Description" + }, + "button": { + "start": "Organize Library" + }, + "warning-text": "Organizing your library cannot be stopped once started.", "effects": { "success-detail": "Library consolidation has started...", "error-detail": "Failed to start library consolidation..." - } + }, + "variables-note": "The following list shows the variables that can used in the renaming rules.", + "variables-example": "$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE ($COVERDATE)", + "variables-example-note": "This example organizes a library by publisher, series, volume and then a detailed filename. Note you do NOT need to specify the extension: that is added automatically.", + "variable": { + "PUBLISHER": "The name of the publisher of the comic", + "SERIES": "The name of the series of the comic", + "VOLUME": "The first year this volume of the comic was published", + "ISSUE": "The issue number for this isue", + "COVERDATE": "The coverdate for this issue" + }, + "delete-files-warning-header": "Delete Physical Files", + "delete-files-warning-message": "Deleting physical files cannot be undone. Are you SURE you want to do this?", + "confirmation-header": "Organize Library", + "confirmation-message": "Are you sure you want to {deletePhysicalFiles, select, true{delete comic files marked for deletion and} other{}} organizing the library?" } }, "library-effects": { @@ -80,14 +106,6 @@ "detail": "Error al convertir los cómics" } }, - "consolidate": { - "success": { - "detail": "Biblioteca consolidada correctamente." - }, - "error": { - "detail": "Error consolidando la biblioteca." - } - }, "clear-image-cache": { "success": { "detail": "Image cache {success, select, true{successfully} other{failed to be}} cleared..." @@ -428,27 +446,6 @@ } } }, - "consolidate-library": { - "label": { - "delete-physical-files": "Borrar los archivos físicos de cómics.", - "target-directory": "Target directory", - "renaming-rule": "The renaming rule" - }, - "button": { - "start": "Comenzar la consolidación" - }, - "delete-files-warning": { - "header": "Delete Files Warning", - "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" - }, - "confirm": { - "header": "Consolidar la biblioteca", - "message": "¿Seguro que quieres consolidar la biblitoteca y {deletePhysicalFiles, select, true{borrar} other{no borrar}} los archivos físicos de cómics?" - }, - "text": { - "paragraph-1": "Consolidar la biblioteca conlleva la siguiente acción: borrar los archivos físicos de los cómics marcados para eliminación." - } - }, "library-admin-page": { "title": "ComiXed: Administración de la biblioteca", "rescan": { @@ -468,9 +465,6 @@ "buttons": { "export-library": "Exportar biblioteca" } - }, - "consolidate": { - "header": "Consolidar archivos de la biblioteca" } }, "account-preferences": { diff --git a/comixed-frontend/src/assets/i18n/fr/library.json b/comixed-frontend/src/assets/i18n/fr/library.json index 80b21c8d7..42324a574 100644 --- a/comixed-frontend/src/assets/i18n/fr/library.json +++ b/comixed-frontend/src/assets/i18n/fr/library.json @@ -1,10 +1,36 @@ { "library": { "move-comics": { + "title": "Organize Library", + "label": { + "delete-physical-files": "Delete physical files (WARNING: be sure to backup your library first)", + "target-directory": "The new parent directory for the library", + "renaming-rule": "The file renaming rule (see notes below)", + "variable-name": "Variable Name", + "variable-description": "Description" + }, + "button": { + "start": "Organize Library" + }, + "warning-text": "Organizing your library cannot be stopped once started.", "effects": { "success-detail": "Library consolidation has started...", "error-detail": "Failed to start library consolidation..." - } + }, + "variables-note": "The following list shows the variables that can used in the renaming rules.", + "variables-example": "$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE ($COVERDATE)", + "variables-example-note": "This example organizes a library by publisher, series, volume and then a detailed filename. Note you do NOT need to specify the extension: that is added automatically.", + "variable": { + "PUBLISHER": "The name of the publisher of the comic", + "SERIES": "The name of the series of the comic", + "VOLUME": "The first year this volume of the comic was published", + "ISSUE": "The issue number for this isue", + "COVERDATE": "The coverdate for this issue" + }, + "delete-files-warning-header": "Delete Physical Files", + "delete-files-warning-message": "Deleting physical files cannot be undone. Are you SURE you want to do this?", + "confirmation-header": "Organize Library", + "confirmation-message": "Are you sure you want to {deletePhysicalFiles, select, true{delete comic files marked for deletion and} other{}} organizing the library?" } }, "library-effects": { @@ -80,14 +106,6 @@ "detail": "Échec de la conversion des bandes dessinées." } }, - "consolidate": { - "success": { - "detail": "Consolidation réussie de la bibliothèque." - }, - "error": { - "detail": "Il y a eu une erreur durant la consolidation de la bibliothèque." - } - }, "clear-image-cache": { "success": { "detail": "Le cache d'images {success, select, true{a été vidé avec succès} other{n'a pas pu être vidé}}..." @@ -428,27 +446,6 @@ } } }, - "consolidate-library": { - "label": { - "delete-physical-files": "Supprimer les fichiers physiques de la bande dessinée.", - "target-directory": "Répertoire cible", - "renaming-rule": "Règle de renommage" - }, - "button": { - "start": "Commencer la consolidation" - }, - "delete-files-warning": { - "header": "Delete Files Warning", - "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" - }, - "confirm": { - "header": "Consolider la bibliothèque", - "message": "Êtes-vous sûr de vouloir consolider la bibliothèque et {deletePhysicalFiles, select, true{supprimer} other{ne pas supprimer}} les fichiers de bande dessinée?" - }, - "text": { - "paragraph-1": "La consolidation de la bibliothèque implique l'action suivante : suppression des fichiers de bandes dessinées marqués pour suppression." - } - }, "library-admin-page": { "title": "ComiXed: Administration de la bibliothèque", "rescan": { @@ -468,9 +465,6 @@ "buttons": { "export-library": "Exporter la bibliothèque" } - }, - "consolidate": { - "header": "Consolider les fichiers de la bibliothèque" } }, "account-preferences": { diff --git a/comixed-frontend/src/assets/i18n/pt/library.json b/comixed-frontend/src/assets/i18n/pt/library.json index f60b71d6e..28dbe4191 100644 --- a/comixed-frontend/src/assets/i18n/pt/library.json +++ b/comixed-frontend/src/assets/i18n/pt/library.json @@ -1,10 +1,36 @@ { "library": { "move-comics": { + "title": "Organize Library", + "label": { + "delete-physical-files": "Delete physical files (WARNING: be sure to backup your library first)", + "target-directory": "The new parent directory for the library", + "renaming-rule": "The file renaming rule (see notes below)", + "variable-name": "Variable Name", + "variable-description": "Description" + }, + "button": { + "start": "Organize Library" + }, + "warning-text": "Organizing your library cannot be stopped once started.", "effects": { "success-detail": "Library consolidation has started...", "error-detail": "Failed to start library consolidation..." - } + }, + "variables-note": "The following list shows the variables that can used in the renaming rules.", + "variables-example": "$PUBLISHER/$SERIES/$VOLUME/$SERIES v$VOLUME #$ISSUE ($COVERDATE)", + "variables-example-note": "This example organizes a library by publisher, series, volume and then a detailed filename. Note you do NOT need to specify the extension: that is added automatically.", + "variable": { + "PUBLISHER": "The name of the publisher of the comic", + "SERIES": "The name of the series of the comic", + "VOLUME": "The first year this volume of the comic was published", + "ISSUE": "The issue number for this isue", + "COVERDATE": "The coverdate for this issue" + }, + "delete-files-warning-header": "Delete Physical Files", + "delete-files-warning-message": "Deleting physical files cannot be undone. Are you SURE you want to do this?", + "confirmation-header": "Organize Library", + "confirmation-message": "Are you sure you want to {deletePhysicalFiles, select, true{delete comic files marked for deletion and} other{}} organizing the library?" } }, "library-effects": { @@ -80,14 +106,6 @@ "detail": "Failed to convert comics." } }, - "consolidate": { - "success": { - "detail": "Library successfully consolidated." - }, - "error": { - "detail": "There was an error consolidating the library." - } - }, "clear-image-cache": { "success": { "detail": "Image cache {success, select, true{successfully} other{failed to be}} cleared..." @@ -428,27 +446,6 @@ } } }, - "consolidate-library": { - "label": { - "delete-physical-files": "Delete The Physical Comic Files.", - "target-directory": "Target directory", - "renaming-rule": "The renaming rule" - }, - "button": { - "start": "Start Consolidation" - }, - "delete-files-warning": { - "header": "Delete Files Warning", - "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" - }, - "confirm": { - "header": "Consolidate Library", - "message": "Are you sure you want to consolidate the library and {deletePhysicalFiles, select, true{delete} other{not delete}} the comic files?" - }, - "text": { - "paragraph-1": "Consolidating the library involves the following actions: deleting comic files marked for deletion." - } - }, "library-admin-page": { "title": "ComiXed: Library Administration", "rescan": { @@ -468,9 +465,6 @@ "buttons": { "export-library": "Export Library" } - }, - "consolidate": { - "header": "Consolidate Library Files" } }, "account-preferences": {