Commit 77b4022b authored by El Mghazli Yacine's avatar El Mghazli Yacine

rudiments ok

parent 6bcd3006
......@@ -2,24 +2,17 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
export interface IOption {
key: string;
value: number;
}
export interface ICommand {
name: string;
options: IOption[];
}
export interface IStatus {
infos: string;
config_file: string;
executable_function: string;
}
export interface ILog {
text: string;
export interface IInfos {
display_status: IStatus;
menu_cmds: string[];
}
const route = '/commands';
const route = '/oaisoftmodem';
@Injectable({
providedIn: 'root',
......@@ -27,11 +20,41 @@ const route = '/commands';
export class CommandsApi {
constructor(private httpClient: HttpClient) { }
public readCommands$ = () => this.httpClient.get<ICommand[]>(environment.backend + route + '/list');
public readStatus$ = () => this.httpClient.get<IStatus>(environment.backend + route + '/status');
public readInfos$ = () => this.httpClient.get<IInfos>(environment.backend + route);
}
public runCommand$ = (command: ICommand) => this.httpClient.post<ICommand>(environment.backend + route, command);
public readLogs$ = () => this.httpClient.get<IStatus>(environment.backend + route + '/logs');
}
\ No newline at end of file
// 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"
// ]
// }
<h1 mat-dialog-title>Status</h1>
<mat-form-field *ngIf="commandsCtrls$ | async as commands">
<mat-label>Command</mat-label>
<mat-select [formControl]="selectedCtrl!.nameFC" [value]="selectedCtrl!.nameFC.value">
<mat-option *ngFor="let command of commands" [value]="command">{{ command }}</mat-option>
</mat-select>
</mat-form-field>
\ No newline at end of file
<div *ngIf="infos$ | async as infos">
<p> config_file: {{ infos.display_status.config_file }}</p>
<p> executable_function: {{ infos.display_status.executable_function }}</p>
<mat-form-field>
<mat-label>Command</mat-label>
<mat-select [formControl]="selectedCmd!.value" [value]="selectedCmd!.value">
<mat-option *ngFor="let control of infos.cmdsFA.controls" [value]="control.value">{{ control.value }}</mat-option>
</mat-select>
</mat-form-field>
</div>
\ No newline at end of file
......@@ -3,10 +3,11 @@
/* eslint-disable eqeqeq */
/* eslint-disable @typescript-eslint/naming-convention */
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { CommandsApi } from 'src/app/api/commands.api';
import { CommandCtrl } from 'src/app/controls/command.control';
import { InfosCtrl } from 'src/app/controls/infos.control';
import { LoadingService } from 'src/app/services/loading.service';
......@@ -17,23 +18,16 @@ import { LoadingService } from 'src/app/services/loading.service';
})
export class CommandsComponent {
commandsCtrls$: Observable<CommandCtrl[]>
selectedCtrl?: CommandCtrl
infos$: Observable<InfosCtrl>
selectedCmd?: FormControl
constructor(
public commandsApi: CommandsApi,
public loadingService: LoadingService,
) {
this.commandsCtrls$ = this.commandsApi.readCommands$().pipe(
map((docs) => docs.map((doc) => new CommandCtrl(doc))),
this.infos$ = this.commandsApi.readInfos$().pipe(
map((doc) => new InfosCtrl(doc)),
);
}
onSubmit(control: CommandCtrl) {
this.commandsApi.runCommand$(control.api()).pipe(
// take(1),
tap(() => control.markAsPristine())
).subscribe();
}
}
......@@ -2,11 +2,7 @@
<mat-sidenav #drawer class="sidenav" fixedInViewport [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="(isHandset$ | async) === false">
<mat-nav-list>
<a mat-list-item routerLink="/bookings" routerLinkActive="active">Month</a>
<a mat-list-item routerLink="/year" routerLinkActive="active">Year</a>
<a mat-list-item routerLink="/messages" routerLinkActive="active">Autosend</a>
<a mat-list-item routerLink="/cleaners" routerLinkActive="active">Cleaners</a>
<a mat-list-item routerLink="/user" routerLinkActive="active">Calendars</a>
<a mat-list-item routerLink="/commands" routerLinkActive="active">Commands</a>
</mat-nav-list>
</mat-sidenav>
......@@ -18,7 +14,7 @@
<button mat-icon-button (click)="drawer.toggle()">
<mat-icon>menu</mat-icon>
</button>
<h1>SOFTMODEM</h1>
<h1>OAI SoftModem</h1>
</ng-template>
<ng-template #loading>
<mat-progress-spinner mode="indeterminate" diameter="40">
......
/* eslint-disable no-shadow */
import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { ICommand } from '../api/commands.api';
import { OptionCtrl } from './option.control';
const enum CommandFCN {
name = 'name',
options = 'options',
}
export class CommandCtrl extends FormGroup {
constructor(icommand: ICommand) {
super({});
this.addControl(CommandFCN.name, new FormControl(icommand.name));
this.addControl(CommandFCN.options, new FormArray(icommand.options.map((ioption) => new OptionCtrl(ioption))));
}
api() {
const doc: ICommand = {
name: this.nameFC.value,
options: this.optionsFA.controls.map(control => (control as OptionCtrl).api()),
};
return doc;
}
get nameFC() {
return this.get(CommandFCN.name) as FormControl;
}
set nameFC(control: FormControl) {
this.setControl(CommandFCN.name, control);
}
get optionsFA() {
return this.get(CommandFCN.options) as FormArray;
}
set optionsFA(control: FormArray) {
this.setControl(CommandFCN.options, control);
}
}
/* eslint-disable no-shadow */
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);
}
}
/* eslint-disable no-shadow */
import { FormControl, FormGroup } from '@angular/forms';
import { IOption } from '../api/commands.api';
const enum OptionFCN {
key = 'key',
value = 'value',
}
export class Option {
key: string;
value: number;
constructor(ioption: IOption) {
this.key = ioption.key;
this.value = ioption.value;
}
}
export class OptionCtrl extends FormGroup {
constructor(ioption: IOption) {
super({});
const option = new Option(ioption);
this.addControl(OptionFCN.key, new FormControl(option.key));
this.addControl(OptionFCN.value, new FormControl(option.value));
}
api() {
const doc: IOption = {
key: this.keyFC.value,
value: this.valueFC.value,
};
return doc;
}
get keyFC() {
return this.get(OptionFCN.key) as FormControl;
}
set keyFC(control: FormControl) {
this.setControl(OptionFCN.key, control);
}
get valueFC() {
return this.get(OptionFCN.value) as FormControl;
}
setvalueFC(control: FormControl) {
this.setControl(OptionFCN.value, 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