Skip to content
Snippets Groups Projects
ghci.service.ts 13.56 KiB
import { Injectable,ViewChild,ElementRef } from '@angular/core';
import { Observable, Subject } from 'rxjs/Rx';
import { WebsocketService } from './websocket.service';
import { AuthenticationService } from './authentication.service';
import { GHCI_URL } from '../config';

declare var $:any;
declare var that :any ;
const regex = /^color (errores|input|output|logs) (\d)$/g;

import 'tippy.js/dist/tippy';

@Injectable()
export class GHCIService {
	public messages: Subject<any> = new Subject<any>();
	private connection = undefined;
	private cons = undefined;
	private modoAvanzado: boolean = false;     // indica si debe mostrarse todo lo que ocurre en el intérprete.
	private clear:boolean = false;
	private error :string ="";
	private warnings: any = [];
	private codemirrorRef :any = null;
	private warningStepReaded :number = 0;
	private waitingForError : boolean = false;
	private waitingForWarning : boolean = false;
	private waitingForWarning2 : boolean = false;
	private warningText :string = "";
	private lastError : number = -1;
	private lastWarning :number = -1;

	private console_error_class : string = "jqconsole-asd";

	consoleBuffer = [];

	constructor(private authService:AuthenticationService){
		console.log("contructor ghci");
		this.conectarWS(GHCI_URL, authService.getUser().cedula, authService.getToken());
		setInterval( this.checkConnection.bind(this), 5000);	
		setInterval( this.doPing.bind(this), 30000);	
	}

	setCodemirrorRef(instance){
		this.codemirrorRef = instance;
	}

	clearWarnings(){
		this.warnings = [];
	}

	getWarnings(){
		return this.warnings;
	}

	loadFile(fileId, dependencias) {
		this.waitingForWarning = true;
		var message = {
			'token': this.authService.getToken(),
			'load': fileId,
			'dependencias' :[]

		};
		for(var i in dependencias){
			message.dependencias.push(dependencias[i]);
		};
		this.connection.send(JSON.stringify(message));
	}
	copyFile(fileId){
		var message = {
			'token': this.authService.getToken(),
			'copy': fileId