Skip to content

Commit d0293f7

Browse files
authored
Revert "refactor: move program list styling to ProgramRunnerInfo" (#138)
Reverts #134
1 parent 59736a7 commit d0293f7

File tree

4 files changed

+34
-134
lines changed

4 files changed

+34
-134
lines changed

src/graphics/renderables/device_info.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { Device } from "../../types/devices";
33
import { DeviceType } from "../../types/devices/device";
44
import { ViewGraph } from "../../types/graphs/viewgraph";
55
import { RemoveDeviceMove } from "../../types/undo-redo";
6-
import { urManager } from "../../types/viewportManager";
7-
import { createRightBarButton, createRoutingTable } from "../right_bar";
6+
import { refreshElement, urManager } from "../../types/viewportManager";
7+
import {
8+
createDropdown,
9+
createRightBarButton,
10+
createTable,
11+
createRoutingTable,
12+
} from "../right_bar";
813
import { ProgramInfo } from "./program_info";
9-
import { ProgramRunnerInfo } from "./program_runner_info";
1014
import { StyledInfo } from "./styled_info";
1115

1216
export { ProgramInfo } from "./program_info";
@@ -56,8 +60,28 @@ export class DeviceInfo extends StyledInfo {
5660

5761
// First argument is to avoid a circular dependency
5862
addProgramRunner(runner: ProgramRunner, programs: ProgramInfo[]) {
59-
const programRunnerInfo = new ProgramRunnerInfo(runner, programs);
60-
this.inputFields.push(...programRunnerInfo.toHTML());
63+
const programOptions = programs.map(({ name }, i) => {
64+
return { value: i.toString(), text: name };
65+
});
66+
const inputsContainer = document.createElement("div");
67+
let selectedProgram = programs[0];
68+
inputsContainer.replaceChildren(...selectedProgram.toHTML());
69+
this.inputFields.push(
70+
// Dropdown for selecting program
71+
createDropdown("Program", programOptions, "program-selector", (v) => {
72+
selectedProgram = programs[parseInt(v)];
73+
inputsContainer.replaceChildren(...selectedProgram.toHTML());
74+
}),
75+
inputsContainer,
76+
// Button to send a packet
77+
createRightBarButton("Start program", () => {
78+
const { name } = selectedProgram;
79+
console.log("Started program: ", name);
80+
const inputs = selectedProgram.getInputValues();
81+
runner.addRunningProgram(name, inputs);
82+
refreshElement();
83+
}),
84+
);
6185
}
6286

6387
addRunningProgramsList(

src/graphics/renderables/program_runner_info.ts

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/programs/index.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,8 @@ export interface RunningProgram {
1313

1414
// Currently used only for Host, due to a circular dependency
1515
export interface ProgramRunner {
16-
/**
17-
* Adds a new program to run.
18-
* @param name program name
19-
* @param inputs program inputs
20-
* @returns the running program data
21-
*/
22-
addRunningProgram(name: string, inputs: string[]): RunningProgram;
23-
24-
/**
25-
* Lists running programs.
26-
* @returns the list of running programs
27-
*/
28-
getRunningPrograms(): RunningProgram[];
29-
30-
/**
31-
* Stops a running program.
32-
* @param pid running program ID
33-
* @returns `true` if the program exists and was stopped, `false` otherwise
34-
*/
35-
removeRunningProgram(pid: Pid): boolean;
16+
addRunningProgram(name: string, inputs: string[]): void;
17+
removeRunningProgram(pid: Pid): void;
3618
}
3719

3820
export interface Program {

src/types/devices/host.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class Host extends Device {
4848
const info = new DeviceInfo(this);
4949
info.addField("IP Address", this.ip.octets.join("."));
5050
info.addProgramRunner(this, programList);
51+
info.addRunningProgramsList(this, runningProgramsList);
5152
RightBar.getInstance().renderInfo(info);
5253
}
5354

@@ -77,7 +78,6 @@ export class Host extends Device {
7778
device.runningPrograms.push(runningProgram);
7879
});
7980
this.runProgram(runningProgram);
80-
return runningProgram;
8181
}
8282

8383
removeRunningProgram(pid: Pid) {
@@ -93,14 +93,13 @@ export class Host extends Device {
9393
const program = this.runningPrograms.get(pid);
9494
if (!program) {
9595
console.error("Program not found");
96-
return false;
96+
return;
9797
}
9898
program.stop();
9999
this.runningPrograms.delete(pid);
100-
return true;
101100
}
102101

103-
getRunningPrograms() {
102+
private getRunningPrograms() {
104103
const thisDevice = this.viewgraph.getDataGraph().getDevice(this.id);
105104
if (!isHost(thisDevice)) {
106105
console.error("Node is not a Host");

0 commit comments

Comments
 (0)