Skip to content

Commit 14e97c4

Browse files
committed
Adopt Conditional class in frontend
1 parent c3cdf00 commit 14e97c4

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

src/ui/dspf.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,7 @@ export class DisplayFile {
406406
}
407407

408408
for (const keyword of recordFormat.keywords) {
409-
for (const keyword of recordFormat.keywords) {
410-
lines.push(...keyword.conditional.getLinesWithCondition(` A ${keyword.name}${keyword.value ? `(${keyword.value})` : ``}`));
411-
}
409+
lines.push(...keyword.conditional.getLinesWithCondition(` A ${keyword.name}${keyword.value ? `(${keyword.value})` : ``}`));
412410
}
413411

414412
return lines;
@@ -597,7 +595,7 @@ export class Conditional {
597595
this.conditions[this.conditions.length - 1].indicators.push({
598596
indicator: indicator,
599597
negate: negate
600-
})
598+
});
601599
}
602600
}
603601

@@ -610,7 +608,7 @@ export class Conditional {
610608
}
611609

612610
getLinesWithCondition(line: string): string[] {
613-
if (this.conditions.length == 1 && this.conditions[0].indicators.length == 0) {
611+
if (this.conditions.length === 1 && this.conditions[0].indicators.length === 0) {
614612
return [line];
615613
}
616614
let lines: string[] = [];
@@ -622,7 +620,7 @@ export class Conditional {
622620
lines.push(line.padEnd(16));
623621
i = 0;
624622
}
625-
if (i == 0) {
623+
if (i === 0) {
626624
line = ` A${cIdx > 0 ? "O" : " "}`;
627625
}
628626
i++;
@@ -635,7 +633,7 @@ export class Conditional {
635633
}
636634

637635
isActive(indicators: DisplayFileIndicators): boolean {
638-
if (this.conditions.length <= 1 && this.conditions[0].indicators.length == 0) {
636+
if (this.conditions.length <= 1 && this.conditions[0].indicators.length === 0) {
639637
return true;
640638
}
641639
this.conditions.forEach(cond => {

webui/dspf.d.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export declare class DisplayFile {
2424
}): {
2525
value: string;
2626
keywords: Keyword[];
27-
conditions: Conditional[];
27+
conditional: Conditional;
2828
};
2929
updateField(recordFormat: string, originalFieldName: string, fieldInfo: FieldInfo): {
3030
newLines: string[];
@@ -51,7 +51,7 @@ export declare class RecordInfo {
5151
export interface Keyword {
5252
name: string;
5353
value?: string;
54-
conditions: Conditional[];
54+
conditional: Conditional;
5555
}
5656
export type DisplayType = "input" | "output" | "both" | "const" | "hidden";
5757
export declare class FieldInfo {
@@ -73,13 +73,22 @@ export declare class FieldInfo {
7373
[lineIndex: number]: string;
7474
};
7575
};
76-
conditions: Conditional[];
76+
conditional: Conditional;
7777
keywords: Keyword[];
7878
constructor(startRange: number, name?: string | undefined);
7979
handleKeywords(): void;
8080
}
8181
export declare class Conditional {
82+
conditions: Condition[];
83+
//indicator: number;
84+
//negate: boolean;
85+
//constructor(indicator: number, negate?: boolean);
86+
}
87+
export declare class Condition {
88+
indicators: Indicator[];
89+
}
90+
export declare class Indicator {
8291
indicator: number;
8392
negate: boolean;
84-
constructor(indicator: number, negate?: boolean);
8593
}
94+

webui/main.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @typedef {import('./dspf.d.ts').RecordInfo} RecordInfo
44
* @typedef {import('./dspf.d.ts').FieldInfo} FieldInfo
55
* @typedef {import('./dspf.d.ts').Keyword} Keyword
6+
* @typedef {import('./dspf.d.ts').Conditional} Conditional
67
* @typedef {import("konva").default.Rect} Rect
78
* @typedef {import("konva").default.Stage} Stage
89
* @typedef {import("konva").default.Group} Group
@@ -261,13 +262,13 @@ function renderSelectedFormat(layer, format) {
261262
windowTitle.keywords.push({
262263
name: `COLOR`,
263264
value: parts[index + 1],
264-
conditions: []
265+
conditional: new Conditional()
265266
});
266267
case `*DSPATR`:
267268
windowTitle.keywords.push({
268269
name: `DSPATR`,
269270
value: parts[index + 1],
270-
conditions: []
271+
conditional: new Conditional()
271272
});
272273
break;
273274

@@ -289,7 +290,7 @@ function renderSelectedFormat(layer, format) {
289290
windowTitle.keywords.push({
290291
name: `COLOR`,
291292
value: `BLU`,
292-
conditions: []
293+
conditional: new Conditional()
293294
});
294295
}
295296

@@ -409,12 +410,12 @@ function addFieldsToLayer(layer, format) {
409410
fields.forEach(field => {
410411
let canDisplay = true;
411412

412-
field.conditions.forEach(cond => {
413-
// TODO: indicator support?
413+
// TODO: indicator support?
414+
//field.conditions.forEach(cond => {
414415
// if (this.indicators[cond.indicator] !== (cond.negate ? false : true)) {
415416
// canDisplay = false;
416417
// }
417-
});
418+
//});
418419

419420
if (canDisplay) {
420421
const content = getElement(field);
@@ -1028,11 +1029,12 @@ function createKeywordPanel(id, inputKeywords, onUpdate) {
10281029
value: keyword,
10291030
description: keyword.value,
10301031
actions,
1031-
subItems: keyword.conditions.map(c => ({
1032-
label: String(c.indicator),
1033-
description: c.negate ? `Negated` : undefined,
1032+
// TODO: Support multiple conditions (or-groups)
1033+
subItems: keyword.conditional.conditions[0].indicators.map(ind => ({
1034+
label: String(ind.indicator),
1035+
description: ind.negate ? `Negated` : undefined,
10341036
icons
1035-
})),
1037+
}))
10361038
};
10371039
});
10381040
};
@@ -1294,7 +1296,7 @@ function editKeyword(onUpdate, keyword) {
12941296
const newKeyword = {
12951297
name: keywordName,
12961298
value: keywordValue ? keywordValue : undefined,
1297-
conditions: []
1299+
conditional: new Conditional()
12981300
};
12991301

13001302
if (ind1 !== `None`) {

0 commit comments

Comments
 (0)