import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core'; import { Exercise } from 'app/shared/model/exercise.model'; import { ExerciseService } from '../service/exercise.service'; @Component({ selector: 'jhi-markdown-viewer', templateUrl: './markDownViewer.component.html', styleUrls: ['./markDownViewer.component.scss'], }) export class MarkDownViewerComponent implements OnInit, OnChanges { @Input() exercise: Exercise | undefined; public filename: string; public content: string; constructor( private exerciseService: ExerciseService, ) { this.filename = 'README.md'; this.content = ''; } ngOnInit(): void { } // eslint-disable-next-line ngOnChanges(changes: SimpleChanges): void { if(!this.exercise) return; this.exerciseService.loadExerciseFile(this.exercise.originalResult.project.project_id, 'README.md').subscribe( (content) => { this.content = content; this.filename = 'README.md' }, () => { this.exerciseService.loadExerciseFile(this.exercise!.originalResult.project.project_id, 'exercise.md').subscribe( (content) => { this.content = content; this.filename = 'exercise.md'; }, () => { this.content = '#No README found'; this.filename = '' } ) } ) } }