Commit b203d4ae authored by El Mghazli Yacine's avatar El Mghazli Yacine

openDialog

parent dfa75798
...@@ -10,20 +10,20 @@ export interface IVariable { ...@@ -10,20 +10,20 @@ export interface IVariable {
modifiable: boolean; //set command ? modifiable: boolean; //set command ?
} }
export enum ILogLvl { // export enum ILogLvl {
error="error", // error="error",
warn="warn", // warn="warn",
analysis="analysis", // analysis="analysis",
info="info", // info="info",
debug="debug", // debug="debug",
trace="trace" // trace="trace"
} // }
export interface ICmdResp { // export interface ICmdResp {
component: string; // component: string;
level: ILogLvl; // level: ILogLvl;
enabled: boolean; // enabled: boolean;
output: string; // output: string;
} // }
export enum IArgType { export enum IArgType {
boolean = "boolean", boolean = "boolean",
...@@ -50,8 +50,8 @@ export class CommandsApi { ...@@ -50,8 +50,8 @@ export class CommandsApi {
public readCommands$ = (moduleName?: string) => this.httpClient.get<ICommand[]>(environment.backend + route + '/' + (moduleName ? ('/' + moduleName) : "") + '/commands/'); public readCommands$ = (moduleName?: string) => this.httpClient.get<ICommand[]>(environment.backend + route + '/' + (moduleName ? ('/' + moduleName) : "") + '/commands/');
public runCommand$ = (command: ICommand, moduleName: string) => this.httpClient.post<ICmdResp[]>(environment.backend + route + '/' + moduleName + '/commands/', command); public runCommand$ = (command: ICommand, moduleName: string) => this.httpClient.post<string[]>(environment.backend + route + '/' + moduleName + '/commands/', command);
public setVariable$ = (variable: IVariable, moduleName?: string) => this.httpClient.post<string>(environment.backend + route + (moduleName ? ('/' + moduleName) : "") + '/variables/', variable); public setVariable$ = (variable: IVariable, moduleName?: string) => this.httpClient.post<string[]>(environment.backend + route + (moduleName ? ('/' + moduleName) : "") + '/variables/', variable);
} }
...@@ -40,17 +40,11 @@ ...@@ -40,17 +40,11 @@
</div> </div>
</div> </div>
<div *ngIf="cmds$ | async as cmds" fxLaypout="column" fxLayoutGap="10px"> <div *ngIf="cmds$ | async as cmds">
<div *ngIf="cmds.length"> <div *ngIf="cmds.length">
<h2 mat-dialog-title>Commands</h2> <h2 mat-dialog-title>Commands</h2>
<div *ngFor="let cmd of cmds"> <div *ngFor="let cmd of cmds" fxLayoutGap="10px">
<!-- <mat-form-field> <button mat-raised-button color="primary" (click)="onCmdSubmit(cmd)"> {{cmd.nameFC.value}} </button>
<mat-label>{{ cmd.nameFC.value }}</mat-label>
<input input matInput [formControl]="cmd.nameFC" />
</mat-form-field> -->
<button mat-raised-button color="primary" (click)="onCmdSubmit(cmd)">
{{cmd.nameFC.value}}
</button>
</div> </div>
</div> </div>
</div> </div>
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { map } from 'rxjs/internal/operators/map'; import { map } from 'rxjs/internal/operators/map';
import { tap } from 'rxjs/internal/operators/tap';
import { CommandsApi, IArgType } from 'src/app/api/commands.api'; import { CommandsApi, IArgType } from 'src/app/api/commands.api';
import { CmdCtrl } from 'src/app/controls/cmd.control'; import { CmdCtrl } from 'src/app/controls/cmd.control';
import { VarCtrl } from 'src/app/controls/var.control'; import { VarCtrl } from 'src/app/controls/var.control';
import { DialogService } from 'src/app/services/dialog.service';
import { LoadingService } from 'src/app/services/loading.service'; import { LoadingService } from 'src/app/services/loading.service';
...@@ -33,6 +33,7 @@ export class CommandsComponent { ...@@ -33,6 +33,7 @@ export class CommandsComponent {
constructor( constructor(
public commandsApi: CommandsApi, public commandsApi: CommandsApi,
public loadingService: LoadingService, public loadingService: LoadingService,
public dialogService: DialogService
) { ) {
this.vars$ = this.commandsApi.readVariables$().pipe( this.vars$ = this.commandsApi.readVariables$().pipe(
map((vars) => vars.map(ivar => new VarCtrl(ivar))) map((vars) => vars.map(ivar => new VarCtrl(ivar)))
...@@ -72,10 +73,22 @@ export class CommandsComponent { ...@@ -72,10 +73,22 @@ export class CommandsComponent {
} }
onSubVarSubmit(control: VarCtrl) { onSubVarSubmit(control: VarCtrl) {
this.commandsApi.setVariable$(control.api(), `${this.selectedModule!.nameFC.value}`).subscribe(); this.commandsApi.setVariable$(control.api(), `${this.selectedModule!.nameFC.value}`)
.pipe(
map(array => this.success('setVariable ' + control.nameFC.value + ' OK', array[0]))
).subscribe();
} }
onCmdSubmit(control: CmdCtrl) { onCmdSubmit(control: CmdCtrl) {
this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`).subscribe(); this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`).pipe(
map(array => this.success('runCommand ' + control.nameFC.value + ' OK', array[0]))
).subscribe();
} }
}
private success = (mess: string, str: string) => this.dialogService.openDialog({
title: mess,
body: str,
});
}
\ No newline at end of file
...@@ -10,21 +10,22 @@ export class ErrorInterceptor implements HttpInterceptor { ...@@ -10,21 +10,22 @@ export class ErrorInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<unknown>, next: HttpHandler) { intercept(request: HttpRequest<unknown>, next: HttpHandler) {
return next.handle(request).pipe( return next.handle(request).pipe(
tap((event: HttpEvent<any>) => { // tap((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) { // if (event instanceof HttpResponse) {
switch (event.status) { // switch (event.status) {
case 201: // case 200:
this.log(GREEN, request.method + ' ' + event.status + ' Success'); // case 201:
this.dialogService.openSnackBar(request.method + ' 201 Success'); // this.log(GREEN, request.method + ' ' + event.status + ' Success');
break; // this.dialogService.openSnackBar(request.method + ' ' + event.status + ' Success');
// break;
default:
break; // default:
} // break;
// }
// return throwError(event.body);
} // // return throwError(event.body);
}), // }
// }),
catchError((error: HttpErrorResponse) => { catchError((error: HttpErrorResponse) => {
switch (error.status) { switch (error.status) {
case 400: case 400:
...@@ -32,7 +33,7 @@ export class ErrorInterceptor implements HttpInterceptor { ...@@ -32,7 +33,7 @@ export class ErrorInterceptor implements HttpInterceptor {
case 501: case 501:
case 500: case 500:
this.log(YELLOW, request.method + ' ' + error.status + ' Error: ' + error.error); this.log(YELLOW, request.method + ' ' + error.status + ' Error: ' + error.error);
this.dialogService.openErrorDialog({ this.dialogService.openDialog({
title: error.status + ' Error', title: error.status + ' Error',
body: error.error, body: error.error,
}); });
......
...@@ -14,7 +14,7 @@ export class DialogService { ...@@ -14,7 +14,7 @@ export class DialogService {
private _snackBar: MatSnackBar, private _snackBar: MatSnackBar,
) { } ) { }
openErrorDialog(data: any): any { openDialog(data: any): any {
if (this.isDialogOpen) { if (this.isDialogOpen) {
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment