mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:31:33 +00:00
Implement solution check forwarding
This commit is contained in:
parent
43e43b061d
commit
57db977873
@ -24,8 +24,9 @@ import {
|
||||
ConfigReadyService,
|
||||
IdeConfigService,
|
||||
DashboardConfigService,
|
||||
SiteConfigService
|
||||
SiteConfigService,
|
||||
} from './services/config.service';
|
||||
import { FSMUpdateService } from './services/fsmupdate.service';
|
||||
import { LoaderComponent } from './loader/loader.component';
|
||||
|
||||
|
||||
@ -59,7 +60,8 @@ import { LoaderComponent } from './loader/loader.component';
|
||||
ConfigReadyService,
|
||||
IdeConfigService,
|
||||
DashboardConfigService,
|
||||
SiteConfigService
|
||||
SiteConfigService,
|
||||
FSMUpdateService
|
||||
],
|
||||
bootstrap: [
|
||||
AppComponent
|
||||
|
@ -22,7 +22,7 @@ export class ConsoleComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.webSocketService.connect();
|
||||
this.webSocketService.observeKey<WebSocketMessage>('console').subscribe(
|
||||
this.webSocketService.observeControl<WebSocketMessage>('console').subscribe(
|
||||
message => this.command_handlers[message.key](message)
|
||||
);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import { WebSocketMessage } from '../message-types/websocket-message';
|
||||
import { DashboardConfigService } from '../services/config.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { delay, retryWhen, tap } from 'rxjs/operators';
|
||||
import { FSMUpdateService } from '../services/fsmupdate.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
@ -37,11 +38,13 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
private webSocketService: WebSocketService,
|
||||
private changeDetectorRef: ChangeDetectorRef,
|
||||
private http: HttpClient,
|
||||
private configService: DashboardConfigService) {}
|
||||
private configService: DashboardConfigService,
|
||||
private fsmUpdateService: FSMUpdateService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.webSocketService.connect();
|
||||
this.configService.init();
|
||||
this.subscribeCheckSolution();
|
||||
this.hideIframeUntilResponseOk();
|
||||
this.subscribeResizeOnLayoutChange();
|
||||
this.initCommandHandling();
|
||||
@ -49,6 +52,15 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
this.sendReady();
|
||||
}
|
||||
|
||||
subscribeCheckSolution() {
|
||||
this.fsmUpdateService.init();
|
||||
this.fsmUpdateService.in_accepted_state.subscribe(in_accepted_state => {
|
||||
if (in_accepted_state) {
|
||||
window.parent.postMessage('check solution', '*');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
hideIframeUntilResponseOk() {
|
||||
// TODO: hide iframe and show it after this whole deal...
|
||||
this.reloadIframeWhenResponseOk();
|
||||
@ -62,7 +74,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
initCommandHandling() {
|
||||
this.webSocketService.observeKey<WebSocketMessage>('dashboard').subscribe(message => {
|
||||
this.webSocketService.observeControl<WebSocketMessage>('dashboard').subscribe(message => {
|
||||
this.command_handlers[message.key](message);
|
||||
this.changeDetectorRef.detectChanges();
|
||||
});
|
||||
|
@ -67,18 +67,18 @@ export class IdeComponent implements OnInit {
|
||||
}
|
||||
|
||||
subscribeWS() {
|
||||
this.webSocketService.observeKey<WebSocketMessage>('ide').subscribe(message => {
|
||||
this.webSocketService.observeControl<WebSocketMessage>('ide').subscribe(message => {
|
||||
this.command_handlers[message.key](message);
|
||||
this.changeDetectorRef.detectChanges();
|
||||
});
|
||||
|
||||
this.webSocketService.observeKey<DeployMessage>('deploy.finish').subscribe(
|
||||
this.webSocketService.observeControl<DeployMessage>('deploy.finish').subscribe(
|
||||
message => this.deployHandler(message)
|
||||
);
|
||||
}
|
||||
|
||||
subscribeFirstLanguageDetection() {
|
||||
this.webSocketService.observeKey<IDEMessage>('ide.read').pipe(first()).subscribe(
|
||||
this.webSocketService.observeControl<IDEMessage>('ide.read').pipe(first()).subscribe(
|
||||
() => this.autoDetectEditorLanguage(this.filename)
|
||||
);
|
||||
}
|
||||
|
6
src/app/message-types/fsm-update-message.ts
Normal file
6
src/app/message-types/fsm-update-message.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { WebSocketMessage } from './websocket-message';
|
||||
|
||||
export interface FSMUpdateMessage extends WebSocketMessage {
|
||||
current_state: string;
|
||||
in_accepted_state: boolean;
|
||||
}
|
@ -30,7 +30,7 @@ export class MessagesComponent implements OnInit {
|
||||
});
|
||||
|
||||
this.websocketService.connect();
|
||||
this.websocketService.observeKey<Message>('message.send').subscribe(
|
||||
this.websocketService.observeControl<Message>('message.send').subscribe(
|
||||
message => this.newMessage.next(message)
|
||||
);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ export abstract class ConfigServiceBase {
|
||||
subscribeConfigKeys() {
|
||||
this.webSocketService.connect();
|
||||
this.keys.forEach(key =>
|
||||
this.webSocketService.observeKey<any>(key).subscribe(this.handleConfig.bind(this))
|
||||
this.webSocketService.observeControl<any>(key).subscribe(this.handleConfig.bind(this))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ export class ConfigReadyService {
|
||||
|
||||
const recvdConfigDone = new Subject<void>();
|
||||
this.readyNotifiers.push(recvdConfigDone);
|
||||
this.webSocketService.observeKey<any>('frontend.ready').subscribe(() => {
|
||||
this.webSocketService.observeControl<any>('frontend.ready').subscribe(() => {
|
||||
recvdConfigDone.next();
|
||||
recvdConfigDone.complete();
|
||||
});
|
||||
|
20
src/app/services/fsmupdate.service.ts
Normal file
20
src/app/services/fsmupdate.service.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { WebSocketService } from './websocket.service';
|
||||
import { FSMUpdateMessage } from '../message-types/fsm-update-message';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class FSMUpdateService {
|
||||
public current_state = new Subject<string>();
|
||||
public in_accepted_state = new Subject<boolean>();
|
||||
|
||||
constructor(private websocketService: WebSocketService) {}
|
||||
|
||||
public init() {
|
||||
this.websocketService.connect();
|
||||
this.websocketService.observeAll<FSMUpdateMessage>('fsm.update').subscribe((message) => {
|
||||
this.current_state.next(message.current_state);
|
||||
this.in_accepted_state.next(message.in_accepted_state);
|
||||
});
|
||||
}
|
||||
}
|
@ -28,10 +28,15 @@ export class WebSocketService {
|
||||
}
|
||||
}
|
||||
|
||||
public observeKey<T extends WebSocketMessage>(key: string): Observable<T> {
|
||||
public observeControl<T extends WebSocketMessage>(key: string): Observable<T> {
|
||||
return this.observeAll<T>(key).pipe(
|
||||
filter(message => message.intent !== Intent.EVENT)
|
||||
);
|
||||
}
|
||||
|
||||
public observeAll<T extends WebSocketMessage>(key: string): Observable<T> {
|
||||
return this.ws.pipe(
|
||||
filter(message => message.key.startsWith(key)),
|
||||
filter(message => message.intent !== Intent.EVENT),
|
||||
map(message => <T> message)
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export class TestmessengerComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.webSocketService.connect();
|
||||
this.webSocketService.observeKey('').subscribe();
|
||||
this.webSocketService.observeControl('').subscribe();
|
||||
}
|
||||
|
||||
sendTestMessage() {
|
||||
|
Loading…
Reference in New Issue
Block a user