Newer
Older
import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
import { Exercise } from 'app/shared/model/exercise.model';
import { SearchService } from 'app/search/service/search-service.ts';
import { JhiAlertService } from 'ng-jhipster';
import { ExerciseService } from '../service/exercise.service';
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 searchService: SearchService,
private jhiAlertService: JhiAlertService,
private exerciseService: ExerciseService,
) {
this.filename = 'README.md';
this.content = '';
}
ngOnChanges(changes: SimpleChanges): void {
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 = '' }
)
}
)
}