result to screen (#2)
continuous-integration/drone/push Build is passing Details

please, peer review my code

Co-authored-by: bastien ollier <bastien.ollier@etu.uca.fr>
Co-authored-by: clfreville2 <clement.freville2@etu.uca.fr>
Reviewed-on: #2
Reviewed-by: Clément FRÉVILLE <clement.freville2@etu.uca.fr>
Co-authored-by: Bastien OLLIER <bastien.ollier@noreply.codefirst.iut.uca.fr>
Co-committed-by: Bastien OLLIER <bastien.ollier@noreply.codefirst.iut.uca.fr>
pull/4/head
Bastien OLLIER 1 year ago committed by Clément FRÉVILLE
parent e6516aa240
commit a17d97c050

@ -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 = result;
});
}
}

@ -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;
// Émettre le résultat à tous les abonnés
const text = decodeURIComponent(result.replace(/%00/g, ''));
this.resultSubject.next(text);
});
}
getResult(): Observable<string> {
return this.resultSubject.asObservable();
}
}

Loading…
Cancel
Save