Skip to content

Commit

Permalink
[Issue comixed#20] Enable consolidating the library.
Browse files Browse the repository at this point in the history
* [Issue comixed#20] Add REST API for conslidating the library.

* [Issue comixed#20] Add the consolidation feature to the library state.

* [Issue comixed#20] Add the ConsolidateLibrary component and tests.

* [Issue comixed#20] Moved LibraryAdminPage into the library module.
  • Loading branch information
mcpierce authored Mar 24, 2020
1 parent f317df0 commit 8d9e0cb
Show file tree
Hide file tree
Showing 39 changed files with 1,001 additions and 141 deletions.
4 changes: 0 additions & 4 deletions comixed-frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ import { ComicsModule } from 'app/comics/comics.module';
import { LoginComponent } from 'app/components/login/login.component';
import { MainMenuComponent } from 'app/components/main-menu/main-menu.component';
import { LibraryModule } from 'app/library/library.module';
import { LibraryAdminPageComponent } from 'app/pages/admin/library-admin-page/library-admin-page.component';
import { MainPageComponent } from 'app/pages/main-page/main-page.component';
import { UserService } from 'app/services/user.service';
import { UserModule } from 'app/user/user.module';
import { XhrInterceptor } from 'app/xhr.interceptor';
import { FileSaverModule } from 'ngx-filesaver';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
import { MultiTranslateHttpLoader } from 'ngx-translate-multi-http-loader';
import { ConfirmationService, MessageService } from 'primeng/api';
Expand Down Expand Up @@ -90,7 +88,6 @@ import { LoggerModule } from '@angular-ru/logger';
AppComponent,
MainPageComponent,
LoginComponent,
LibraryAdminPageComponent,
MainMenuComponent
],
imports: [
Expand Down Expand Up @@ -159,7 +156,6 @@ import { LoggerModule } from '@angular-ru/logger';
}
}),
LoggerModule.forRoot(),
FileSaverModule,
BreadcrumbModule
],
providers: [
Expand Down
7 changes: 0 additions & 7 deletions comixed-frontend/src/app/app.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AdminGuard } from 'app/user';
import { MainPageComponent } from 'app/pages/main-page/main-page.component';
import { LibraryAdminPageComponent } from 'app/pages/admin/library-admin-page/library-admin-page.component';

export const routes: Routes = [
{
path: 'home',
component: MainPageComponent
},
{
path: 'admin/library',
component: LibraryAdminPageComponent,
canActivate: [AdminGuard]
},
{
path: '',
redirectTo: 'home',
Expand Down
28 changes: 26 additions & 2 deletions comixed-frontend/src/app/library/actions/library.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export enum LibraryActionTypes {
DeleteMultipleComicsFailed = '[LIBRARY] Failed to delete multiple comics',
ConvertComics = '[LIBRARY] Convert comics to a new archive type',
ComicsConverting = '[LIBRARY] Comics converting to a new archive type',
ConvertComicsFailed = '[LIBRARY] Failed to convert comics'
ConvertComicsFailed = '[LIBRARY] Failed to convert comics',
Consolidate = '[LIBRARY] Consolidate the library',
Consolidated = '[LIBRARY] Library is consolidated',
ConsolidateFailed = '[LIBRARY] Failed to consolidate libary'
}

export class LibraryReset implements Action {
Expand Down Expand Up @@ -137,6 +140,24 @@ export class LibraryConvertComicsFailed implements Action {
constructor() {}
}

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

constructor(public payload: { deletePhysicalFiles: boolean }) {}
}

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

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

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

constructor() {}
}

export type LibraryActions =
| LibraryReset
| LibraryGetUpdates
Expand All @@ -150,4 +171,7 @@ export type LibraryActions =
| LibraryDeleteMultipleComicsFailed
| LibraryConvertComics
| LibraryComicsConverting
| LibraryConvertComicsFailed;
| LibraryConvertComicsFailed
| LibraryConsolidate
| LibraryConsolidated
| LibraryConsolidateFailed;
68 changes: 68 additions & 0 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import { MessageService } from 'primeng/api';
import * as LibraryActions from '../actions/library.actions';
import {
LibraryComicsConverting,
LibraryConsolidate,
LibraryConsolidated,
LibraryConsolidateFailed,
LibraryConvertComics,
LibraryConvertComicsFailed,
LibraryGetUpdates,
Expand Down Expand Up @@ -311,4 +314,69 @@ describe('LibraryAdaptor', () => {
});
});
});

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

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

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: []
})
);
store.dispatch(
new LibraryConsolidated({ deletedComics: DELETED_COMICS })
);
});

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());
});

it('provides updates on consolidating', () => {
adaptor.consolidating$.subscribe(response =>
expect(response).toBeFalsy()
);
});
});
});
});
18 changes: 18 additions & 0 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { filter } from 'rxjs/operators';
import { extractField } from 'app/library/utility.functions';
import { LastReadDate } from 'app/library/models/last-read-date';
import {
LibraryConsolidate,
LibraryConvertComics,
LibraryDeleteMultipleComics,
LibraryGetUpdates,
Expand Down Expand Up @@ -60,6 +61,7 @@ export class LibraryAdaptor {
private _timeout = 60;
private _maximum = 100;
private _converting$ = new BehaviorSubject<boolean>(false);
private _consolidating$ = new BehaviorSubject<boolean>(false);

constructor(
private store: Store<AppState>,
Expand Down Expand Up @@ -118,6 +120,9 @@ 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);
}
});
}

Expand Down Expand Up @@ -241,4 +246,17 @@ export class LibraryAdaptor {
get converting$(): Observable<boolean> {
return this._converting$.asObservable();
}

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

get consolidating$(): Observable<boolean> {
return this._consolidating$.asObservable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class='ui-g'>
<form [formGroup]='consolidationForm'>
<div class='ui-g-12'>
<p-checkbox id='delete-physical-files'
[binary]='true'
formControlName='deletePhysicalFiles'></p-checkbox>
<label for='delete-physical-files'>{{'consolidate-library.label.delete-physical-files'|translate}}</label>
</div>
<div class='ui-g-12 cx-container-centered-text'>
<button pButton
type='button'
class='cx-action-button'
[label]='"consolidate-library.button.start"|translate'
(click)='consolidateLibrary()'></button>
</div>
</form>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p-checkbox {
padding-right: 5px;
}
Loading

0 comments on commit 8d9e0cb

Please sign in to comment.