Add notification service for deployment status and blur login page when neccesary

This commit is contained in:
Gabor PEK 2018-03-12 14:50:44 +01:00
parent fcb5d6ecf0
commit 8f4a6fd83e
5 changed files with 61 additions and 28 deletions

View File

@ -20,6 +20,7 @@ import { FSMUpdateService } from './services/fsmupdate.service';
import {ProcessManagerService} from './services/processmanager.service';
import {AppRoutingModule} from './app-routing.module';
import {TestmessengerComponent} from './testmessenger/testmessenger.component';
import {DeploymentNotificationService} from './services/deployment-notification.service';
@NgModule({
@ -46,7 +47,8 @@ import { TestmessengerComponent } from './testmessenger/testmessenger.component'
WebSocketService,
TerminadoService,
FSMUpdateService,
ProcessManagerService
ProcessManagerService,
DeploymentNotificationService
],
bootstrap: [
AppComponent

View File

@ -1,4 +1,4 @@
<div [class.deploy-blur]="deployButtonState === 'DEPLOYING'">
<div [ngClass]="{ 'deploy-blur': deploying }">
<h1>Login page</h1>
<form #loginForm="ngForm" (submit)="onSubmit()" [hidden]="submitted">
<div class="form-group">

View File

@ -1,21 +1,28 @@
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 { Login } from './login';
import {DeploymentNotificationService} from '../services/deployment-notification.service';
import {Subscription} from 'rxjs/Subscription';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
export class LoginComponent implements OnInit, OnDestroy {
model = new Login('', '');
submitted = false;
is_admin: boolean;
logged_in_email: string;
deploying = false;
deploymentNotificationSubscription: Subscription;
constructor(
private http: HttpClient
private http: HttpClient,
private deploymentNotificationService: DeploymentNotificationService
) {}
onSubmit() {
this.postLogin(this.model).subscribe(
res => {
@ -30,5 +37,15 @@ export class LoginComponent implements OnInit {
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();
}
}
}

View 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() { }
}

View File

@ -15,6 +15,7 @@ import 'brace/theme/cobalt';
import { SourceCode } from './source-code';
import { WebSocketService } from '../services/websocket.service';
import { ProcessManagerService } from '../services/processmanager.service';
import {DeploymentNotificationService} from '../services/deployment-notification.service';
const modelist = brace.acequire('ace/ext/modelist');
@ -43,7 +44,8 @@ export class WebideComponent implements OnInit {
constructor(private webSocketService: WebSocketService,
private changeDetectorRef: ChangeDetectorRef,
private processManagerService: ProcessManagerService) { }
private processManagerService: ProcessManagerService,
private deploymentNotificationService: DeploymentNotificationService) { }
ngOnInit() {
this.webSocketService.connect();
@ -109,11 +111,12 @@ export class WebideComponent implements OnInit {
setDeployButtonState(state: string) {
this.deployButtonState = state;
this.deploymentNotificationService.deploying.next(state === 'DEPLOYING' ? true : false);
}
deployCode() {
this.processManagerService.restartProcess('login');
this.deployButtonState = 'DEPLOYING';
this.setDeployButtonState('DEPLOYING');
}
sendCodeIfDirty() {