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

openDialog

parent dfa75798
......@@ -10,20 +10,20 @@ export interface IVariable {
modifiable: boolean; //set command ?
}
export enum ILogLvl {
error="error",
warn="warn",
analysis="analysis",
info="info",
debug="debug",
trace="trace"
}
export interface ICmdResp {
component: string;
level: ILogLvl;
enabled: boolean;
output: string;
}
// export enum ILogLvl {
// error="error",
// warn="warn",
// analysis="analysis",
// info="info",
// debug="debug",
// trace="trace"
// }
// export interface ICmdResp {
// component: string;
// level: ILogLvl;
// enabled: boolean;
// output: string;
// }
export enum IArgType {
boolean = "boolean",
......@@ -50,8 +50,8 @@ export class CommandsApi {
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 @@
</div>
</div>
<div *ngIf="cmds$ | async as cmds" fxLaypout="column" fxLayoutGap="10px">
<div *ngIf="cmds$ | async as cmds">
<div *ngIf="cmds.length">
<h2 mat-dialog-title>Commands</h2>
<div *ngFor="let cmd of cmds">
<!-- <mat-form-field>
<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 *ngFor="let cmd of cmds" fxLayoutGap="10px">
<button mat-raised-button color="primary" (click)="onCmdSubmit(cmd)"> {{cmd.nameFC.value}} </button>
</div>
</div>
</div>
......
import { Component } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { map } from 'rxjs/internal/operators/map';
import { tap } from 'rxjs/internal/operators/tap';
import { CommandsApi, IArgType } from 'src/app/api/commands.api';
import { CmdCtrl } from 'src/app/controls/cmd.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';
......@@ -33,6 +33,7 @@ export class CommandsComponent {
constructor(
public commandsApi: CommandsApi,
public loadingService: LoadingService,
public dialogService: DialogService
) {
this.vars$ = this.commandsApi.readVariables$().pipe(
map((vars) => vars.map(ivar => new VarCtrl(ivar)))
......@@ -72,10 +73,22 @@ export class CommandsComponent {
}
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) {
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 {
intercept(request: HttpRequest<unknown>, next: HttpHandler) {
return next.handle(request).pipe(
tap((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
switch (event.status) {
case 201:
this.log(GREEN, request.method + ' ' + event.status + ' Success');
this.dialogService.openSnackBar(request.method + ' 201 Success');
break;
default:
break;
}
// return throwError(event.body);
}
}),
// tap((event: HttpEvent<any>) => {
// if (event instanceof HttpResponse) {
// switch (event.status) {
// case 200:
// case 201:
// this.log(GREEN, request.method + ' ' + event.status + ' Success');
// this.dialogService.openSnackBar(request.method + ' ' + event.status + ' Success');
// break;
// default:
// break;
// }
// // return throwError(event.body);
// }
// }),
catchError((error: HttpErrorResponse) => {
switch (error.status) {
case 400:
......@@ -32,7 +33,7 @@ export class ErrorInterceptor implements HttpInterceptor {
case 501:
case 500:
this.log(YELLOW, request.method + ' ' + error.status + ' Error: ' + error.error);
this.dialogService.openErrorDialog({
this.dialogService.openDialog({
title: error.status + ' Error',
body: error.error,
});
......
......@@ -14,7 +14,7 @@ export class DialogService {
private _snackBar: MatSnackBar,
) { }
openErrorDialog(data: any): any {
openDialog(data: any): any {
if (this.isDialogOpen) {
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