From 9c3f70d36bab1ee09bde7c5d3e4ebde0518d8cb3 Mon Sep 17 00:00:00 2001 From: Patrick Gebhardt Date: Fri, 19 Jun 2020 17:25:05 +0200 Subject: [PATCH] Add bookmarks --- frontend/src/app/app-routing.module.ts | 2 + frontend/src/app/app.component.html | 10 ++- frontend/src/app/app.module.ts | 11 +++- .../bookmark-button.component.html | 7 +++ .../bookmark-button.component.scss | 0 .../bookmark-button.component.spec.ts | 25 ++++++++ .../bookmark-button.component.ts | 40 ++++++++++++ .../components/region/region.component.html | 7 +-- .../components/result/result.component.html | 7 +-- .../bookmark-list.component.html | 10 +++ .../bookmark-list.component.scss | 23 +++++++ .../bookmark-list.component.spec.ts | 25 ++++++++ .../bookmark-list/bookmark-list.component.ts | 46 ++++++++++++++ .../region-details.component.html | 7 +-- .../src/app/services/bookmark.service.spec.ts | 12 ++++ frontend/src/app/services/bookmark.service.ts | 63 +++++++++++++++++++ frontend/src/app/services/data.service.ts | 22 +++++-- frontend/src/app/utils/base64conversion.ts | 4 ++ frontend/src/assets/i18n/en.json | 1 + 19 files changed, 301 insertions(+), 21 deletions(-) create mode 100644 frontend/src/app/components/bookmark-button/bookmark-button.component.html create mode 100644 frontend/src/app/components/bookmark-button/bookmark-button.component.scss create mode 100644 frontend/src/app/components/bookmark-button/bookmark-button.component.spec.ts create mode 100644 frontend/src/app/components/bookmark-button/bookmark-button.component.ts create mode 100644 frontend/src/app/containers/bookmark-list/bookmark-list.component.html create mode 100644 frontend/src/app/containers/bookmark-list/bookmark-list.component.scss create mode 100644 frontend/src/app/containers/bookmark-list/bookmark-list.component.spec.ts create mode 100644 frontend/src/app/containers/bookmark-list/bookmark-list.component.ts create mode 100644 frontend/src/app/services/bookmark.service.spec.ts create mode 100644 frontend/src/app/services/bookmark.service.ts diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 90657fb..d0b18c7 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -4,12 +4,14 @@ import {HomeComponent} from './containers/home/home.component'; import {NotfoundComponent} from './containers/notfound/notfound.component'; import {SearchComponent} from './containers/search/search.component'; import {RegionDetailsComponent} from './containers/region-details/region-details.component'; +import {BookmarkListComponent} from './containers/bookmark-list/bookmark-list.component'; const routes: Routes = [ {path: 'home', component: HomeComponent}, {path: 'search', component: SearchComponent}, {path: 'region/:id', component: RegionDetailsComponent}, + {path: 'bookmark', component: BookmarkListComponent}, {path: '', redirectTo: 'home', pathMatch: 'full'}, {path: '**', component: NotfoundComponent} ]; diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 659f55e..2ce0211 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -9,10 +9,16 @@
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 51aedd2..268ffbe 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -21,13 +21,15 @@ import {TranslateModule, TranslateService} from '@ngx-translate/core'; // @ts-ignore import * as enLang from '../assets/i18n/en.json'; import {HttpClientModule} from '@angular/common/http'; -import {MatButtonToggleModule, MatCheckboxModule, MatDividerModule} from '@angular/material'; +import {MatButtonToggleModule, MatCheckboxModule, MatDividerModule, MatTooltipModule} from '@angular/material'; import {FormsModule} from '@angular/forms'; import {RegionComponent} from './components/region/region.component'; import {ResultComponent} from './components/result/result.component'; import {RegionDetailsComponent} from './containers/region-details/region-details.component'; import {GraphComponent} from './components/graph/graph.component'; import {RegionStatsComponent} from './components/region-stats/region-stats.component'; +import {BookmarkButtonComponent} from './components/bookmark-button/bookmark-button.component'; +import {BookmarkListComponent} from './containers/bookmark-list/bookmark-list.component'; @NgModule({ @@ -41,7 +43,9 @@ import {RegionStatsComponent} from './components/region-stats/region-stats.compo ResultComponent, RegionDetailsComponent, GraphComponent, - RegionStatsComponent + RegionStatsComponent, + BookmarkButtonComponent, + BookmarkListComponent ], imports: [ BrowserModule, @@ -61,7 +65,8 @@ import {RegionStatsComponent} from './components/region-stats/region-stats.compo MatCheckboxModule, FormsModule, MatButtonToggleModule, - MatDividerModule + MatDividerModule, + MatTooltipModule ], providers: [], bootstrap: [AppComponent] diff --git a/frontend/src/app/components/bookmark-button/bookmark-button.component.html b/frontend/src/app/components/bookmark-button/bookmark-button.component.html new file mode 100644 index 0000000..4e819e3 --- /dev/null +++ b/frontend/src/app/components/bookmark-button/bookmark-button.component.html @@ -0,0 +1,7 @@ + diff --git a/frontend/src/app/components/bookmark-button/bookmark-button.component.scss b/frontend/src/app/components/bookmark-button/bookmark-button.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/components/bookmark-button/bookmark-button.component.spec.ts b/frontend/src/app/components/bookmark-button/bookmark-button.component.spec.ts new file mode 100644 index 0000000..a944a77 --- /dev/null +++ b/frontend/src/app/components/bookmark-button/bookmark-button.component.spec.ts @@ -0,0 +1,25 @@ +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; + +import {BookmarkButtonComponent} from './bookmark-button.component'; + +describe('BookmarkButtonComponent', () => { + let component: BookmarkButtonComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [BookmarkButtonComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BookmarkButtonComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/components/bookmark-button/bookmark-button.component.ts b/frontend/src/app/components/bookmark-button/bookmark-button.component.ts new file mode 100644 index 0000000..6610323 --- /dev/null +++ b/frontend/src/app/components/bookmark-button/bookmark-button.component.ts @@ -0,0 +1,40 @@ +import {Component, Input, OnDestroy, OnInit} from '@angular/core'; +import {Region} from '../../interfaces/region.interface'; +import {BookmarkService} from '../../services/bookmark.service'; +import {Subject} from 'rxjs'; +import {takeUntil} from 'rxjs/operators'; + +@Component({ + selector: 'app-bookmark-button', + templateUrl: './bookmark-button.component.html', + styleUrls: ['./bookmark-button.component.scss'] +}) +export class BookmarkButtonComponent implements OnInit, OnDestroy { + + @Input() + region: Region; + + isBookmarked = false; + + private destroyed$ = new Subject(); + + constructor(private bs: BookmarkService) { + } + + ngOnInit() { + this.bs.isMarked(this.region.region_id).pipe( + takeUntil(this.destroyed$) + ).subscribe(val => this.isBookmarked = val); + } + + onToggle(event: Event) { + event.stopPropagation(); + this.bs.toggleRegion(this.region.region_id); + } + + ngOnDestroy(): void { + this.destroyed$.next(); + this.destroyed$.complete(); + } + +} diff --git a/frontend/src/app/components/region/region.component.html b/frontend/src/app/components/region/region.component.html index 3d6bead..4ea7798 100644 --- a/frontend/src/app/components/region/region.component.html +++ b/frontend/src/app/components/region/region.component.html @@ -1,13 +1,12 @@
- + Picture of {{region.name}}