Skip to content

Commit

Permalink
Changed the app to use the new feature to move comics [#378]
Browse files Browse the repository at this point in the history
 * Refactored the MoveComics component.
 * Removed the old state wiring code.
 * Changed i18n entries to be feature-specific.
  • Loading branch information
mcpierce committed Aug 28, 2020
1 parent 5c89e1b commit 012c1bd
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 484 deletions.
30 changes: 0 additions & 30 deletions comixed-frontend/src/app/library/actions/library.actions.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -227,9 +200,6 @@ export type LibraryActions =
| LibraryConvertComics
| LibraryComicsConverting
| LibraryConvertComicsFailed
| LibraryMoveComics
| LibraryComicsMoved
| LibraryMoveComicsFailed
| LibraryClearImageCache
| LibraryImageCacheCleared
| LibraryClearImageCacheFailed;
Expand Up @@ -47,14 +47,11 @@ import {
LibraryClearImageCache,
LibraryClearImageCacheFailed,
LibraryComicsConverting,
LibraryComicsMoved,
LibraryConvertComics,
LibraryConvertComicsFailed,
LibraryDeleteMultipleComicsFailed,
LibraryGetUpdates,
LibraryImageCacheCleared,
LibraryMoveComics,
LibraryMoveComicsFailed,
LibraryMultipleComicsDeleted,
LibraryMultipleComicsUndeleted,
LibraryUndeleteMultipleComicsFailed,
Expand All @@ -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<AppState>;
Expand Down Expand Up @@ -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();
Expand Down
26 changes: 0 additions & 26 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.ts
Expand Up @@ -34,7 +34,6 @@ import {
LibraryConvertComics,
LibraryDeleteMultipleComics,
LibraryGetUpdates,
LibraryMoveComics,
LibraryReset,
LibraryStartRescan,
LibraryUndeleteMultipleComics
Expand Down Expand Up @@ -67,7 +66,6 @@ export class LibraryAdaptor {
private _timeout = 60;
private _maximum = 100;
private _converting$ = new BehaviorSubject<boolean>(false);
private _consolidating$ = new BehaviorSubject<boolean>(false);
private _clearingImageCache$ = new BehaviorSubject<boolean>(false);
private _deleting$ = new BehaviorSubject<boolean>(false);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<boolean> {
return this._consolidating$.asObservable();
}

getReadingList(name: string): ReadingList {
return this._lists$.getValue().find(list => list.name === name);
}
Expand Down
Expand Up @@ -5,11 +5,11 @@
[binary]="true"
(onChange)="showDeleteFilesWarning($event)"
formControlName="deletePhysicalFiles"></p-checkbox>
<label for="delete-physical-files">{{"consolidate-library.label.delete-physical-files"|translate}}</label>
<label for="delete-physical-files">{{"library.move-comics.label.delete-physical-files"|translate}}</label>
</div>
<div class="ui-g-12">
<label for="cx-target-directory"
class="cx-input-label">{{"consolidate-library.label.target-directory"|translate}}</label>
class="cx-input-label">{{"library.move-comics.label.target-directory"|translate}}</label>
</div>
<div class="ui-g-12">
<input pInputText
Expand All @@ -19,7 +19,7 @@
</div>
<div class="ui-g-12">
<label for="cx-renaming-rule"
class="cx-input-label">{{"consolidate-library.label.renaming-rule"|translate}}</label>
class="cx-input-label">{{"library.move-comics.label.renaming-rule"|translate}}</label>
</div>
<div class="ui-g-12">
<input pInputText
Expand All @@ -28,13 +28,39 @@
formControlName="renamingRule">
</div>
<div class="ui-g-12">
<p>{{"consolidate-library.text.paragraph-1"|translate}}</p>
<p>{{"library.move-comics.variables-note"|translate}}</p>

<pre>{{"library.move-comics.variables-example"|translate}}</pre>

<p>{{"library.move-comics.variables-example-note"|translate}}</p>
<p-table [value]="VARIABLES">
<ng-template pTemplate="colgroup">
<col class="cx-table-column-large"/>
<col/>
</ng-template>
<ng-template pTemplate="header">
<tr>
<th id="variable-name">{{"library.move-comics.label.variable-name"|translate}}</th>
<th id="variable-description">{{"library.move-comics.label.variable-description"|translate}}</th>
</tr>
</ng-template>
<ng-template pTemplate="body"
let-variable>
<tr>
<td [pTooltip]="'library.move-comics.variable.' + variable|translate">${{variable}}</td>
<td class="cx-no-wrap-text">{{"library.move-comics.variable." + variable|translate}}</td>
</tr>
</ng-template>
</p-table>
</div>
<div class="ui-g-12">
<p>{{"library.move-comics.warning-text"|translate}}</p>
</div>
<div class="ui-g-12 cx-container-centered-text">
<button pButton
type="button"
class="cx-action-button"
[label]="'consolidate-library.button.start'|translate"
[label]="'library.move-comics.button.start'|translate"
(click)="consolidateLibrary()"></button>
</div>
</form>
Expand Down
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -53,13 +55,13 @@ describe('ConsolidateLibraryComponent', () => {
let component: ConsolidateLibraryComponent;
let fixture: ComponentFixture<ConsolidateLibraryComponent>;
let confirmationService: ConfirmationService;
let libraryAdaptor: LibraryAdaptor;
let authenticationAdaptor: AuthenticationAdaptor;
let store: Store<AppState>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
UserModule,
ComicsModule,
RouterTestingModule,
Expand All @@ -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();
}));

Expand Down Expand Up @@ -131,7 +133,6 @@ describe('ConsolidateLibraryComponent', () => {
spyOn(confirmationService, 'confirm').and.callFake(
(confirm: Confirmation) => confirm.accept()
);
spyOn(libraryAdaptor, 'consolidate');
spyOn(authenticationAdaptor, 'setPreference');
});

Expand All @@ -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
})
);
});

Expand Down Expand Up @@ -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
})
);
});

Expand Down

0 comments on commit 012c1bd

Please sign in to comment.