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

fixed cmds display

parent 2afae815
...@@ -33,7 +33,7 @@ export class CommandsApi { ...@@ -33,7 +33,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$ = (moduleName: string, command: ICommand) => this.httpClient.post<string>(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);
......
...@@ -11,19 +11,22 @@ ...@@ -11,19 +11,22 @@
</div> </div>
</div> </div>
<div *ngIf="cmds$ | async as cmds" fxLaypout="row"> <div *ngIf="modules$ | async as modules" fxLaypout="row">
<mat-form-field> <mat-form-field>
<mat-label>Module</mat-label> <mat-label>Module</mat-label>
<mat-select [formControl]="selectedCmd!.nameFC" [value]="selectedCmd!.nameFC.value" <mat-select (selectionChange)="onModuleSelect($event.value)">
(selectionChange)=" onCmdSelect()"> <mat-option *ngFor="let module of modules" [value]="module"> {{ module.nameFC.value }}
<mat-option *ngFor="let cmd of cmds" [value]="cmd.nameFC.value">{{ cmd.nameFC.value }}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div>
<div *ngIf="selectedModule">
<h1 mat-dialog-title>{{ selectedModule!.nameFC.value }} module</h1>
<div *ngIf="subvars$ | async as subvars" fxLaypout="column"> <div *ngIf="subvars$ | async as subvars" fxLaypout="column">
<div *ngIf="subvars.length"> <div *ngIf="subvars.length">
<h1 mat-dialog-title>{{ selectedCmd!.nameFC.value }} variables</h1> <h2 mat-dialog-title>Variables</h2>
<div *ngFor="let variable of subvars"> <div *ngFor="let variable of subvars">
<mat-form-field> <mat-form-field>
<mat-label>{{ variable.nameFC.value }}</mat-label> <mat-label>{{ variable.nameFC.value }}</mat-label>
...@@ -37,34 +40,19 @@ ...@@ -37,34 +40,19 @@
</div> </div>
</div> </div>
<div *ngIf="subcmds$ | async as subcmds" fxLaypout="column" fxLayoutGap="10px"> <div *ngIf="cmds$ | async as cmds" fxLaypout="column" fxLayoutGap="10px">
<div *ngIf="subcmds.length"> <div *ngIf="cmds.length">
<h1 mat-dialog-title>{{ selectedCmd!.nameFC.value }} commands</h1> <h2 mat-dialog-title>Commands</h2>
<mat-form-field> <div *ngFor="let cmd of cmds">
<mat-label>Command</mat-label> <!-- <mat-form-field>
<mat-select [formControl]="selectedSubCmd!.nameFC" [value]="selectedSubCmd!.nameFC.value" <mat-label>{{ cmd.nameFC.value }}</mat-label>
(selectionChange)="onSubCmdSelect()"> <input input matInput [formControl]="cmd.nameFC" />
<mat-option *ngFor="let subcmd of subcmds" [value]="subcmd.nameFC.value">{{ subcmd.nameFC.value }} </mat-form-field> -->
</mat-option> <button mat-raised-button color="primary" (click)="onCmdSubmit(cmd)">
</mat-select> {{cmd.nameFC.value}}
</mat-form-field> </button>
<div *ngIf="args$ | async as args" fxLaypout="column">
<div *ngIf="args.length">
<h1 mat-dialog-title>{{ selectedSubCmd!.nameFC.value }} Sub-Variables</h1>
<div *ngFor="let variable of args">
<mat-form-field>
<mat-label>{{ variable.nameFC.value }}</mat-label>
<input input matInput [formControl]="variable.valueFC" />
</mat-form-field>
<button mat-raised-button color="primary" [disabled]="!variable.modifiableFC.value"
(click)="onSubVarSubmit(variable)">
submit
</button>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -18,17 +18,17 @@ export class CommandsComponent { ...@@ -18,17 +18,17 @@ export class CommandsComponent {
IOptionType = IArgType; IOptionType = IArgType;
vars$: Observable<VarCtrl[]> vars$: Observable<VarCtrl[]>
cmds$: Observable<CmdCtrl[]> modules$: Observable<CmdCtrl[]>
selectedCmd?: CmdCtrl selectedModule?: CmdCtrl
selectedVar?: VarCtrl // selectedVar?: VarCtrl
subvars$?: Observable<VarCtrl[]> subvars$?: Observable<VarCtrl[]>
subcmds$?: Observable<CmdCtrl[]> cmds$?: Observable<CmdCtrl[]>
selectedSubCmd?: CmdCtrl // selectedSubCmd?: CmdCtrl
selectedSubVar?: VarCtrl // selectedSubVar?: VarCtrl
args$?: Observable<VarCtrl[]> args$?: Observable<VarCtrl[]>
selectedArg?: VarCtrl // selectedArg?: VarCtrl
constructor( constructor(
public commandsApi: CommandsApi, public commandsApi: CommandsApi,
...@@ -38,29 +38,32 @@ export class CommandsComponent { ...@@ -38,29 +38,32 @@ export class CommandsComponent {
map((vars) => vars.map(ivar => new VarCtrl(ivar))) map((vars) => vars.map(ivar => new VarCtrl(ivar)))
); );
this.cmds$ = this.commandsApi.readCommands$().pipe( this.modules$ = this.commandsApi.readCommands$().pipe(
map((cmds) => cmds.map(icmd => new CmdCtrl(icmd))), map((cmds) => cmds.map(icmd => new CmdCtrl(icmd))),
tap(controls => [this.selectedCmd] = controls) // tap(controls => [this.selectedCmd] = controls)
); );
} }
onCmdSelect() { onModuleSelect(control: CmdCtrl) {
this.subcmds$ = this.commandsApi.readCommands$(`${this.selectedCmd!.nameFC.value}`).pipe( this.selectedModule = control
map(icmds => icmds.map(icmd => new CmdCtrl(icmd))),
tap(controls => [this.selectedSubCmd] = controls) this.cmds$ = this.commandsApi.readCommands$(`${control.nameFC.value}`).pipe(
map(icmds => icmds.map(icmd => new CmdCtrl(icmd)))
) )
this.subvars$ = this.commandsApi.readVariables$(`${this.selectedCmd!.nameFC.value}`).pipe( this.subvars$ = this.commandsApi.readVariables$(`${control.nameFC.value}`).pipe(
map(ivars => ivars.map(ivar => new VarCtrl(ivar))), map(ivars => ivars.map(ivar => new VarCtrl(ivar))),
tap(controls => [this.selectedSubVar] = controls) // tap(controls => [this.selectedSubVar] = controls)
) )
} }
onSubCmdSelect() { onCmdSelect(control: CmdCtrl) {
this.args$ = this.commandsApi.readVariables$(`${this.selectedCmd!.nameFC.value}/${this.selectedSubCmd!.nameFC.value}`).pipe(
map(ivars => ivars.map(ivar => new VarCtrl(ivar))), // this.selectedSubCmd = control
tap(controls => [this.selectedArg] = controls)
this.args$ = this.commandsApi.readVariables$(`${this.selectedModule!.nameFC.value}/${control.nameFC.value}`).pipe(
map(ivars => ivars.map(ivar => new VarCtrl(ivar)))
) )
} }
...@@ -69,7 +72,10 @@ export class CommandsComponent { ...@@ -69,7 +72,10 @@ export class CommandsComponent {
} }
onSubVarSubmit(control: VarCtrl) { onSubVarSubmit(control: VarCtrl) {
this.commandsApi.setVariable$(control.api(), `${this.selectedCmd?.nameFC.value}`).subscribe(); this.commandsApi.setVariable$(control.api(), `${this.selectedModule!.nameFC.value}`).subscribe();
// this.commandsApi.setVariable$(control.api(), `${this.selectedCmd?.nameFC.value} / ${this.selectedSubCmd?.nameFC.value} / ${control.nameFC.value}`).subscribe(); }
onCmdSubmit(control: CmdCtrl) {
this.commandsApi.runCommand$(control.api(), `${this.selectedModule!.nameFC.value}`).subscribe();
} }
} }
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