Newer
Older
import { Component, Input, Output, EventEmitter, AfterViewChecked } from '@angular/core';
import { Exercise } from 'app/shared/model/exercise.model';

Michael Breu
committed
import { SearchService } from 'app/search/service/search-service';
import { WatchlistManager } from 'app/shared/watchlist/watchlist-manager';

Eduard Frankford
committed
import { ExerciseService } from '../service/exercise.service';
import { AccountService } from 'app/core/auth/account.service';

Michael Breu
committed

Michael Breu
committed
selector: 'jhi-exercise-card',
templateUrl: './exercise-card.component.html',
styleUrls: ['./exercise-card.component.scss'],
export class ExerciseCardComponent implements AfterViewChecked {

Michael Breu
committed
@Input() exercise: Exercise | undefined;
@Input() autoOpenDetails = false; // if true opens details dialog automatically

Michael Breu
committed
@Output() exerciseSelectionEvent = new EventEmitter<Exercise>();

Eduard Frankford
committed
constructor(
protected searchService: SearchService,
private watchlistManager: WatchlistManager,
private exerciseService: ExerciseService,
private accountService: AccountService

Eduard Frankford
committed
) {}
ngAfterViewChecked(): void {
if (this.autoOpenDetails) {
const button = document.querySelector('.exerciseDetailButton');
if (button instanceof HTMLElement) {
button.click();
this.autoOpenDetails = false;
}
}
isLoggedIn(): boolean {
return this.accountService.isAuthenticated();
}

Michael Breu
committed
selectExercise(): void {
this.bookmarked = this.watchlistManager.isExerciseOnCurrentWatchlist(this.exercise!);

Eduard Frankford
committed
this.exercise = this.exerciseService.populateExerciseWithData(this.exercise!);

Michael Breu
committed
this.exerciseSelectionEvent.emit(this.exercise);
}
isOnCurrentWatchlist(e: Exercise): boolean {
return this.watchlistManager.isExerciseOnCurrentWatchlist(e);
}
handleForCurrentWatchlist(): void {
if (this.watchlistManager.isExerciseOnCurrentWatchlist(this.exercise!)) {
this.bookmarked = false;
this.watchlistManager.handleCheckForCurrentWatchlist(this.exercise!, false);
} else {
this.bookmarked = true;
this.watchlistManager.handleCheckForCurrentWatchlist(this.exercise!, true);
}

Michael Breu
committed
/**
* correct missing image urls
*/
correctImageURL(event: Event): void {
const img = event.srcElement as HTMLImageElement;
if (img) {
img.src = '/content/images/Logo_codeAbility_4c_300dpi_RGB3.gif';

Michael Breu
committed
}