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

working with first API version

parent 14321bfe
......@@ -12,6 +12,23 @@ export interface IInfos {
menu_cmds: string[];
}
export enum IOptionType {
subcommand = "subcommand",
variable = "variable"
}
export interface IOption {
type: IOptionType;
}
export interface IVariable extends IOption {
name: string;
value: string;
modifiable: boolean;
}
export interface ISubCommands extends IOption {
name: string[];
}
const route = '/oaisoftmodem';
@Injectable({
......@@ -22,41 +39,10 @@ export class CommandsApi {
public readInfos$ = () => this.httpClient.get<IInfos>(environment.backend + route);
public runCommand$ = (cmdName: string) => this.httpClient.post<string>(environment.backend + route, cmdName);
}
public getOptions$ = (cmdName: string) => this.httpClient.get<IOption[]>(environment.backend + route + '/module/' + cmdName);
public runCommand$ = (cmdName: string) => this.httpClient.post<string>(environment.backend + route + '/command/' + cmdName, {});
// FRANCOIS_BODY = {
// "main_oai softmodem": [
// {
// "display_status": [
// { "Config file": "../../../ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf" },
// { "Executable function": "gnb" }
// ]
// },
// {
// "menu_cmds": [
// "telnet",
// "softmodem",
// "loader",
// "measur",
// "rfsimu"
// ]
// }
// ]
// }
// YASS_BODY = {
// display_status: {
// config_file: '../../../ ci - scripts / conf_files / gnb.band78.sa.fr1.106PRB.usrpn310.conf',
// executable_function: "gnb"
// },
// menu_cmds: [
// "telnet",
// "softmodem",
// "loader",
// "measur",
// "rfsimu"
// ]
// }
public setVariable$ = (variable: IVariable) => this.httpClient.post<string>(environment.backend + route + '/variable/' + variable.name, variable.value);
}
......@@ -3,7 +3,7 @@ import { Routes, RouterModule } from '@angular/router';
import { CommandsComponent } from './components/commands/commands.component';
const routes: Routes = [
{ path: '', redirectTo: '/', pathMatch: 'full' },
{ path: '', redirectTo: '/commands', pathMatch: 'full' },
{ path: 'commands', component: CommandsComponent },
{ path: '**', redirectTo: '' },
];
......
......@@ -4,17 +4,35 @@
<p> config_file: {{ infos.display_status.config_file }}</p>
<p> executable_function: {{ infos.display_status.executable_function }}</p>
<h1 mat-dialog-title>Commands</h1>
<div fxLaypout="row">
<div *ngIf="infos$ | async as infos" fxLaypout="row">
<h1 mat-dialog-title>Commands</h1>
<mat-form-field>
<mat-label>Command</mat-label>
<mat-select [formControl]="selected" [value]="selected?.value">
<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>
</mat-select>
</mat-form-field>
<button mat-raised-button color="primary" [disabled]="!selected" (click)="onSubmit()">
submit
</button>
</div>
</div>
\ No newline at end of file
<div *ngIf="variables$ | async as variables" fxLaypout="column">
<h1 mat-dialog-title>Variables</h1>
<div *ngFor="let variable of variables">
<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)="onVarSubmit(variable)">
set
</button>
</div>
</div>
<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
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
import { map } from 'rxjs/internal/operators/map';
import { CommandsApi } from 'src/app/api/commands.api';
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';
......@@ -14,10 +18,15 @@ import { LoadingService } from 'src/app/services/loading.service';
})
export class CommandsComponent {
IOptionType = IOptionType;
infos$: Observable<InfosCtrl>
// infos: InfosCtrl
variables$ = new BehaviorSubject<VariableCtrl[]>([])
subcmds$: BehaviorSubject<SubCmdCtrl> | undefined
selected = new FormControl()
selectedCmd = new FormControl()
selectedSubCmd = new FormControl()
selectedVariable?: VariableCtrl
constructor(
public commandsApi: CommandsApi,
......@@ -26,38 +35,22 @@ export class CommandsComponent {
this.infos$ = this.commandsApi.readInfos$().pipe(
map((doc) => new InfosCtrl(doc)),
);
}
onCmdSubmit(subCmdName: string) {
this.commandsApi.runCommand$(subCmdName).subscribe();
}
// this.infos = new InfosCtrl({
// display_status: {
// config_file: '../../../ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf',
// executable_function: "gnb"
// },
// menu_cmds: [
// "telnet",
// "softmodem",
// "loader",
// "measur",
// "rfsimu"
// ]
// })
// const BODY_JSON = {
// "display_status": {
// "config_file": '../../../ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf',
// "executable_function": "gnb"
// },
// "menu_cmds": [
// "telnet",
// "softmodem",
// "loader",
// "measur",
// "rfsimu"
// ]
// }
onVarSubmit(varCtrl: VariableCtrl) {
this.commandsApi.setVariable$(varCtrl.api()).subscribe();
}
onSubmit() {
this.commandsApi.runCommand$(this.selected.value).subscribe();
onSelect(cmdNameFC: FormControl) {
this.commandsApi.getOptions$(cmdNameFC.value).subscribe(opts => {
this.variables$.next(opts.filter(iopt => iopt.type === IOptionType.variable).map(iopt => new VariableCtrl(iopt as IVariable)))
const [subCmds] = opts.filter(iopt => iopt.type === IOptionType.subcommand)
this.subcmds$ = new BehaviorSubject<SubCmdCtrl>(new SubCmdCtrl(subCmds as ISubCommands))
})
}
}
import { FormArray, FormControl } from '@angular/forms';
import { ISubCommands } from '../api/commands.api';
import { OptionsCtrl } from './options.control';
const enum SubCmdsFCN {
names = 'names',
}
export class SubCmdCtrl extends OptionsCtrl {
constructor(isubs: ISubCommands) {
super(isubs);
this.addControl(SubCmdsFCN.names, new FormArray(isubs.name.map((name) => new FormControl(name))));
}
api() {
const doc: ISubCommands = {
type: this.type,
name: this.namesFA.value
};
return doc;
}
get namesFA() {
return this.get(SubCmdsFCN.names) as FormArray;
}
set namesFA(fa: FormArray) {
this.setControl(SubCmdsFCN.names, fa);
}
}
......@@ -3,35 +3,35 @@ import { IInfos, IStatus } from '../api/commands.api';
const enum InfosFCN {
menu_cmds = 'commands',
menu_cmds = 'commands',
}
export class InfosCtrl extends FormGroup {
display_status: IStatus
display_status: IStatus
constructor(icommand: IInfos) {
super({});
constructor(icommand: IInfos) {
super({});
this.display_status = icommand.display_status
this.display_status = icommand.display_status
this.addControl(InfosFCN.menu_cmds, new FormArray(icommand.menu_cmds.map((cmd) => new FormControl(cmd))));
}
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,
};
api() {
const doc: IInfos = {
display_status: this.display_status,
menu_cmds: this.cmdsFA.value,
};
return doc;
}
return doc;
}
get cmdsFA() {
return this.get(InfosFCN.menu_cmds) as FormArray;
}
get cmdsFA() {
return this.get(InfosFCN.menu_cmds) as FormArray;
}
set cmdsFA(control: FormArray) {
this.setControl(InfosFCN.menu_cmds, control);
}
set cmdsFA(control: FormArray) {
this.setControl(InfosFCN.menu_cmds, control);
}
}
import { FormGroup } from "@angular/forms";
import { IOption, IOptionType } from "../api/commands.api";
export class OptionsCtrl extends FormGroup {
type: IOptionType
constructor(ioption: IOption) {
super({});
this.type = ioption.type
}
}
\ No newline at end of file
import { FormControl } from '@angular/forms';
import { IOptionType, IVariable } from '../api/commands.api';
import { OptionsCtrl } from './options.control';
const enum VariablesFCN {
name = 'name',
value = "value",
modifiable = "modifiable"
}
export class VariableCtrl extends OptionsCtrl {
constructor(ivar: IVariable) {
super(ivar);
this.addControl(VariablesFCN.name, new FormControl(ivar.name));
this.addControl(VariablesFCN.value, new FormControl(ivar.value));
this.addControl(VariablesFCN.modifiable, new FormControl(ivar.modifiable));
}
api() {
const doc: IVariable = {
type: this.type,
name: this.nameFC.value,
value: this.valueFC.value,
modifiable: this.modifiableFC.value
};
return doc;
}
get nameFC() {
return this.get(VariablesFCN.name) as FormControl;
}
set nameFC(control: FormControl) {
this.setControl(VariablesFCN.name, control);
}
get valueFC() {
return this.get(VariablesFCN.value) as FormControl;
}
set valueFC(control: FormControl) {
this.setControl(VariablesFCN.value, control);
}
get modifiableFC() {
return this.get(VariablesFCN.modifiable) as FormControl;
}
set modifiableFC(control: FormControl) {
this.setControl(VariablesFCN.modifiable, control);
}
}
......@@ -4,7 +4,7 @@
export const environment = {
production: false,
backend: 'http://localhost:8090'
backend: 'http://10.130.163.206:8090'
};
/*
......
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