From 6a759009081da62da3114300e567861d14c3a388 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Thu, 18 Feb 2021 10:23:00 -0600 Subject: [PATCH] #86 - implement basic bookmarks in sidebar --- src/app/app.component.ts | 32 +++++++++++++++++++ .../option-menu/option-menu.component.html | 2 +- src/app/service/db/database.service.ts | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c53f12d..a4bb710 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -227,12 +227,19 @@ export class AppComponent implements OnInit { const options = [ {name: 'Make Virtual Root', icon: 'fa fa-search-plus', value: 'virtual_root'}, {name: 'Export to HTML', icon: 'fa fa-file-export', value: 'export_html'}, + // {name: 'Export as PDF', icon: 'fa fa-file-export', value: 'export_pdf'}, ]; const manageOptions = [ {name: 'Share Sub-Tree', icon: 'fa fa-share-alt', value: 'share'}, ]; + if ( this.menuTarget.data.bookmark ) { + options.push({name: 'Remove Bookmark', icon: 'fa fa-star', value: 'bookmark_remove'}); + } else { + options.push({name: 'Bookmark', icon: 'fa fa-star', value: 'bookmark_add'}); + } + const popover = await this.popover.create({ component: OptionMenuComponent, componentProps: { @@ -263,8 +270,14 @@ export class AppComponent implements OnInit { }); } else if ( result.data === 'export_html' ) { this.exportTargetAsHTML(); + } else if ( result.data === 'export_pdf' ) { + this.exportTargetAsPDF(); } else if ( result.data === 'virtual_root' ) { this.setVirtualRoot(); + } else if ( result.data === 'bookmark_add' ) { + this.addBookmark(); + } else if ( result.data === 'bookmark_remove' ) { + this.removeBookmark(); } }); @@ -303,6 +316,25 @@ export class AppComponent implements OnInit { window.open(dlUrl, '_blank'); } + addBookmark() { + const bookmarks = this.session.get('user.preferences.bookmark_page_ids') || []; + + if ( !bookmarks.includes(this.menuTarget.data.id) ) { + bookmarks.push(this.menuTarget.data.id); + } + + this.session.set('user.preferences.bookmark_page_ids', bookmarks); + this.session.save().then(() => this.navService.requestSidebarRefresh({ quiet: true })); + } + + removeBookmark() { + let bookmarks = this.session.get('user.preferences.bookmark_page_ids') || []; + bookmarks = bookmarks.filter(x => x !== this.menuTarget.data.id); + + this.session.set('user.preferences.bookmark_page_ids', bookmarks); + this.session.save().then(() => this.navService.requestSidebarRefresh({ quiet: true })); + } + async onCreateClick($event: MouseEvent) { const menuItems = [ { diff --git a/src/app/components/option-menu/option-menu.component.html b/src/app/components/option-menu/option-menu.component.html index eab4628..81afa0d 100644 --- a/src/app/components/option-menu/option-menu.component.html +++ b/src/app/components/option-menu/option-menu.component.html @@ -1,5 +1,5 @@ - + {{ menuItems[i].name }} diff --git a/src/app/service/db/database.service.ts b/src/app/service/db/database.service.ts index 9f174a9..516fc74 100644 --- a/src/app/service/db/database.service.ts +++ b/src/app/service/db/database.service.ts @@ -35,6 +35,7 @@ export class DatabaseService extends Dexie { constructor( ) { super('NodedLocalDatabase'); + this.createSchemata(); } public async getKeyValue(key: string): Promise {