result to screen
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

pull/2/head
Bastien OLLIER 1 year ago
parent 5b4839668d
commit 93395cbe37

@ -14,6 +14,21 @@
</ngx-codemirror>
</div>
<div>
<ngx-codemirror
[options]="{
theme: 'material',
lineNumbers: false,
lineWrapping: false,
mode: mode,
autofocus: true,
readOnly: true
}"
[(ngModel)]="resultContent"
>
</ngx-codemirror>
</div>
<div>
<label for="language">Langage de programmation</label>
<select

@ -34,6 +34,7 @@ export class EditorComponent implements OnInit{
// Contenu de l'éditeur que l'on passera au serveur
editorContent: string = defaults[this.mode];
resultContent: string = defaults[this.mode];
constructor(private router: Router, private codeExecutionService: CodeExecutionService) {}
@ -62,6 +63,11 @@ export class EditorComponent implements OnInit{
onRunButtonClicked() {
// Le code à exécuter est le contenu de l'éditeur
const codeToExecute = this.editorContent;
this.codeExecutionService.executeCode(codeToExecute, this.mode);
this.codeExecutionService.getResult().subscribe(result => {
this.resultContent = decodeURIComponent(result.replace(/%00/g, ''));
});
}
}

@ -1,12 +1,14 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { SSE } from 'sse.js';
import { Observable, Subject } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class CodeExecutionService {
private apiUrl = 'http://localhost:3000/run'; // Url du serveur Node.js en local
private apiUrl = 'http://localhost:3000/run';
private resultSubject = new Subject<string>();
constructor(private http: HttpClient) {}
@ -19,8 +21,17 @@ export class CodeExecutionService {
},
payload: JSON.stringify({ code, language }),
});
sse.addEventListener('message', (event: MessageEvent<string>) => {
console.log(event.data);
const result = event.data;
console.log(result);
// Émettre le résultat à tous les abonnés
this.resultSubject.next(result);
});
}
getResult(): Observable<string> {
return this.resultSubject.asObservable();
}
}

Loading…
Cancel
Save