Skip to content

Commit

Permalink
[Issue #230] Add the collection type to ComicCollectionEntry.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Jun 21, 2020
1 parent fb0f47c commit e980c14
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 20 deletions.
Expand Up @@ -22,9 +22,11 @@ import { TranslateModule } from '@ngx-translate/core';
import { CardModule } from 'primeng/card';
import { ComicGroupingCardComponent } from './comic-grouping-card.component';
import { ComicCollectionEntry } from 'app/library/models/comic-collection-entry';
import { CollectionType } from 'app/library/models/collection-type.enum';

export const DEFAULT_COMIC_GROUPING: ComicCollectionEntry = {
name: 'grouping name',
type: CollectionType.PUBLISHERS,
count: 0,
comics: [],
last_comic_added: 0
Expand Down
Expand Up @@ -42,6 +42,7 @@ import { BehaviorSubject } from 'rxjs';
import { ComicCollectionEntry } from 'app/library/models/comic-collection-entry';
import { PublisherThumbnailUrlPipe } from 'app/comics/pipes/publisher-thumbnail-url.pipe';
import { PublisherPipe } from 'app/comics/pipes/publisher.pipe';
import { CollectionType } from 'app/library/models/collection-type.enum';

describe('ComicOverviewComponent', () => {
const COMIC = Object.assign({}, COMIC_1);
Expand Down Expand Up @@ -159,6 +160,7 @@ describe('ComicOverviewComponent', () => {
publishers.next([
{
name: 'FOO',
type: CollectionType.SERIES,
comics: [],
count: 0,
last_comic_added: null
Expand All @@ -167,6 +169,7 @@ describe('ComicOverviewComponent', () => {
series.next([
{
name: 'BAR',
type: CollectionType.SERIES,
comics: [],
count: 0,
last_comic_added: null
Expand Down
25 changes: 19 additions & 6 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.spec.ts
Expand Up @@ -55,6 +55,7 @@ import {
LibraryUpdatesReceived
} from '../actions/library.actions';
import { LibraryAdaptor } from './library.adaptor';
import { CollectionType } from 'app/library/models/collection-type.enum';

describe('LibraryAdaptor', () => {
const ASCENDING = false;
Expand Down Expand Up @@ -132,12 +133,24 @@ describe('LibraryAdaptor', () => {
});

describe('when updates are received', () => {
const PUBLISHERS = extractField(COMICS, 'publisher');
const SERIES = extractField(COMICS, 'series');
const CHARACTERS = extractField(COMICS, 'characters');
const TEAMS = extractField(COMICS, 'teams');
const LOCATIONS = extractField(COMICS, 'locations');
const STORIES = extractField(COMICS, 'storyArcs');
const PUBLISHERS = extractField(
COMICS,
CollectionType.PUBLISHERS,
'publisher'
);
const SERIES = extractField(COMICS, CollectionType.SERIES, 'series');
const CHARACTERS = extractField(
COMICS,
CollectionType.CHARACTERS,
'characters'
);
const TEAMS = extractField(COMICS, CollectionType.TEAMS, 'teams');
const LOCATIONS = extractField(
COMICS,
CollectionType.LOCATIONS,
'locations'
);
const STORIES = extractField(COMICS, CollectionType.STORIES, 'storyArcs');

beforeEach(() => {
store.dispatch(
Expand Down
28 changes: 22 additions & 6 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.ts
Expand Up @@ -42,6 +42,7 @@ import { ComicAdaptor } from 'app/comics/adaptors/comic.adaptor';
import { ComicGetIssue } from 'app/comics/actions/comic.actions';
import { ComicCollectionEntry } from 'app/library/models/comic-collection-entry';
import { LoggerService } from '@angular-ru/logger';
import { CollectionType } from 'app/library/models/collection-type.enum';

@Injectable()
export class LibraryAdaptor {
Expand Down Expand Up @@ -108,13 +109,28 @@ export class LibraryAdaptor {
if (!_.isEqual(this._comic$.getValue(), state.comics)) {
this._comic$.next(state.comics);
this._publishers$.next(
extractField(state.comics, 'publisher', 'imprint')
extractField(
state.comics,
CollectionType.PUBLISHERS,
'publisher',
'imprint'
)
);
this._series$.next(
extractField(state.comics, CollectionType.SERIES, 'series')
);
this._characters$.next(
extractField(state.comics, CollectionType.CHARACTERS, 'characters')
);
this._teams$.next(
extractField(state.comics, CollectionType.TEAMS, 'teams')
);
this._locations$.next(
extractField(state.comics, CollectionType.LOCATIONS, 'locations')
);
this._stories$.next(
extractField(state.comics, CollectionType.STORIES, 'storyArcs')
);
this._series$.next(extractField(state.comics, 'series'));
this._characters$.next(extractField(state.comics, 'characters'));
this._teams$.next(extractField(state.comics, 'teams'));
this._locations$.next(extractField(state.comics, 'locations'));
this._stories$.next(extractField(state.comics, 'storyArcs'));
}
if (
!!state.lastComicId &&
Expand Down
Expand Up @@ -24,17 +24,20 @@ import {
COMIC_4,
COMIC_5
} from 'app/comics/comics.fixtures';
import { CollectionType } from 'app/library/models/collection-type.enum';

export const COMIC_COLLECTION_ENTRY_1: ComicCollectionEntry = {
comics: [COMIC_1, COMIC_3, COMIC_5],
count: 3,
last_comic_added: 0,
name: 'collection1'
name: 'collection1',
type: CollectionType.STORIES
};

export const COMIC_COLLECTION_ENTRY_2: ComicCollectionEntry = {
comics: [COMIC_2, COMIC_4, COMIC_5],
count: 3,
last_comic_added: 0,
name: 'collection2'
name: 'collection2',
type: CollectionType.PUBLISHERS
};
Expand Up @@ -17,9 +17,11 @@
*/

import { Comic } from 'app/comics/models/comic';
import { CollectionType } from 'app/library/models/collection-type.enum';

export interface ComicCollectionEntry {
name: string;
type: CollectionType;
count: number;
comics: Comic[];
last_comic_added: number;
Expand Down
15 changes: 9 additions & 6 deletions comixed-frontend/src/app/library/utility.functions.ts
Expand Up @@ -19,6 +19,7 @@
import * as _ from 'lodash';
import { Comic } from 'app/comics/models/comic';
import { ComicCollectionEntry } from 'app/library/models/comic-collection-entry';
import { CollectionType } from 'app/library/models/collection-type.enum';

export function mergeComics(base: Comic[], update: Comic[]): Comic[] {
const result = base.filter(base_entry => {
Expand Down Expand Up @@ -59,6 +60,7 @@ interface ExtractEntry {

export function extractField(
comics: Comic[],
type: CollectionType,
primaryFieldName: string,
secondaryFieldName: string = null
): ComicCollectionEntry[] {
Expand Down Expand Up @@ -87,21 +89,22 @@ export function extractField(
}
});

const comics_by_field = new Map<string, Comic[]>();
extractedData.forEach(extract_entry => {
let collection_entry: Comic[] = comics_by_field[extract_entry.name];
const comicsByField = new Map<string, Comic[]>();
extractedData.forEach(extractEntry => {
let collection_entry: Comic[] = comicsByField[extractEntry.name];

if (!collection_entry) {
collection_entry = [];
comics_by_field[extract_entry.name] = collection_entry;
comicsByField[extractEntry.name] = collection_entry;
}
collection_entry.push(extract_entry.comic);
collection_entry.push(extractEntry.comic);
});

const result: ComicCollectionEntry[] = [];
_.forEach(comics_by_field, (value: Comic[], key: string) => {
_.forEach(comicsByField, (value: Comic[], key: string) => {
result.push({
name: key,
type: type,
count: value.length,
comics: value,
last_comic_added: latestComicAddedDate(value)
Expand Down

0 comments on commit e980c14

Please sign in to comment.