import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { Exercise } from 'app/shared/model/exercise.model'; import { SearchService } from 'app/search/service/search-service'; import { Statistics } from 'app/shared/model/statistics.model'; @Component({ selector: 'jhi-exercise-card', templateUrl: './exercise-card.component.html', styleUrls: ['./exercise-card.component.scss'], }) export class ExerciseCardComponent implements OnInit { @Input() exercise: Exercise | undefined; @Output() exerciseSelectionEvent = new EventEmitter<Exercise>(); constructor(protected searchService: SearchService) {} ngOnInit(): void {} selectExercise(): void { if (this.exercise !== undefined) { this.exercise.views = 0; this.exercise.downloads = 0; this.searchService.getStatisticsForExercise(this.exercise.originalResult.project.project_id).subscribe( (data: Statistics) => { this.exercise!.views = data.views!; this.exercise!.downloads = data.downloads!; }, () => alert('Could not load exercise statistics') ); } this.exerciseSelectionEvent.emit(this.exercise); } /** * correct missing image urls */ correctImageURL(event: Event): void { if (event.srcElement) { event.srcElement['src'] = '/content/img/gitLab.png'; } } }