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

display fix

parent 6dc9440b
......@@ -26,18 +26,6 @@ export enum ILogOutput {
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 {
boolean = "boolean",
list = "list",
......@@ -51,6 +39,23 @@ export interface ICommand {
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';
@Injectable({
......@@ -63,8 +68,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<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 { Observable } from 'rxjs/internal/Observable';
import { of } from 'rxjs/internal/observable/of';
import { map } from 'rxjs/internal/operators/map';
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 { RowCtrl } from 'src/app/controls/row.control';
import { VarCtrl } from 'src/app/controls/var.control';
......@@ -83,31 +84,31 @@ export class CommandsComponent {
onSubVarSubmit(control: VarCtrl) {
this.commandsApi.setVariable$(control.api(), `${this.selectedModule!.nameFC.value}`)
.pipe(
map(resp => this.success('setVariable ' + control.nameFC.value + ' OK', resp[0]))
map(resp => this.dialogService.openRespDialog(resp))
).subscribe();
}
onCmdSubmit(control: CmdCtrl) {
// const obs = control.confirm ? this.dialogService.openConfirmDialog(control.confirm) : of(null)
this.rows$ = this.dialogService.openConfirmDialog().pipe(
mergeMap(() => this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`)),
map(iresp => {
this.columns = iresp.columns
// this.rows$ = obs.pipe(
// mergeMap(() => this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`)),
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)
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
})
);
}
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 {
api() {
const doc: IVariable = {
name: this.nameFC.value,
value: this.valueFC.value,
value: String(this.valueFC.value), //FIXME
type: this.typeFC.value,
modifiable: this.modifiableFC.value
};
......
......@@ -33,10 +33,7 @@ export class ErrorInterceptor implements HttpInterceptor {
case 501:
case 500:
this.log(YELLOW, request.method + ' ' + error.status + ' Error: ' + error.error);
this.dialogService.openDialog({
title: error.status + ' Error',
body: error.error,
});
this.dialogService.openErrorDialog(error);
break;
default:
......
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Observable } from 'rxjs/internal/Observable';
import { of } from 'rxjs/internal/observable/of';
import { tap } from 'rxjs/internal/operators/tap';
import { IResp } from '../api/commands.api';
import { ConfirmDialogComponent } from '../components/confirm/confirm.component';
import { ErrorDialogComponent } from '../components/error-dialog/error-dialog.component';
......@@ -17,22 +20,44 @@ export class DialogService {
private _snackBar: MatSnackBar,
) { }
openDialog(data: any): any {
openErrorDialog(error: HttpErrorResponse): Observable<any> {
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;
const dialogRef = this._dialog.open(ErrorDialogComponent, {
width: '900px',
data,
data: {
title: title,
body: resp.display!.join("</p><p>")
},
});
dialogRef.afterClosed().subscribe((_) => {
console.log('The dialog was closed');
this.isDialogOpen = false;
});
return of(resp)
}
openSnackBar(title: string): void {
......@@ -43,7 +68,7 @@ export class DialogService {
});
}
openConfirmDialog() {
openConfirmDialog(question: string) {
if (this.isDialogOpen) {
return of(undefined);
}
......@@ -51,7 +76,8 @@ export class DialogService {
this.isDialogOpen = true;
return this._dialog.open(ConfirmDialogComponent, {
width: '300px'
width: '300px',
data: { title: question }
})
.afterClosed()
.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