Commit 6e3f09a3 authored by El Mghazli Yacine's avatar El Mghazli Yacine

webserv APIv2 (frontend part)

parent 9ca2d78f
...@@ -2,15 +2,6 @@ import { HttpClient } from '@angular/common/http'; ...@@ -2,15 +2,6 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
export interface IStatus {
config_file: string;
executable_function: string;
}
export interface IInfos {
display_status: IStatus;
menu_cmds: string[];
}
export enum IOptionType { export enum IOptionType {
subcommand = "subcommand", subcommand = "subcommand",
...@@ -37,7 +28,9 @@ const route = '/oaisoftmodem'; ...@@ -37,7 +28,9 @@ const route = '/oaisoftmodem';
export class CommandsApi { export class CommandsApi {
constructor(private httpClient: HttpClient) { } constructor(private httpClient: HttpClient) { }
public readInfos$ = () => this.httpClient.get<IInfos>(environment.backend + route); public readStatus$ = () => this.httpClient.get<IVariable[]>(environment.backend + route + '/status/');
public readModules$ = () => this.httpClient.get<string[]>(environment.backend + route + '/modules/');
public getOptions$ = (cmdName: string) => this.httpClient.get<IOption[]>(environment.backend + route + '/module/' + cmdName); public getOptions$ = (cmdName: string) => this.httpClient.get<IOption[]>(environment.backend + route + '/module/' + cmdName);
......
<div *ngIf="infos$ | async as infos"> <div *ngIf="status$ | async as statusVariables">
<h1 mat-dialog-title>Status</h1> <h1 mat-dialog-title>Status</h1>
<p> config_file: {{ infos.display_status.config_file }}</p> <div *ngFor="let status of statusVariables">
<p> executable_function: {{ infos.display_status.executable_function }}</p>
<div *ngIf="infos$ | async as infos" fxLaypout="row">
<h1 mat-dialog-title>Commands</h1>
<mat-form-field> <mat-form-field>
<mat-label>Command</mat-label> <mat-label>{{ status.nameFC.value }}</mat-label>
<mat-select [formControl]="selectedCmd" [value]="selectedCmd?.value" (selectionChange)="onSelect(selectedCmd)"> <input input matInput [formControl]="status.valueFC" />
<mat-option *ngFor="let control of infos.cmdsFA.controls" [value]="control.value">{{ control.value }}
</mat-option>
</mat-select>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="primary" [disabled]="!status.modifiableFC.value" (click)="onVarSubmit(status)">
set
</button>
</div>
</div>
<div *ngIf="variables$ | async as variables" fxLaypout="column"> <div *ngIf="cmds$ | async as cmds" fxLaypout="row">
<h1 mat-dialog-title>Variables</h1> <h1 mat-dialog-title>Commands</h1>
<div *ngFor="let variable of variables"> <mat-form-field>
<mat-form-field> <mat-label>Command</mat-label>
<mat-label>{{ variable.nameFC.value }}</mat-label> <mat-select [formControl]="selectedCmd" [value]="selectedCmd?.value" (selectionChange)="onSelect(selectedCmd)">
<input input matInput [formControl]="variable.valueFC" /> <mat-option *ngFor="let cmd of cmds" [value]="cmd">{{ cmd }}
</mat-form-field> </mat-option>
<button mat-raised-button color="primary" [disabled]="!variable.modifiableFC.value" </mat-select>
(click)="onVarSubmit(variable)"> </mat-form-field>
set
</button>
</div>
</div>
<div *ngIf="subcmds$ | async as subcmds" fxLaypout="column" fxLayoutGap="10px"> <div *ngIf="variables$ | async as variables" fxLaypout="column">
<h1 mat-dialog-title>Sub-commands</h1> <h1 mat-dialog-title>Variables</h1>
<button *ngFor="let control of subcmds.namesFA.controls" mat-raised-button color="primary" <div *ngFor="let variable of variables">
(click)="onCmdSubmit(control.value)"> <mat-form-field>
{{ control.value }} <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)="onVarSubmit(variable)">
set
</button> </button>
</div> </div>
</div> </div>
\ No newline at end of file
<div *ngIf="subcmds$ | async as subcmds" fxLaypout="column" fxLayoutGap="10px">
<h1 mat-dialog-title>Sub-commands</h1>
<button *ngFor="let control of subcmds.namesFA.controls" mat-raised-button color="primary"
(click)="onCmdSubmit(control.value)">
{{ control.value }}
</button>
</div>
</div>
\ No newline at end of file
...@@ -3,10 +3,8 @@ import { FormControl } from '@angular/forms'; ...@@ -3,10 +3,8 @@ import { FormControl } from '@angular/forms';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
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';
import { tap } from 'rxjs/internal/operators/tap';
import { CommandsApi, IOptionType, ISubCommands, IVariable } from 'src/app/api/commands.api'; import { CommandsApi, IOptionType, ISubCommands, IVariable } from 'src/app/api/commands.api';
import { SubCmdCtrl } from 'src/app/controls/cmds.control'; import { SubCmdCtrl } from 'src/app/controls/cmds.control';
import { InfosCtrl } from 'src/app/controls/infos.control';
import { VariableCtrl } from 'src/app/controls/variable.control'; import { VariableCtrl } from 'src/app/controls/variable.control';
import { LoadingService } from 'src/app/services/loading.service'; import { LoadingService } from 'src/app/services/loading.service';
...@@ -20,7 +18,8 @@ export class CommandsComponent { ...@@ -20,7 +18,8 @@ export class CommandsComponent {
IOptionType = IOptionType; IOptionType = IOptionType;
infos$: Observable<InfosCtrl> status$: Observable<VariableCtrl[]>
cmds$: Observable<string[]>
variables$ = new BehaviorSubject<VariableCtrl[]>([]) variables$ = new BehaviorSubject<VariableCtrl[]>([])
subcmds$: BehaviorSubject<SubCmdCtrl> | undefined subcmds$: BehaviorSubject<SubCmdCtrl> | undefined
...@@ -32,16 +31,17 @@ export class CommandsComponent { ...@@ -32,16 +31,17 @@ export class CommandsComponent {
public commandsApi: CommandsApi, public commandsApi: CommandsApi,
public loadingService: LoadingService, public loadingService: LoadingService,
) { ) {
this.infos$ = this.commandsApi.readInfos$().pipe( this.status$ = this.commandsApi.readStatus$().pipe(
map((doc) => new InfosCtrl(doc)), map((ivars) => ivars.map(ivar => new VariableCtrl(ivar)))
); );
this.cmds$ = this.commandsApi.readModules$();
} }
onCmdSubmit(subCmdName: string) { onCmdSubmit(subCmdName: string) {
this.commandsApi.runCommand$(subCmdName).subscribe(); this.commandsApi.runCommand$(subCmdName).subscribe();
} }
onVarSubmit(varCtrl: VariableCtrl) { onVarSubmit(varCtrl: VariableCtrl) {
this.commandsApi.setVariable$(varCtrl.api()).subscribe(); this.commandsApi.setVariable$(varCtrl.api()).subscribe();
} }
......
import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { IInfos, IStatus } from '../api/commands.api';
const enum InfosFCN {
menu_cmds = 'commands',
}
export class InfosCtrl extends FormGroup {
display_status: IStatus
constructor(icommand: IInfos) {
super({});
this.display_status = icommand.display_status
this.addControl(InfosFCN.menu_cmds, new FormArray(icommand.menu_cmds.map((cmd) => new FormControl(cmd))));
}
api() {
const doc: IInfos = {
display_status: this.display_status,
menu_cmds: this.cmdsFA.value,
};
return doc;
}
get cmdsFA() {
return this.get(InfosFCN.menu_cmds) as FormArray;
}
set cmdsFA(control: FormArray) {
this.setControl(InfosFCN.menu_cmds, 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