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

display fix

parent 6dc9440b
...@@ -26,18 +26,6 @@ export enum ILogOutput { ...@@ -26,18 +26,6 @@ export enum ILogOutput {
file = "/tmp/<component>.log", file = "/tmp/<component>.log",
} }
export interface IColumn { //should use IVariable ?
name: string;
type: IArgType;
modifiable: boolean; //set command ?
}
export type IRow = string[]
export interface ITable {
columns: IColumn[];
rows: IRow[];
}
export enum IArgType { export enum IArgType {
boolean = "boolean", boolean = "boolean",
list = "list", list = "list",
...@@ -51,6 +39,23 @@ export interface ICommand { ...@@ -51,6 +39,23 @@ export interface ICommand {
confirm?: string; confirm?: string;
} }
export interface IColumn { //should use IVariable ?
name: string;
type: IArgType;
modifiable: boolean; //set command ?
}
export type IRow = string[]
export interface ITable {
columns: IColumn[];
rows: IRow[];
}
export interface IResp {
display: string[],
table?: ITable
}
const route = '/oaisoftmodem'; const route = '/oaisoftmodem';
@Injectable({ @Injectable({
...@@ -63,8 +68,8 @@ export class CommandsApi { ...@@ -63,8 +68,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<ITable>(environment.backend + route + '/' + moduleName + '/commands/', command); public runCommand$ = (command: ICommand, moduleName: string) => this.httpClient.post<IResp>(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<IResp>(environment.backend + route + (moduleName ? ('/' + moduleName) : "") + '/variables/', variable);
} }
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { of } from 'rxjs/internal/observable/of';
import { map } from 'rxjs/internal/operators/map'; import { map } from 'rxjs/internal/operators/map';
import { mergeMap } from 'rxjs/internal/operators/mergeMap'; import { mergeMap } from 'rxjs/internal/operators/mergeMap';
import { CommandsApi, IArgType, IColumn } from 'src/app/api/commands.api'; import { CommandsApi, IArgType, IColumn, ITable } from 'src/app/api/commands.api';
import { CmdCtrl } from 'src/app/controls/cmd.control'; import { CmdCtrl } from 'src/app/controls/cmd.control';
import { RowCtrl } from 'src/app/controls/row.control'; import { RowCtrl } from 'src/app/controls/row.control';
import { VarCtrl } from 'src/app/controls/var.control'; import { VarCtrl } from 'src/app/controls/var.control';
...@@ -83,31 +84,31 @@ export class CommandsComponent { ...@@ -83,31 +84,31 @@ export class CommandsComponent {
onSubVarSubmit(control: VarCtrl) { onSubVarSubmit(control: VarCtrl) {
this.commandsApi.setVariable$(control.api(), `${this.selectedModule!.nameFC.value}`) this.commandsApi.setVariable$(control.api(), `${this.selectedModule!.nameFC.value}`)
.pipe( .pipe(
map(resp => this.success('setVariable ' + control.nameFC.value + ' OK', resp[0])) map(resp => this.dialogService.openRespDialog(resp))
).subscribe(); ).subscribe();
} }
onCmdSubmit(control: CmdCtrl) { onCmdSubmit(control: CmdCtrl) {
// const obs = control.confirm ? this.dialogService.openConfirmDialog(control.confirm) : of(null)
this.rows$ = this.dialogService.openConfirmDialog().pipe( // this.rows$ = obs.pipe(
mergeMap(() => this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`)), // mergeMap(() => this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`)),
map(iresp => {
this.columns = iresp.columns this.rows$ = this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`).pipe(
mergeMap(resp => {
if (resp.display[0]) return this.dialogService.openRespDialog(resp, 'cmd ' + control.nameFC.value + ' response:')
else return of(resp)
}),
map(resp => {
this.columns = resp.table!.columns
this.displayedColumns = this.columns.map(col => col.name) this.displayedColumns = this.columns.map(col => col.name)
let rows: RowCtrl[] = [] let rows: RowCtrl[] = []
iresp.rows.map(row => this.columns.map(col => rows.push(new RowCtrl(row, col.type)))) resp.table?.rows.map(row => this.columns.map(col => rows.push(new RowCtrl(row, col.type))))
return rows return rows
}) })
); );
} }
private success = (mess: string, str: string) => {
return this.dialogService.openDialog({
title: mess,
body: str,
})
};
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ export class VarCtrl extends FormGroup { ...@@ -24,7 +24,7 @@ export class VarCtrl extends FormGroup {
api() { api() {
const doc: IVariable = { const doc: IVariable = {
name: this.nameFC.value, name: this.nameFC.value,
value: this.valueFC.value, value: String(this.valueFC.value), //FIXME
type: this.typeFC.value, type: this.typeFC.value,
modifiable: this.modifiableFC.value modifiable: this.modifiableFC.value
}; };
......
...@@ -33,10 +33,7 @@ export class ErrorInterceptor implements HttpInterceptor { ...@@ -33,10 +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.openDialog({ this.dialogService.openErrorDialog(error);
title: error.status + ' Error',
body: error.error,
});
break; break;
default: default:
......
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { Observable } from 'rxjs/internal/Observable';
import { of } from 'rxjs/internal/observable/of'; import { of } from 'rxjs/internal/observable/of';
import { tap } from 'rxjs/internal/operators/tap'; import { tap } from 'rxjs/internal/operators/tap';
import { IResp } from '../api/commands.api';
import { ConfirmDialogComponent } from '../components/confirm/confirm.component'; import { ConfirmDialogComponent } from '../components/confirm/confirm.component';
import { ErrorDialogComponent } from '../components/error-dialog/error-dialog.component'; import { ErrorDialogComponent } from '../components/error-dialog/error-dialog.component';
...@@ -17,22 +20,44 @@ export class DialogService { ...@@ -17,22 +20,44 @@ export class DialogService {
private _snackBar: MatSnackBar, private _snackBar: MatSnackBar,
) { } ) { }
openDialog(data: any): any { openErrorDialog(error: HttpErrorResponse): Observable<any> {
if (this.isDialogOpen) { if (this.isDialogOpen) {
return false; return of(undefined);
}
this.isDialogOpen = true;
return this._dialog.open(ErrorDialogComponent, {
width: '900px',
data: {
title: error.status + ' Error',
body: error.error,
},
}).afterClosed()
.pipe(tap(() => this.isDialogOpen = false));
}
openRespDialog(resp: IResp, title?: string): Observable<IResp> {
if (this.isDialogOpen || !resp.display.length) {
return of(resp);
} }
this.isDialogOpen = true; this.isDialogOpen = true;
const dialogRef = this._dialog.open(ErrorDialogComponent, { const dialogRef = this._dialog.open(ErrorDialogComponent, {
width: '900px', width: '900px',
data, data: {
title: title,
body: resp.display!.join("</p><p>")
},
}); });
dialogRef.afterClosed().subscribe((_) => { dialogRef.afterClosed().subscribe((_) => {
console.log('The dialog was closed'); console.log('The dialog was closed');
this.isDialogOpen = false; this.isDialogOpen = false;
}); });
return of(resp)
} }
openSnackBar(title: string): void { openSnackBar(title: string): void {
...@@ -43,7 +68,7 @@ export class DialogService { ...@@ -43,7 +68,7 @@ export class DialogService {
}); });
} }
openConfirmDialog() { openConfirmDialog(question: string) {
if (this.isDialogOpen) { if (this.isDialogOpen) {
return of(undefined); return of(undefined);
} }
...@@ -51,7 +76,8 @@ export class DialogService { ...@@ -51,7 +76,8 @@ export class DialogService {
this.isDialogOpen = true; this.isDialogOpen = true;
return this._dialog.open(ConfirmDialogComponent, { return this._dialog.open(ConfirmDialogComponent, {
width: '300px' width: '300px',
data: { title: question }
}) })
.afterClosed() .afterClosed()
.pipe(tap(() => this.isDialogOpen = false)); .pipe(tap(() => this.isDialogOpen = 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