From 9882e3bb1f40d30be53fcca481c2965e51415cf9 Mon Sep 17 00:00:00 2001 From: "michael.breu" <michael.breu@uibk.ac.at> Date: Wed, 14 Apr 2021 18:54:48 +0200 Subject: [PATCH] Resolving problems with required login --- .../app/watchlist/watchlist.component.html | 2 +- .../app/watchlist/watchlist.component.ts | 31 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/app/watchlist/watchlist.component.html b/src/main/webapp/app/watchlist/watchlist.component.html index 50ebf64a0..d0e04b1f7 100644 --- a/src/main/webapp/app/watchlist/watchlist.component.html +++ b/src/main/webapp/app/watchlist/watchlist.component.html @@ -1,5 +1,5 @@ <div > - <div *ngFor="let watchList of myWatchLists">{{watchList.name}} + <div *ngFor="let watchList of getMyWatchLists()">{{watchList.name}} </div> </div> diff --git a/src/main/webapp/app/watchlist/watchlist.component.ts b/src/main/webapp/app/watchlist/watchlist.component.ts index 75e080180..7b458e4c6 100644 --- a/src/main/webapp/app/watchlist/watchlist.component.ts +++ b/src/main/webapp/app/watchlist/watchlist.component.ts @@ -2,6 +2,9 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { HttpResponse } from '@angular/common/http'; import { UserWatchListService } from '../entities/user-watch-list/user-watch-list.service'; import { IUserWatchList } from 'app/shared/model/user-watch-list.model'; +import { AccountService } from 'app/core/auth/account.service'; +import { Subscription } from 'rxjs'; +import { Account } from 'app/core/user/account.model'; @Component({ @@ -11,16 +14,21 @@ import { IUserWatchList } from 'app/shared/model/user-watch-list.model'; }) export class WatchlistComponent implements OnInit, OnDestroy { + account: Account | null = null; + authSubscription?: Subscription; + myWatchLists: IUserWatchList[] | undefined; constructor( protected watchListService: UserWatchListService, + private accountService: AccountService, + ) { } - - ngOnInit(): void { - if (!this.myWatchLists) { + getMyWatchLists(): IUserWatchList[] { + if(!this.isAuthenticated()) return []; + if (!this.myWatchLists) { this.watchListService.findMyWatchlists().subscribe((data: HttpResponse<IUserWatchList[]>) => { if (data.body) { this.myWatchLists = data.body; @@ -33,11 +41,24 @@ export class WatchlistComponent implements OnInit, OnDestroy { } }) - + return[]; + } else { + return this.myWatchLists; } + } - ngOnDestroy(): void { + ngOnInit(): void { + this.authSubscription = this.accountService.getAuthenticationState().subscribe(account => (this.account = account)); } + isAuthenticated(): boolean { + return this.accountService.isAuthenticated(); + } + + ngOnDestroy(): void { + if (this.authSubscription) { + this.authSubscription.unsubscribe(); + } + } } -- GitLab