mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 09:22:56 +00:00 
			
		
		
		
	Add notification service for deployment status and blur login page when neccesary
This commit is contained in:
		@@ -1,25 +1,26 @@
 | 
				
			|||||||
import { HttpClientModule } from '@angular/common/http';
 | 
					import {HttpClientModule} from '@angular/common/http';
 | 
				
			||||||
import { FormsModule } from '@angular/forms';
 | 
					import {FormsModule} from '@angular/forms';
 | 
				
			||||||
import { BrowserModule } from '@angular/platform-browser';
 | 
					import {BrowserModule} from '@angular/platform-browser';
 | 
				
			||||||
import { NgModule } from '@angular/core';
 | 
					import {NgModule} from '@angular/core';
 | 
				
			||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
 | 
					import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
 | 
				
			||||||
import { AceEditorModule } from 'ng2-ace-editor';
 | 
					import {AceEditorModule} from 'ng2-ace-editor';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { AppComponent } from './app.component';
 | 
					import {AppComponent} from './app.component';
 | 
				
			||||||
import { DashboardComponent } from './dashboard/dashboard.component';
 | 
					import {DashboardComponent} from './dashboard/dashboard.component';
 | 
				
			||||||
import { HeaderComponent } from './header/header.component';
 | 
					import {HeaderComponent} from './header/header.component';
 | 
				
			||||||
import { LoginComponent } from './login/login.component';
 | 
					import {LoginComponent} from './login/login.component';
 | 
				
			||||||
import { MarkdownService } from './services/markdown.service';
 | 
					import {MarkdownService} from './services/markdown.service';
 | 
				
			||||||
import { TerminadoService } from './services/terminado.service';
 | 
					import {TerminadoService} from './services/terminado.service';
 | 
				
			||||||
import { WebideComponent } from './webide/webide.component';
 | 
					import {WebideComponent} from './webide/webide.component';
 | 
				
			||||||
import { MessagesComponent } from './messages/messages.component';
 | 
					import {MessagesComponent} from './messages/messages.component';
 | 
				
			||||||
import { WebSocketService } from './services/websocket.service';
 | 
					import {WebSocketService} from './services/websocket.service';
 | 
				
			||||||
import { TerminalComponent } from './terminal/terminal.component';
 | 
					import {TerminalComponent} from './terminal/terminal.component';
 | 
				
			||||||
import { FSMUpdateService } from './services/fsmupdate.service';
 | 
					import {FSMUpdateService} from './services/fsmupdate.service';
 | 
				
			||||||
import { ProcessManagerService } from './services/processmanager.service';
 | 
					import {ProcessManagerService} from './services/processmanager.service';
 | 
				
			||||||
import { AppRoutingModule } from './app-routing.module';
 | 
					import {AppRoutingModule} from './app-routing.module';
 | 
				
			||||||
import { TestmessengerComponent } from './testmessenger/testmessenger.component';
 | 
					import {TestmessengerComponent} from './testmessenger/testmessenger.component';
 | 
				
			||||||
 | 
					import {DeploymentNotificationService} from './services/deployment-notification.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@NgModule({
 | 
					@NgModule({
 | 
				
			||||||
@@ -46,7 +47,8 @@ import { TestmessengerComponent } from './testmessenger/testmessenger.component'
 | 
				
			|||||||
    WebSocketService,
 | 
					    WebSocketService,
 | 
				
			||||||
    TerminadoService,
 | 
					    TerminadoService,
 | 
				
			||||||
    FSMUpdateService,
 | 
					    FSMUpdateService,
 | 
				
			||||||
    ProcessManagerService
 | 
					    ProcessManagerService,
 | 
				
			||||||
 | 
					    DeploymentNotificationService
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  bootstrap: [
 | 
					  bootstrap: [
 | 
				
			||||||
    AppComponent
 | 
					    AppComponent
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
<div [class.deploy-blur]="deployButtonState === 'DEPLOYING'">
 | 
					<div [ngClass]="{ 'deploy-blur': deploying }">
 | 
				
			||||||
  <h1>Login page</h1>
 | 
					  <h1>Login page</h1>
 | 
				
			||||||
  <form #loginForm="ngForm" (submit)="onSubmit()" [hidden]="submitted">
 | 
					  <form #loginForm="ngForm" (submit)="onSubmit()" [hidden]="submitted">
 | 
				
			||||||
    <div class="form-group">
 | 
					    <div class="form-group">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,21 +1,28 @@
 | 
				
			|||||||
import { HttpClient } from '@angular/common/http';
 | 
					import { HttpClient } from '@angular/common/http';
 | 
				
			||||||
import { Component, OnInit } from '@angular/core';
 | 
					import {Component, OnDestroy, OnInit} from '@angular/core';
 | 
				
			||||||
import { Observable } from 'rxjs/Observable';
 | 
					import { Observable } from 'rxjs/Observable';
 | 
				
			||||||
import { Login } from './login';
 | 
					import { Login } from './login';
 | 
				
			||||||
 | 
					import {DeploymentNotificationService} from '../services/deployment-notification.service';
 | 
				
			||||||
 | 
					import {Subscription} from 'rxjs/Subscription';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'app-login',
 | 
					  selector: 'app-login',
 | 
				
			||||||
  templateUrl: './login.component.html',
 | 
					  templateUrl: './login.component.html',
 | 
				
			||||||
  styleUrls: ['./login.component.scss']
 | 
					  styleUrls: ['./login.component.scss']
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class LoginComponent implements OnInit {
 | 
					export class LoginComponent implements OnInit, OnDestroy {
 | 
				
			||||||
  model = new Login('', '');
 | 
					  model = new Login('', '');
 | 
				
			||||||
  submitted = false;
 | 
					  submitted = false;
 | 
				
			||||||
  is_admin: boolean;
 | 
					  is_admin: boolean;
 | 
				
			||||||
  logged_in_email: string;
 | 
					  logged_in_email: string;
 | 
				
			||||||
 | 
					  deploying = false;
 | 
				
			||||||
 | 
					  deploymentNotificationSubscription: Subscription;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    private http: HttpClient
 | 
					    private http: HttpClient,
 | 
				
			||||||
 | 
					    private deploymentNotificationService: DeploymentNotificationService
 | 
				
			||||||
  ) {}
 | 
					  ) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onSubmit() {
 | 
					  onSubmit() {
 | 
				
			||||||
    this.postLogin(this.model).subscribe(
 | 
					    this.postLogin(this.model).subscribe(
 | 
				
			||||||
      res => {
 | 
					      res => {
 | 
				
			||||||
@@ -30,5 +37,15 @@ export class LoginComponent implements OnInit {
 | 
				
			|||||||
    return this.http.post<Login>('/login', login);
 | 
					    return this.http.post<Login>('/login', login);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {}
 | 
					  ngOnInit() {
 | 
				
			||||||
 | 
					    this.deploymentNotificationSubscription = this.deploymentNotificationService.deploying.subscribe(
 | 
				
			||||||
 | 
					      (deploying) => this.deploying = deploying
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ngOnDestroy() {
 | 
				
			||||||
 | 
					    if (this.deploymentNotificationSubscription) {
 | 
				
			||||||
 | 
					      this.deploymentNotificationSubscription.unsubscribe();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								src/app/services/deployment-notification.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/app/services/deployment-notification.service.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					import {Injectable} from '@angular/core';
 | 
				
			||||||
 | 
					import {Subject} from 'rxjs/Subject';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Injectable()
 | 
				
			||||||
 | 
					export class DeploymentNotificationService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  deploying: Subject<boolean> = new Subject<boolean>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  constructor() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -15,6 +15,7 @@ import 'brace/theme/cobalt';
 | 
				
			|||||||
import { SourceCode } from './source-code';
 | 
					import { SourceCode } from './source-code';
 | 
				
			||||||
import { WebSocketService } from '../services/websocket.service';
 | 
					import { WebSocketService } from '../services/websocket.service';
 | 
				
			||||||
import { ProcessManagerService } from '../services/processmanager.service';
 | 
					import { ProcessManagerService } from '../services/processmanager.service';
 | 
				
			||||||
 | 
					import {DeploymentNotificationService} from '../services/deployment-notification.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const modelist = brace.acequire('ace/ext/modelist');
 | 
					const modelist = brace.acequire('ace/ext/modelist');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -43,7 +44,8 @@ export class WebideComponent implements OnInit {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  constructor(private webSocketService: WebSocketService,
 | 
					  constructor(private webSocketService: WebSocketService,
 | 
				
			||||||
              private changeDetectorRef: ChangeDetectorRef,
 | 
					              private changeDetectorRef: ChangeDetectorRef,
 | 
				
			||||||
              private processManagerService: ProcessManagerService) { }
 | 
					              private processManagerService: ProcessManagerService,
 | 
				
			||||||
 | 
					              private deploymentNotificationService: DeploymentNotificationService) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.webSocketService.connect();
 | 
					    this.webSocketService.connect();
 | 
				
			||||||
@@ -109,11 +111,12 @@ export class WebideComponent implements OnInit {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  setDeployButtonState(state: string) {
 | 
					  setDeployButtonState(state: string) {
 | 
				
			||||||
    this.deployButtonState = state;
 | 
					    this.deployButtonState = state;
 | 
				
			||||||
 | 
					    this.deploymentNotificationService.deploying.next(state === 'DEPLOYING' ? true : false);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  deployCode() {
 | 
					  deployCode() {
 | 
				
			||||||
    this.processManagerService.restartProcess('login');
 | 
					    this.processManagerService.restartProcess('login');
 | 
				
			||||||
    this.deployButtonState = 'DEPLOYING';
 | 
					    this.setDeployButtonState('DEPLOYING');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sendCodeIfDirty() {
 | 
					  sendCodeIfDirty() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user