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';
import { Injectable } from '@angular/core';
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 {
subcommand = "subcommand",
......@@ -37,7 +28,9 @@ const route = '/oaisoftmodem';
export class CommandsApi {
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);
......
<div *ngIf="infos$ | async as infos">
<div *ngIf="status$ | async as statusVariables">
<h1 mat-dialog-title>Status</h1>
<p> config_file: {{ infos.display_status.config_file }}</p>
<p> executable_function: {{ infos.display_status.executable_function }}</p>
<div *ngFor="let status of statusVariables">
<mat-form-field>
<mat-label>{{ status.nameFC.value }}</mat-label>
<input input matInput [formControl]="status.valueFC" />
</mat-form-field>
<button mat-raised-button color="primary" [disabled]="!status.modifiableFC.value" (click)="onVarSubmit(status)">
set
</button>
</div>
</div>
<div *ngIf="infos$ | async as infos" fxLaypout="row">
<div *ngIf="cmds$ | async as cmds" fxLaypout="row">
<h1 mat-dialog-title>Commands</h1>
<mat-form-field>
<mat-label>Command</mat-label>
<mat-select [formControl]="selectedCmd" [value]="selectedCmd?.value" (selectionChange)="onSelect(selectedCmd)">
<mat-option *ngFor="let control of infos.cmdsFA.controls" [value]="control.value">{{ control.value }}
<mat-option *ngFor="let cmd of cmds" [value]="cmd">{{ cmd }}
</mat-option>
</mat-select>
</mat-form-field>
......@@ -35,4 +42,4 @@
{{ control.value }}
</button>
</div>
</div>
\ No newline at end of file
</div>
\ No newline at end of file
......@@ -3,10 +3,8 @@ import { FormControl } from '@angular/forms';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
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 { SubCmdCtrl } from 'src/app/controls/cmds.control';
import { InfosCtrl } from 'src/app/controls/infos.control';
import { VariableCtrl } from 'src/app/controls/variable.control';
import { LoadingService } from 'src/app/services/loading.service';
......@@ -20,7 +18,8 @@ export class CommandsComponent {
IOptionType = IOptionType;
infos$: Observable<InfosCtrl>
status$: Observable<VariableCtrl[]>
cmds$: Observable<string[]>
variables$ = new BehaviorSubject<VariableCtrl[]>([])
subcmds$: BehaviorSubject<SubCmdCtrl> | undefined
......@@ -32,16 +31,17 @@ export class CommandsComponent {
public commandsApi: CommandsApi,
public loadingService: LoadingService,
) {
this.infos$ = this.commandsApi.readInfos$().pipe(
map((doc) => new InfosCtrl(doc)),
this.status$ = this.commandsApi.readStatus$().pipe(
map((ivars) => ivars.map(ivar => new VariableCtrl(ivar)))
);
this.cmds$ = this.commandsApi.readModules$();
}
onCmdSubmit(subCmdName: string) {
this.commandsApi.runCommand$(subCmdName).subscribe();
}
onVarSubmit(varCtrl: VariableCtrl) {
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