easel-dashboard 0.4.3 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,136 @@
1
+ /* controller.js.erb
2
+ *
3
+ * Author: Eric Power
4
+ *
5
+ * Description:
6
+ * This ERB file generates the javascript that runs the client side of the Easel
7
+ * Dashboard.
8
+ */
9
+
10
+ // Key Variables
11
+ let webSocket = new WebSocket("ws://" + location.hostname + ":" + location.port);
12
+ let graphicDashboards = {
13
+ <% $config[:dashboards].each do |dashboard| %>
14
+ "<%= dashboard[:id] %>": new GraphicDashboard("<%= dashboard[:name] %>", "<%= dashboard[:desc] %>", [
15
+ <% dashboard[:elements].each do |element| %>
16
+ {
17
+ type: "<%= element[:type] %>",
18
+ name: "<%= element[:name] %>",
19
+ desc: "___________",
20
+ dataTypes: [
21
+ <% element[:data].each do |datum| %>
22
+ {
23
+ name: "<%= datum[:name] %>",
24
+ colour: "<%= $config[:colours][:primary] %>"
25
+ },
26
+ <% end %>
27
+ ]
28
+ },
29
+ <% end %>
30
+ ]),
31
+ <% end %>
32
+ }
33
+ let textDashboards = { <% $config[:commands].each do |command| %>
34
+ "<%= command[:id] %>": new TextDashboard("Waiting:",
35
+ "",
36
+ "[Please run a command to see the output here.]"),
37
+ <% end %>
38
+ };
39
+
40
+
41
+ // Handle incomming websocket messages.
42
+ /* Receive message
43
+ *
44
+ * Sets the WebSocket's onmessage handler to recieve the message and then process
45
+ * it appropriately.
46
+ */
47
+ webSocket.onmessage = (event) => {
48
+
49
+ console.log("Received: " + event.data);
50
+
51
+ // If msg is about a textDashboard, or a graphicDashboard.
52
+ if (/\d/.test(event.data[0])) { // True IFF .data starts with a digit (textDashboard ID)
53
+
54
+ // Split message into [ID, CMD, MSG]
55
+ let msg_frags = event.data.split(":");
56
+ let id = msg_frags[0];
57
+ let cmd_type = msg_frags[1];
58
+ let msg = msg_frags.slice(2).join(":");
59
+ // Validate
60
+ if (!(id in textDashboards) ) {
61
+ console.log("Error validating message: " + event.data);
62
+ return;
63
+ }
64
+ // Process message
65
+ let tDash = textDashboards[id];
66
+ switch (cmd_type) {
67
+ case "ERR":
68
+ tDash.appendContent( "<span class=\"stderr\">" + msg + "</span>");
69
+ break;
70
+ case "OUT":
71
+ tDash.appendContent(msg);
72
+ break;
73
+ case "CLEAR":
74
+ tDash.clearContent();
75
+ break;
76
+ case "FINISHED":
77
+ tDash.setIsRunning(false);
78
+ break;
79
+ default:
80
+ console.log("Error: Message not understood. Id: " + id + ", cmd_type: " + cmd_type + ", msg:" + msg);
81
+ }
82
+
83
+ } else { // .data start with a non-digit character (it's about a dashboard).
84
+
85
+ // Split message into [DASH, ELEMENT, MSG FRAG, DATA TYPE]
86
+ let msg_frags = event.data.split(":");
87
+ let dash_id = msg_frags[0][0]; // TODO: Allow more than one character to represent the dashboard.
88
+ let elem_id = parseInt(msg_frags[0].slice(1));
89
+ if (msg_frags[1] != "A" ) {
90
+ console.log("Error: fragmented dashboard update received. Not implemented yet.")
91
+ return;
92
+ }
93
+ let msg = msg_frags.slice(2).join(":");
94
+
95
+ // Parse dashboard update msg
96
+ let dataType = parseInt(msg.split("->")[0]);
97
+ msg = msg.split("->")[1];
98
+ let label = msg.split('"')[1];
99
+ let value = parseFloat(msg.split('"')[3]);
100
+
101
+ // Update Chart
102
+ let gDash = graphicDashboards[dash_id];
103
+ gDash.addData(elem_id, dataType, label, value);
104
+ console.log("Appending: " + value);
105
+ }
106
+ }
107
+
108
+ /* toggle_run
109
+ *
110
+ * Sends a message to the server to stop or run the given id (dependent on its
111
+ * state), and updates the run/stop button accordingly.
112
+ */
113
+ function toggle_run(id){
114
+
115
+ let tDash = textDashboards[id];
116
+ if (tDash == null) {
117
+ console.log("Error: toggle_run called with id '" + id + "'");
118
+ return;
119
+ }
120
+ if (tDash.isRunning) { // TODO: Move into the Dashboard Class.
121
+ webSocket.send("STOP:" + id);
122
+ } else {
123
+ webSocket.send("RUN:" + id);
124
+ }
125
+ tDash.toggleRunning();
126
+ }
127
+
128
+ /* load_dashboard
129
+ *
130
+ * Loads the dashboard associated with the id.
131
+ */
132
+ function load_dashboard(id) {
133
+ let dash = graphicDashboards[id];
134
+ if(dash == null) dash = textDashboards[id];
135
+ dash.load();
136
+ }
metadata CHANGED
@@ -1,19 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easel-dashboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Power
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Use a YAML file to set up a dashboard, and change everything from the
14
- page colours to the commands that can be run. The dashboard shows the output of
15
- each command, which can be used to monitor server health, running processes, and
16
- much more.
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: concurrent-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.9
41
+ description:
17
42
  email: ericpower@outlook.com
18
43
  executables:
19
44
  - easel
@@ -24,13 +49,17 @@ files:
24
49
  - lib/easel.rb
25
50
  - lib/easel/build_pages.rb
26
51
  - lib/easel/configuration.rb
52
+ - lib/easel/controller.rb
53
+ - lib/easel/data_gathering.rb
27
54
  - lib/easel/logging.rb
28
55
  - lib/easel/server.rb
29
56
  - lib/easel/websocket.rb
30
57
  - lib/html/app.css.erb
31
58
  - lib/html/app.html.erb
59
+ - lib/html/app.js.erb
60
+ - lib/html/controller.js.erb
32
61
  - lib/html/error.html.erb
33
- homepage: https://github.com/epwr/cdash
62
+ homepage: https://github.com/epwr/easel-dashboard
34
63
  licenses:
35
64
  - MIT
36
65
  metadata: {}
@@ -52,5 +81,5 @@ requirements: []
52
81
  rubygems_version: 3.2.22
53
82
  signing_key:
54
83
  specification_version: 4
55
- summary: Easily set up and serve a dashboard using only a YAML file.
84
+ summary: An easier way to manage your server.
56
85
  test_files: []