Skip to content

Commit

Permalink
Changed consolidating to moving the library [#21]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce authored and BRUCELLA2 committed Jul 1, 2020
1 parent 90d3590 commit 070eadb
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 106 deletions.
34 changes: 20 additions & 14 deletions comixed-frontend/src/app/library/actions/library.actions.ts
Expand Up @@ -35,9 +35,9 @@ 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',
Consolidate = '[LIBRARY] Consolidate the library',
Consolidated = '[LIBRARY] Library is consolidated',
ConsolidateFailed = '[LIBRARY] Failed to consolidate library',
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'
Expand Down Expand Up @@ -145,20 +145,26 @@ export class LibraryConvertComicsFailed implements Action {
constructor() {}
}

export class LibraryConsolidate implements Action {
readonly type = LibraryActionTypes.Consolidate;
export class LibraryMoveComics implements Action {
readonly type = LibraryActionTypes.MoveComics;

constructor(public payload: { deletePhysicalFiles: boolean }) {}
constructor(
public payload: {
deletePhysicalFiles: boolean;
directory: string;
renamingRule: string;
}
) {}
}

export class LibraryConsolidated implements Action {
readonly type = LibraryActionTypes.Consolidated;
export class LibraryComicsMoved implements Action {
readonly type = LibraryActionTypes.ComicsMoved;

constructor(public payload: { deletedComics: Comic[] }) {}
constructor() {}
}

export class LibraryConsolidateFailed implements Action {
readonly type = LibraryActionTypes.ConsolidateFailed;
export class LibraryMoveComicsFailed implements Action {
readonly type = LibraryActionTypes.MoveComicsFailed;

constructor() {}
}
Expand Down Expand Up @@ -195,9 +201,9 @@ export type LibraryActions =
| LibraryConvertComics
| LibraryComicsConverting
| LibraryConvertComicsFailed
| LibraryConsolidate
| LibraryConsolidated
| LibraryConsolidateFailed
| LibraryMoveComics
| LibraryComicsMoved
| LibraryMoveComicsFailed
| LibraryClearImageCache
| LibraryImageCacheCleared
| LibraryClearImageCacheFailed;
31 changes: 14 additions & 17 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts
Expand Up @@ -47,13 +47,13 @@ import {
LibraryClearImageCache,
LibraryClearImageCacheFailed,
LibraryComicsConverting,
LibraryConsolidate,
LibraryConsolidated,
LibraryConsolidateFailed,
LibraryComicsMoved,
LibraryConvertComics,
LibraryConvertComicsFailed,
LibraryGetUpdates,
LibraryImageCacheCleared,
LibraryMoveComics,
LibraryMoveComicsFailed,
LibraryUpdatesReceived
} from '../actions/library.actions';
import { LibraryAdaptor } from './library.adaptor';
Expand All @@ -76,6 +76,9 @@ describe('LibraryAdaptor', () => {
const ARCHIVE_TYPE = 'CBZ';
const RENAME_PAGES = true;
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]';

let adaptor: LibraryAdaptor;
let store: Store<AppState>;
Expand Down Expand Up @@ -312,12 +315,16 @@ describe('LibraryAdaptor', () => {

describe('consolidating the library', () => {
beforeEach(() => {
adaptor.consolidate(true);
adaptor.consolidate(true, DIRECTORY, RENAMING_RULE);
});

it('fires an action', () => {
expect(store.dispatch).toHaveBeenCalledWith(
new LibraryConsolidate({ deletePhysicalFiles: true })
new LibraryMoveComics({
deletePhysicalFiles: true,
directory: DIRECTORY,
renamingRule: RENAMING_RULE
})
);
});

Expand All @@ -343,29 +350,19 @@ describe('LibraryAdaptor', () => {
readingLists: []
})
);
store.dispatch(
new LibraryConsolidated({ deletedComics: DELETED_COMICS })
);
store.dispatch(new LibraryComicsMoved());
});

it('provides updates on consolidating', () => {
adaptor.consolidating$.subscribe(response =>
expect(response).toBeFalsy()
);
});

it('provides updates on comics', () => {
DELETED_COMICS.forEach(comic => {
adaptor.comic$.subscribe(comics =>
expect(comics).not.toContain(comic)
);
});
});
});

describe('failure', () => {
beforeEach(() => {
store.dispatch(new LibraryConsolidateFailed());
store.dispatch(new LibraryMoveComicsFailed());
});

it('provides updates on consolidating', () => {
Expand Down
14 changes: 11 additions & 3 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.ts
Expand Up @@ -31,10 +31,10 @@ import { extractField } from 'app/library/library.functions';
import { LastReadDate } from 'app/library/models/last-read-date';
import {
LibraryClearImageCache,
LibraryConsolidate,
LibraryConvertComics,
LibraryDeleteMultipleComics,
LibraryGetUpdates,
LibraryMoveComics,
LibraryReset,
LibraryStartRescan
} from 'app/library/actions/library.actions';
Expand Down Expand Up @@ -300,12 +300,20 @@ export class LibraryAdaptor {
return this._converting$.asObservable();
}

consolidate(deletePhysicalFiles: boolean): void {
consolidate(
deletePhysicalFiles: boolean,
targetDirectory: string,
renamingRule: string
): void {
this.logger.debug(
`firing action to consolidate library: deletePhysicalFiles=${deletePhysicalFiles}`
);
this.store.dispatch(
new LibraryConsolidate({ deletePhysicalFiles: deletePhysicalFiles })
new LibraryMoveComics({
deletePhysicalFiles: deletePhysicalFiles,
directory: targetDirectory,
renamingRule: renamingRule
})
);
}

Expand Down
33 changes: 24 additions & 9 deletions comixed-frontend/src/app/library/effects/library.effects.spec.ts
Expand Up @@ -25,16 +25,16 @@ import {
LibraryClearImageCache,
LibraryClearImageCacheFailed,
LibraryComicsConverting,
LibraryConsolidate,
LibraryConsolidated,
LibraryConsolidateFailed,
LibraryComicsMoved,
LibraryConvertComics,
LibraryConvertComicsFailed,
LibraryDeleteMultipleComics,
LibraryDeleteMultipleComicsFailed,
LibraryGetUpdates,
LibraryGetUpdatesFailed,
LibraryImageCacheCleared,
LibraryMoveComics,
LibraryMoveComicsFailed,
LibraryMultipleComicsDeleted,
LibraryRescanStarted,
LibraryStartRescan,
Expand All @@ -61,6 +61,9 @@ 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<any>;
let effects: LibraryEffects;
Expand Down Expand Up @@ -347,8 +350,12 @@ describe('LibraryEffects', () => {
describe('consolidating the library', () => {
it('fires an action on success', () => {
const serviceResponse = COMICS;
const action = new LibraryConsolidate({ deletePhysicalFiles: true });
const outcome = new LibraryConsolidated({ deletedComics: 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));
Expand All @@ -362,8 +369,12 @@ describe('LibraryEffects', () => {

it('fires an action on service failure', () => {
const serviceResponse = new HttpErrorResponse({});
const action = new LibraryConsolidate({ deletePhysicalFiles: true });
const outcome = new LibraryConsolidateFailed();
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));
Expand All @@ -376,8 +387,12 @@ describe('LibraryEffects', () => {
});

it('fires an action on general failure', () => {
const action = new LibraryConsolidate({ deletePhysicalFiles: true });
const outcome = new LibraryConsolidateFailed();
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');
Expand Down
63 changes: 33 additions & 30 deletions comixed-frontend/src/app/library/effects/library.effects.ts
Expand Up @@ -32,16 +32,16 @@ import {
LibraryActionTypes,
LibraryClearImageCacheFailed,
LibraryComicsConverting,
LibraryConsolidate,
LibraryConsolidated,
LibraryConsolidateFailed,
LibraryComicsMoved,
LibraryConvertComics,
LibraryConvertComicsFailed,
LibraryDeleteMultipleComics,
LibraryDeleteMultipleComicsFailed,
LibraryGetUpdates,
LibraryGetUpdatesFailed,
LibraryImageCacheCleared,
LibraryMoveComics,
LibraryMoveComicsFailed,
LibraryMultipleComicsDeleted,
LibraryRescanStarted,
LibraryStartRescanFailed,
Expand Down Expand Up @@ -257,35 +257,38 @@ export class LibraryEffects {

@Effect()
consolidate$: Observable<Action> = this.actions$.pipe(
ofType(LibraryActionTypes.Consolidate),
ofType(LibraryActionTypes.MoveComics),
tap(action => this.logger.debug('effect: consolidate library:', action)),
map((action: LibraryConsolidate) => action.payload),
map((action: LibraryMoveComics) => action.payload),
switchMap(action =>
this.libraryService.consolidate(action.deletePhysicalFiles).pipe(
tap(response => this.logger.debug('received response:', response)),
tap(() =>
this.messageService.add({
severity: 'info',
detail: this.translateService.instant(
'library-effects.consolidate.success.detail'
)
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());
})
),
map(
(response: Comic[]) =>
new LibraryConsolidated({ deletedComics: response })
),
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 LibraryConsolidateFailed());
})
)
)
),
catchError(error => {
this.logger.error('general failure conslidating library:', error);
Expand All @@ -295,7 +298,7 @@ export class LibraryEffects {
'general-message.error.general-service-failure'
)
});
return of(new LibraryConsolidateFailed());
return of(new LibraryMoveComicsFailed());
})
);

Expand Down
2 changes: 1 addition & 1 deletion comixed-frontend/src/app/library/library.constants.ts
Expand Up @@ -28,7 +28,7 @@ export const SET_DELETED_STATE_URL = `${API_ROOT_URL}/pages/hashes/deleted`;
export const START_RESCAN_URL = `${COMIXED_API_ROOT}/comics/rescan`;
export const DELETE_MULTIPLE_COMICS_URL = `${COMIXED_API_ROOT}/comics/multiple/delete`;
export const CONVERT_COMICS_URL = `${COMIXED_API_ROOT}/library/convert`;
export const CONSOLIDATE_LIBRARY_URL = `${COMIXED_API_ROOT}/library/consolidate`;
export const CONSOLIDATE_LIBRARY_URL = `${COMIXED_API_ROOT}/library/move`;
export const CLEAR_IMAGE_CACHE_URL = `${COMIXED_API_ROOT}/library/cache/images`;

export const GET_COLLECTION_ENTRIES_URL = `${API_ROOT_URL}/collections/\${type}`;
Expand Down
Expand Up @@ -18,4 +18,6 @@

export interface ConsolidateLibraryRequest {
deletePhysicalFiles: boolean;
targetDirectory: string;
renamingRule: string;
}

0 comments on commit 070eadb

Please sign in to comment.