Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { Component, OnInit, Input } from '@angular/core';
import { Exercise, IExerciseType } from 'app/shared/model/exercise.model';
import { Person } from 'app/shared/model/person.model';
import { SearchService } from 'app/search/service/search-service.ts';
import { HttpResponse } from '@angular/common/http';
import { JhiAlertService } from 'ng-jhipster';
@Component({
selector: 'jhi-markdown-viewer',
templateUrl: './markDownViewer.component.html',
styleUrls: ['./markdownViewer.component.scss'],
})
export class MarkDownViewerComponent implements OnInit {
@Input() exercise: Exercise | undefined;
constructor(
private searchService: SearchService,
private jhiAlertService: JhiAlertService
) {}
ngOnInit(): void {
}
public get exerciseType(): typeof IExerciseType {
return IExerciseType;
}
public getPersonName(person: Person): string {
return person.name;
}
public getPersonDetails(person: Person): string {
return person.name + ', ' + person.affiliation;
}
public getPersonDetailsWithEmail(person: Person): string {
return "<a class='text-dark' href='mailto:" + person.email + "'>" + person.name + ', ' + person.affiliation + '</a>';
}
public arrayToString(array: string[]): string {
let result = '';
let i = 1;
array.forEach(element => {
if (array.length > 1 && array.length !== i) {
result += element + ', ';
} else {
result += element;
}
if (i % 5 === 0) {
result += '<br>';
}
i++;
});
return result;
}
public download(): void {
this.exportExercise(Number(this.exercise!.originalResult.project.project_id));
}
exportExercise(projectId: number) {
return this.searchService.exportExercise(projectId).subscribe(
(response: HttpResponse<Blob>) => {
this.jhiAlertService.success('artemisApp.programmingExercise.export.successMessage');
if (response.body) {
const zipFile = new Blob([response.body], { type: 'application/zip' });
const url = window.URL.createObjectURL(zipFile);
const link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', response.headers.get('filename')!);
document.body.appendChild(link); // Required for FF
link.click();
window.URL.revokeObjectURL(url);
}
},
() => alert('Unable to export exercise. Please log in to export.')
);
}
public getViews(): number {
return 5;
}
openLink(link: string): void {
window.open(link);
}
/**
* correct missing image urls
*/
correctImageURL(event: Event): void {
if (event.srcElement) {
event.srcElement['src'] = '/content/img/gitLab.png';
}
}
}