2018-02-07 13:16:14 +01:00

54 lines
1.3 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import 'brace/mode/python';
import 'brace/mode/javascript';
import 'brace/theme/monokai';
import { SourceCode } from './source-code';
import { WebSocketService } from '../websocket.service';
const defaultSourceCode = `alert( 'Hello, world!' );`;
@Component({
selector: 'app-webide',
templateUrl: './webide.component.html',
styleUrls: ['./webide.component.scss']
})
export class WebideComponent implements OnInit {
anchor_id = 'anchor_webide';
filename = 'demo.js';
code: string = defaultSourceCode;
language = 'javascript';
theme = 'monokai';
constructor(private webSocketService: WebSocketService) { }
ngOnInit() {
this.webSocketService.observeAnchor<SourceCode>(this.anchor_id).subscribe((event) => {
this.filename = event.data.filename;
this.code = event.data.content;
this.language = event.data.language;
});
this.requestCode();
}
sendCode() {
this.webSocketService.send(this.anchor_id, {
'command': 'write',
'content': this.code
});
}
requestCode() {
this.webSocketService.send(this.anchor_id, {
'command': 'read'
});
}
selectCode() {
this.webSocketService.send(this.anchor_id, {
'command': 'select',
'filename': this.filename
});
}
}