Commit 9d2b7475 authored by El Mghazli Yacine's avatar El Mghazli Yacine

Merge branch 'websrv-table' into websrv

parents 12099a91 2761d013
...@@ -26,13 +26,6 @@ export enum ILogOutput { ...@@ -26,13 +26,6 @@ export enum ILogOutput {
file = "/tmp/<component>.log", file = "/tmp/<component>.log",
} }
export interface ILog {
component: string;
level: ILogLvl;
output: ILogOutput;
enabled: boolean;
}
export interface IColumn { //should use IVariable ? export interface IColumn { //should use IVariable ?
name: string; name: string;
type: IArgType; type: IArgType;
...@@ -45,11 +38,6 @@ export interface ITable { ...@@ -45,11 +38,6 @@ export interface ITable {
rows: IRow[]; rows: IRow[];
} }
export interface IResp {
display: string[],
logs?: ILog[]
}
export enum IArgType { export enum IArgType {
boolean = "boolean", boolean = "boolean",
list = "list", list = "list",
...@@ -75,7 +63,7 @@ export class CommandsApi { ...@@ -75,7 +63,7 @@ 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<IResp>(environment.backend + route + '/' + moduleName + '/commands/', command); public runCommand$ = (command: ICommand, moduleName: string) => this.httpClient.post<ITable>(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);
......
...@@ -50,59 +50,31 @@ ...@@ -50,59 +50,31 @@
</div> </div>
<mat-table *ngIf="logs$ | async as logs" mat-table [dataSource]="logs" multiTemplateDataRows class="mat-elevation-z8"> <mat-table mat-table [dataSource]="rows$" multiTemplateDataRows class="mat-elevation-z8">
<!-- For anyone who has set the multiTemplateDataRows property of mat-table to true, <!-- For anyone who has set the multiTemplateDataRows property of mat-table to true,
you can't use index. Instead you have use either dataIndex or renderIndex. you can't use index. Instead you have use either dataIndex or renderIndex.
See https://github.com/angular/material2/issues/12793 --> See https://github.com/angular/material2/issues/12793 -->
<div matColumnDef="component"> <div *ngFor="let col of columns; index as colIndex" matColumnDef="{{col.name}}">
<mat-header-cell *matHeaderCellDef> Component <mat-header-cell *matHeaderCellDef>
</mat-header-cell> <div>
<mat-cell *matCellDef="let log"> <h4>{{ col.name }}</h4>
<div fxLayout="row" fxLayoutAlign="start end">
<p>{{log.component}}</p>
</div>
</mat-cell>
</div>
<div matColumnDef="level">
<mat-header-cell *matHeaderCellDef> Level
</mat-header-cell>
<mat-cell *matCellDef="let log">
<div fxLayout="row" fxLayoutAlign="start end">
<p>{{log.level}}</p>
</div>
</mat-cell>
</div>
<div matColumnDef="output">
<mat-header-cell *matHeaderCellDef> Output
</mat-header-cell>
<mat-cell *matCellDef="let log">
<div fxLayout="row" fxLayoutAlign="start end">
<p>{{log.output}}</p>
</div> </div>
</mat-cell>
</div>
<div matColumnDef="enabled">
<mat-header-cell *matHeaderCellDef> Enabled
</mat-header-cell> </mat-header-cell>
<mat-cell *matCellDef="let log"> <mat-cell *matCellDef="let row; dataIndex as rowIndex">
<div fxLayout="row" fxLayoutAlign="start end"> <mat-form-field [ngSwitch]="col.type">
<p>{{log.enabled}}</p> <mat-slide-toggle *ngSwitchCase="IOptionType.boolean" [formControl]="row.booleanFC"
</div> [checked]="row.isEnabledFC.value" [disabled]="!col.modifiable"></mat-slide-toggle>
<input *ngSwitchCase="IOptionType.boolean" matInput [formControl]="row.stringFC"
[disabled]="!col.modifiable" />
</mat-form-field>
</mat-cell> </mat-cell>
</div> </div>
<mat-header-row *matHeaderRowDef="DISPLAYED_COLUMNS"></mat-header-row> <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let stageCtrl; columns: DISPLAYED_COLUMNS"></mat-row> <mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table> </mat-table>
......
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';
<<<<<<< HEAD
import { tap, mergeMap, filter } from 'rxjs/operators'; import { tap, mergeMap, filter } from 'rxjs/operators';
import { CommandsApi, IArgType, ILog } from 'src/app/api/commands.api'; import { CommandsApi, IArgType, ILog } from 'src/app/api/commands.api';
=======
import { CommandsApi, IArgType, IColumn, IRow } from 'src/app/api/commands.api';
>>>>>>> websrv-table
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 { VarCtrl } from 'src/app/controls/var.control'; import { VarCtrl } from 'src/app/controls/var.control';
import { DialogService } from 'src/app/services/dialog.service'; import { DialogService } from 'src/app/services/dialog.service';
import { LoadingService } from 'src/app/services/loading.service'; import { LoadingService } from 'src/app/services/loading.service';
...@@ -32,14 +37,9 @@ export class CommandsComponent { ...@@ -32,14 +37,9 @@ export class CommandsComponent {
// selectedArg?: VarCtrl // selectedArg?: VarCtrl
//table columns //table columns
DISPLAYED_COLUMNS = [ displayedColumns: string[] = []
'component', rows$: Observable<RowCtrl[]> = new Observable<RowCtrl[]>()
'level', columns: IColumn[] = []
'output',
'enabled'
]
logs$: Observable<ILog[]> = new Observable<ILog[]>()
constructor( constructor(
public commandsApi: CommandsApi, public commandsApi: CommandsApi,
...@@ -92,10 +92,14 @@ export class CommandsComponent { ...@@ -92,10 +92,14 @@ export class CommandsComponent {
} }
onCmdSubmit(control: CmdCtrl) { onCmdSubmit(control: CmdCtrl) {
this.logs$ = this.dialogService.openConfirmDialog().pipe( this.rows$ = this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`).pipe(
mergeMap(() => this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`)), map(iresp => {
tap(resp => this.success('runCommand ' + control.nameFC.value + ' OK', resp.display!.join("</p><p>"))), this.columns = iresp.columns
map(iresp => iresp.logs!) 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))))
return rows
})
); );
} }
......
import { FormControl, FormGroup } from '@angular/forms';
import { IArgType, IRow } from '../api/commands.api';
export class RowCtrl extends FormGroup {
type: IArgType
constructor(irow: IRow, type: IArgType) {
super({});
this.type = type
this.addControl(type, new FormControl(irow));
}
api() {
switch (this.type) {
case IArgType.boolean:
return this.boolFC.value ? "true" : "false";
// case IArgType.list:
// return this.listFC.value as string;
case IArgType.number:
return this.numberFC.value as string;
// case IArgType.range:
// return this.rangeFC.value as string;
case IArgType.string:
return this.stringFC.value
}
}
get boolFC() {
return this.get(IArgType.boolean) as FormControl;
}
set boolFC(control: FormControl) {
this.setControl(IArgType.boolean, control);
}
get listFC() {
return this.get(IArgType.list) as FormControl;
}
set listFC(control: FormControl) {
this.setControl(IArgType.list, control);
}
get numberFC() {
return this.get(IArgType.number) as FormControl;
}
set numberFC(control: FormControl) {
this.setControl(IArgType.number, control);
}
get rangeFC() {
return this.get(IArgType.range) as FormControl;
}
set rangeFC(control: FormControl) {
this.setControl(IArgType.range, control);
}
get stringFC() {
return this.get(IArgType.string) as FormControl;
}
set stringFC(control: FormControl) {
this.setControl(IArgType.string, control);
}
}
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