mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 05:32:55 +00:00 
			
		
		
		
	Merge pull request #1 from avatao-content/fsmupdate
Implement service to monitor backend FSM state
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
				
			|||||||
import { Component, OnInit } from '@angular/core';
 | 
					import { Component, OnInit } from '@angular/core';
 | 
				
			||||||
import { WebSocketService } from './websocket.service';
 | 
					import { WebSocketService } from './websocket.service';
 | 
				
			||||||
 | 
					import { FSMUpdateService } from './fsmupdate.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'app-root',
 | 
					  selector: 'app-root',
 | 
				
			||||||
@@ -9,10 +10,11 @@ import { WebSocketService } from './websocket.service';
 | 
				
			|||||||
export class AppComponent implements OnInit {
 | 
					export class AppComponent implements OnInit {
 | 
				
			||||||
  title = 'app';
 | 
					  title = 'app';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(private webSocketService: WebSocketService) {}
 | 
					  constructor(private webSocketService: WebSocketService, private fsmUpdateService: FSMUpdateService) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.webSocketService.connect();
 | 
					    this.webSocketService.connect();
 | 
				
			||||||
    this.webSocketService.send('reset', '');
 | 
					    this.webSocketService.send('reset', '');
 | 
				
			||||||
 | 
					    this.fsmUpdateService.init();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,7 @@ import { LogsComponent } from './logs/logs.component';
 | 
				
			|||||||
import { TestButtonComponent } from './test-button/test-button.component';
 | 
					import { TestButtonComponent } from './test-button/test-button.component';
 | 
				
			||||||
import { WebSocketService } from './websocket.service';
 | 
					import { WebSocketService } from './websocket.service';
 | 
				
			||||||
import { TerminalComponent } from './terminal/terminal.component';
 | 
					import { TerminalComponent } from './terminal/terminal.component';
 | 
				
			||||||
 | 
					import { FSMUpdateService } from './fsmupdate.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@NgModule({
 | 
					@NgModule({
 | 
				
			||||||
@@ -38,7 +39,8 @@ import { TerminalComponent } from './terminal/terminal.component';
 | 
				
			|||||||
  providers: [
 | 
					  providers: [
 | 
				
			||||||
    MarkdownService,
 | 
					    MarkdownService,
 | 
				
			||||||
    WebSocketService,
 | 
					    WebSocketService,
 | 
				
			||||||
    TerminadoService
 | 
					    TerminadoService,
 | 
				
			||||||
 | 
					    FSMUpdateService
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  bootstrap: [
 | 
					  bootstrap: [
 | 
				
			||||||
    AppComponent
 | 
					    AppComponent
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								src/app/fsmupdate.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/app/fsmupdate.service.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					import { Injectable } from '@angular/core';
 | 
				
			||||||
 | 
					import { WebSocketService } from './websocket.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class FSMUpdate {
 | 
				
			||||||
 | 
					  current_state: string;
 | 
				
			||||||
 | 
					  valid_transitions: object;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Injectable()
 | 
				
			||||||
 | 
					export class FSMUpdateService {
 | 
				
			||||||
 | 
					  public current_state: string;
 | 
				
			||||||
 | 
					  public valid_transitions: object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  constructor(private websocketservice: WebSocketService) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public init(): void {
 | 
				
			||||||
 | 
					    this.websocketservice.observeAnchor<FSMUpdate>('FSMUpdate').subscribe((event) => {
 | 
				
			||||||
 | 
					      this.current_state = event.data.current_state;
 | 
				
			||||||
 | 
					      this.valid_transitions = event.data.valid_transitions;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user