Skip to content

Commit

Permalink
Added a context menu item to remove comics from a reading list [#275]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Jun 21, 2020
1 parent 8707e1c commit 0d35c65
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 17 deletions.
Expand Up @@ -71,13 +71,13 @@ import { ScrollPanelModule } from 'primeng/scrollpanel';
import { SliderModule } from 'primeng/slider';
import { SplitButtonModule } from 'primeng/splitbutton';
import { BehaviorSubject } from 'rxjs';
import {
COMIC_LIST_MENU_DESELECT_ALL,
COMIC_LIST_MENU_SELECT_ALL,
ComicListComponent
} from './comic-list.component';
import { ComicListComponent } from './comic-list.component';
import { ConvertComicsSettingsComponent } from 'app/library/components/convert-comics-settings/convert-comics-settings.component';
import { LibraryNavigationTreeComponent } from 'app/library/components/library-navigation-tree/library-navigation-tree.component';
import {
COMIC_LIST_MENU_DESELECT_ALL,
COMIC_LIST_MENU_SELECT_ALL
} from 'app/library/library.constants';

describe('ComicListComponent', () => {
const COMICS = [COMIC_1, COMIC_3, COMIC_5];
Expand Down
Expand Up @@ -45,14 +45,14 @@ import { ConfirmationService, SelectItem } from 'primeng/api';
import { MenuItem } from 'primeng/components/common/menuitem';
import { ContextMenu } from 'primeng/contextmenu';
import { Subscription } from 'rxjs';

export const COMIC_LIST_MENU_SELECT_ALL = 'comic-list-scrape-select-all';
export const COMIC_LIST_MENU_DESELECT_ALL = 'comic-list-scrape-deselect-all';
export const COMIC_LIST_MENU_DELETE_SELECTED = 'comic-list-delete-selected';
export const COMIC_LIST_MENU_SCRAPE_SELECTED = 'comic-list-scrape-selected';
export const COMIC_LIST_MENU_CONVERT_COMIC = 'comic-list-convert-comic';
export const COMIC_LIST_MENU_ADD_TO_READING_LIST =
'comic-list-add-to-reading-list';
import {
COMIC_LIST_MENU_ADD_TO_READING_LIST,
COMIC_LIST_MENU_CONVERT_COMIC,
COMIC_LIST_MENU_DELETE_SELECTED,
COMIC_LIST_MENU_DESELECT_ALL,
COMIC_LIST_MENU_SCRAPE_SELECTED,
COMIC_LIST_MENU_SELECT_ALL
} from 'app/library/library.constants';

@Component({
selector: 'app-comic-list',
Expand Down
9 changes: 9 additions & 0 deletions comixed-frontend/src/app/library/library.constants.ts
Expand Up @@ -42,6 +42,15 @@ export const UPDATE_READING_LIST_URL = `${COMIXED_API_ROOT}/lists/\${id}`;
export const ADD_COMICS_TO_READING_LIST_URL = `${COMIXED_API_ROOT}/lists/\${id}/comics/add`;
export const REMOVE_COMICS_FROM_READING_LIST = `${COMIXED_API_ROOT}/lists/\${id}/comics/remove`;

export const COMIC_LIST_MENU_SELECT_ALL = 'comic-list-scrape-select-all';
export const COMIC_LIST_MENU_DESELECT_ALL = 'comic-list-scrape-deselect-all';
export const COMIC_LIST_MENU_DELETE_SELECTED = 'comic-list-delete-selected';
export const COMIC_LIST_MENU_SCRAPE_SELECTED = 'comic-list-scrape-selected';
export const COMIC_LIST_MENU_CONVERT_COMIC = 'comic-list-convert-comic';
export const COMIC_LIST_MENU_ADD_TO_READING_LIST =
'comic-list-add-to-reading-list';
export const REMOVE_READING_LIST_ITEMS = 'comic-list-reading-list-item-remove';

export const NEW_READING_LIST: ReadingList = {
id: null,
name: '',
Expand Down
Expand Up @@ -19,7 +19,11 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { LibraryAdaptor, SelectionAdaptor } from 'app/library';
import {
LibraryAdaptor,
ReadingListAdaptor,
SelectionAdaptor
} from 'app/library';
import { UserService } from 'app/services/user.service';
import { ConfirmationService, MenuItem, MessageService } from 'primeng/api';
import { TranslateService } from '@ngx-translate/core';
Expand All @@ -31,6 +35,8 @@ import { filter } from 'rxjs/operators';
import { CollectionType } from 'app/library/models/collection-type.enum';
import { LoggerService } from '@angular-ru/logger';
import { ComicCollectionEntry } from 'app/library/models/comic-collection-entry';
import { ContextMenuAdaptor } from 'app/user-experience/adaptors/context-menu.adaptor';
import { REMOVE_READING_LIST_ITEMS } from 'app/library/library.constants';

@Component({
selector: 'app-library-page',
Expand Down Expand Up @@ -67,13 +73,19 @@ export class LibraryPageComponent implements OnInit, OnDestroy {
private confirmationService: ConfirmationService,
private translateService: TranslateService,
private messageService: MessageService,
private breadcrumbAdaptor: BreadcrumbAdaptor
private breadcrumbAdaptor: BreadcrumbAdaptor,
private contextMenuAdaptor: ContextMenuAdaptor,
private readingListAdaptor: ReadingListAdaptor
) {
this.addContextMenuItems();
this.authSubscription = this.authenticationAdaptor.user$.subscribe(
user => (this.user = user)
);
this.selectedComicsSubscription = this.selectionAdaptor.comicSelection$.subscribe(
selected_comics => (this.selectedComics = selected_comics)
selected_comics => {
this.selectedComics = selected_comics;
this.updateContextMenu();
}
);
this.importCountSubscription = this.libraryAdaptor.processingCount$.subscribe(
processing => (this.processingCount = processing)
Expand Down Expand Up @@ -138,6 +150,7 @@ export class LibraryPageComponent implements OnInit, OnDestroy {
this.logger.error('no such collection type:', this.collectionType);
titleKey = '';
}
this.addContextMenuItems();

this.titleService.setTitle(
this.translateService.instant(`library-page.title.${titleKey}`, {
Expand Down Expand Up @@ -193,6 +206,7 @@ export class LibraryPageComponent implements OnInit, OnDestroy {
this.comicsSubscription.unsubscribe();
this.selectedComicsSubscription.unsubscribe();
this.importCountSubscription.unsubscribe();
this.removeContextMenuItems();
}

deleteComic(comic: Comic): void {
Expand Down Expand Up @@ -239,4 +253,64 @@ export class LibraryPageComponent implements OnInit, OnDestroy {
}
this.breadcrumbAdaptor.loadEntries(entries);
}

private updateContextMenu() {
if (this.collectionType === CollectionType.READING_LISTS) {
this.logger.info('this.collectionType:', this.collectionType);
this.logger.info(
'showing remove comics from reading list context menu item'
);
this.contextMenuAdaptor.showItem(REMOVE_READING_LIST_ITEMS);

if (this.selectedComics.length > 0) {
this.logger.info(
'enabling remove comics from reading list context menu item'
);
this.contextMenuAdaptor.enableItem(REMOVE_READING_LIST_ITEMS);
} else {
this.logger.info(
'disabling remove comics from reading list context menu item'
);
this.contextMenuAdaptor.disableItem(REMOVE_READING_LIST_ITEMS);
}
} else {
this.logger.info('this.collectionType:', this.collectionType);
this.logger.info(
'hiding remove comics from reading list context menu item'
);
this.contextMenuAdaptor.hideItem(REMOVE_READING_LIST_ITEMS);
}
}

private removeContextMenuItems() {
this.logger.info('removing context menu items');
this.contextMenuAdaptor.removeItem(REMOVE_READING_LIST_ITEMS);
}

private addContextMenuItems() {
this.logger.info('adding context menu items');
this.contextMenuAdaptor.addItem(
REMOVE_READING_LIST_ITEMS,
'fa fa-fw fa-minus',
'comic-list.context-menu.remove-from-reading-list',
false,
true,
() =>
this.confirmationService.confirm({
header: this.translateService.instant(
'library-page.remove-comics-from-reading-list.header',
{ name: this.collectionName }
),
message: this.translateService.instant(
'library-page.remove-comics-from-reading-list.message',
{ count: this.selectedComics.length }
),
accept: () =>
this.readingListAdaptor.removeComics(
this.libraryAdaptor.findReadingList(this.collectionName),
this.selectedComics
)
})
);
}
}
7 changes: 6 additions & 1 deletion comixed-frontend/src/assets/i18n/library-en.json
Expand Up @@ -140,6 +140,10 @@
"title-for-collection": "{name} [{type, select, publishers{Publisher} series{Series} characters{Character} teams{Team} locations{Location} stories{Story} lists{Reading List} other{Unknown}}] - {count, plural, =1{One Comic} other{# Comics}}",
"error": {
"no-such-type": "No such collection type: {type}"
},
"remove-comics-from-reading-list": {
"header": "Remove Selected Comics From {name}",
"message": "Are you sure you want to remove {count, plural, =1{one comic} other{# comics}} from this reading list?"
}
},
"reading-lists-page": {
Expand Down Expand Up @@ -234,7 +238,8 @@
"delete-selected": "Delete selections...",
"scrape-selected": "Scrape selections",
"convert-comic": "Convert comic...",
"add-to-reading-list": "Add to list..."
"add-to-reading-list": "Add to list...",
"remove-from-reading-list": "Remove from list..."
},
"start-scraping": {
"header": "Scrape Selected Comic",
Expand Down

0 comments on commit 0d35c65

Please sign in to comment.