1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import {UntypedFormArray, UntypedFormControl, UntypedFormGroup} from "@angular/forms";
import {Subscription} from "rxjs";
import {Observable} from "rxjs/internal/Observable";
import {ICommand, ICommandOptions, IQuestion} from "src/app/api/commands.api";
import {HelpApi, HelpRequest, HelpResp} from "src/app/api/help.api";
const enum CmdFCN {
name = "name",
vars = "variables",
confirm = "confirm",
answer = "answer"
}
export class CmdCtrl extends UntypedFormGroup {
confirm?: string;
question?: IQuestion;
cmdname: string;
options?: ICommandOptions[];
public ResUpdTimer?: Observable<number>;
public ResUpdTimerSubscriber?: Subscription;
updbtnname: string;
hlp_cmd: string = "";
constructor(cmd: ICommand)
{
super({});
this.addControl(CmdFCN.name, new UntypedFormControl(cmd.name));
this.addControl(CmdFCN.answer, new UntypedFormControl(""));
this.addControl(CmdFCN.vars, new UntypedFormArray([]));
this.confirm = cmd.confirm;
this.question = cmd.question;
this.cmdname = cmd.name;
this.options = cmd.options;
this.updbtnname = "Start update"
}
api()
{
const doc: ICommand = {
name : this.nameFC.value,
param : this.question ? {name : this.question!.pname, value : this.answerFC.value, type : this.question!.type, modifiable : false} : undefined,
options : this.options
};
return doc;
}
isResUpdatable(): boolean
{
if (this.options) {
for (let opt = 0; opt < this.options.length; opt++) {
if (this.options[opt] == ICommandOptions.update)
return true;
}
} else {
return false;
}
return false;
}
stopUpdate()
{
if (this.ResUpdTimerSubscriber) {
this.updbtnname = "Start update"
}
}
startUpdate()
{
if (this.ResUpdTimerSubscriber && this.ResUpdTimer) {
this.updbtnname = "Stop update"
}
}
get nameFC()
{
return this.get(CmdFCN.name) as UntypedFormControl;
}
set nameFC(fc: UntypedFormControl)
{
this.setControl(CmdFCN.name, fc);
}
get answerFC()
{
return this.get(CmdFCN.answer) as UntypedFormControl;
}
get varsFA()
{
return this.get(CmdFCN.vars) as UntypedFormArray;
}
set varsFA(fa: UntypedFormArray)
{
this.setControl(CmdFCN.vars, fa);
}
public get_cmd_help(helpApi: HelpApi, module: string)
{
if (this.options) {
for (let j = 0; j < this.options!.length; j++) {
if (this.options![j] == ICommandOptions.help) {
helpApi.getHelpText("cmd", module, this.cmdname).subscribe(resp => { this.hlp_cmd = resp; }, err => { this.hlp_cmd = ""; });
}
}
}
}
}