|
| 1 | +<!DOCTYPE html> |
1 | 2 | <html>
|
2 | 3 | <head>
|
3 |
| -<title>Arduino Create Agent Debug Interface</title> |
| 4 | +<title>Arduino Create Agent Debug Console</title> |
| 5 | +<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&display=swap" rel="stylesheet"> |
| 6 | +<link href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,600,700&display=swap" rel="stylesheet"> |
4 | 7 | <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
| 8 | +<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script> |
5 | 9 | <script type="text/javascript">
|
6 | 10 | $(function() {
|
| 11 | + var socket; |
| 12 | + var input = $('#input'); |
| 13 | + var log = document.getElementById('log'); |
| 14 | + var autoscroll = document.getElementById('autoscroll'); |
| 15 | + var listenabled = document.getElementById('list'); |
| 16 | + var messages = []; |
| 17 | + var MESSAGES_MAX_COUNT = 2000; |
7 | 18 |
|
8 |
| - var conn; |
9 |
| - var msg = $("#msg"); |
10 |
| - var log = $("#log"); |
| 19 | + function appendLog(msg) { |
| 20 | + var startsWithBracked = msg.indexOf('{') == 0; |
| 21 | + var startsWithList = msg.indexOf('list') == 0; |
11 | 22 |
|
12 |
| - function appendLog(msg) { |
13 |
| - var d = log[0] |
14 |
| - var doScroll = d.scrollTop == d.scrollHeight - d.clientHeight; |
15 |
| - msg.appendTo(log) |
16 |
| - if (doScroll) { |
17 |
| - d.scrollTop = d.scrollHeight - d.clientHeight; |
18 |
| - } |
19 |
| - } |
| 23 | + if (listenabled.checked || (typeof msg === 'string' && !startsWithBracked && !startsWithList)) { |
| 24 | + messages.push(msg); |
| 25 | + if (messages.length > MESSAGES_MAX_COUNT) { |
| 26 | + messages.shift(); |
| 27 | + } |
| 28 | + log.innerHTML = messages.join('<br>'); |
| 29 | + if (autoscroll.checked) { |
| 30 | + log.scrollTop = log.scrollHeight - log.clientHeight; |
| 31 | + } |
| 32 | + } |
| 33 | + } |
20 | 34 |
|
21 |
| - $("#form").submit(function() { |
22 |
| - if (!conn) { |
23 |
| - return false; |
24 |
| - } |
25 |
| - if (!msg.val()) { |
26 |
| - return false; |
27 |
| - } |
28 |
| - conn.send(msg.val()); |
29 |
| - msg.val(""); |
30 |
| - return false |
31 |
| - }); |
32 |
| - |
33 |
| - if (window["WebSocket"]) { |
34 |
| - conn = new WebSocket("wss://{{$}}/ws"); |
35 |
| - conn.onclose = function(evt) { |
36 |
| - appendLog($("<div><b>Connection closed.</b></div>")) |
37 |
| - } |
38 |
| - conn.onmessage = function(evt) { |
39 |
| - appendLog($("<div/>").text(evt.data)) |
| 35 | + $('#form').submit(function(e) { |
| 36 | + e.preventDefault(); |
| 37 | + if (!socket) { |
| 38 | + return false; |
| 39 | + } |
| 40 | + if (!input.val()) { |
| 41 | + return false; |
| 42 | + } |
| 43 | + socket.emit('command', input.val()); |
| 44 | + }); |
| 45 | + |
| 46 | + $('#export').click(function() { |
| 47 | + var link = document.createElement('a'); |
| 48 | + link.setAttribute('download', 'agent-log.txt'); |
| 49 | + var text = log.innerHTML.replace(/<br>/g, '\n'); |
| 50 | + link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); |
| 51 | + link.click(); |
| 52 | + }); |
| 53 | + |
| 54 | + $('#clear').click(function() { |
| 55 | + messages = []; |
| 56 | + log.innerHTML = ''; |
| 57 | + }); |
| 58 | + |
| 59 | + if (window['WebSocket']) { |
| 60 | + if (window.location.protocol === 'https:') { |
| 61 | + socket = io('https://{{$}}') |
| 62 | + } else { |
| 63 | + socket = io('http://{{$}}'); |
| 64 | + } |
| 65 | + socket.on('disconnect', function(evt) { |
| 66 | + appendLog($('<div><b>Connection closed.</b></div>')) |
| 67 | + }); |
| 68 | + socket.on('message', function(evt) { |
| 69 | + appendLog(evt); |
| 70 | + }); |
| 71 | + } else { |
| 72 | + appendLog($('<div><b>Your browser does not support WebSockets.</b></div>')) |
40 | 73 | }
|
41 |
| - } else { |
42 |
| - appendLog($("<div><b>Your browser does not support WebSockets.</b></div>")) |
43 |
| - } |
44 |
| - }); |
| 74 | + |
| 75 | + $("#input").focus(); |
| 76 | + }); |
45 | 77 | </script>
|
46 | 78 | <style type="text/css">
|
47 |
| -html { |
| 79 | +html, body { |
48 | 80 | overflow: hidden;
|
| 81 | + height: 100%; |
49 | 82 | }
|
50 | 83 |
|
51 |
| -body { |
52 |
| - overflow: hidden; |
53 |
| - padding: 0; |
54 |
| - margin: 0; |
55 |
| - width: 100%; |
| 84 | +body { |
| 85 | + margin: 0px; |
| 86 | + padding: 0px; |
| 87 | + background: #F8F9F9; |
| 88 | + font-size: 16px; |
| 89 | + font-family: "Open Sans", "Lucida Grande", Lucida, Verdana, sans-serif; |
| 90 | +} |
| 91 | + |
| 92 | +#container { |
| 93 | + display: flex; |
| 94 | + flex-direction: column; |
56 | 95 | height: 100%;
|
57 |
| - background: gray; |
| 96 | + width: 100%; |
58 | 97 | }
|
59 | 98 |
|
60 | 99 | #log {
|
61 |
| - background: white; |
62 |
| - margin: 0; |
63 |
| - padding: 0.5em 0.5em 0.5em 0.5em; |
64 |
| - position: absolute; |
65 |
| - top: 0.5em; |
66 |
| - left: 0.5em; |
67 |
| - right: 0.5em; |
68 |
| - bottom: 3em; |
69 |
| - overflow: auto; |
| 100 | + flex-grow: 1; |
| 101 | + font-family: "Roboto Mono", "Courier", "Lucida Grande", Verdana, sans-serif; |
| 102 | + background-color: #DAE3E3; |
| 103 | + margin: 15px 15px 10px; |
| 104 | + padding: 8px 10px; |
| 105 | + overflow-y: auto; |
70 | 106 | }
|
71 | 107 |
|
72 |
| -#form { |
73 |
| - padding: 0 0.5em 0 0.5em; |
74 |
| - margin: 0; |
75 |
| - position: absolute; |
76 |
| - bottom: 1em; |
77 |
| - left: 0px; |
78 |
| - width: 100%; |
79 |
| - overflow: hidden; |
| 108 | +#footer { |
| 109 | + display: flex; |
| 110 | + flex-wrap: wrap; |
| 111 | + align-items: flex-start; |
| 112 | + justify-content: space-between; |
| 113 | + margin: 0px 15px 0px; |
| 114 | +} |
| 115 | + |
| 116 | +#form { |
| 117 | + display: flex; |
| 118 | + flex-grow: 1; |
| 119 | + margin-bottom: 15px; |
| 120 | +} |
| 121 | + |
| 122 | +#input { |
| 123 | + flex-grow: 1; |
| 124 | +} |
| 125 | + |
| 126 | +#secondary-controls div { |
| 127 | + display: inline-block; |
| 128 | + padding: 10px 15px; |
| 129 | +} |
| 130 | + |
| 131 | +#autoscroll, |
| 132 | +#list { |
| 133 | + vertical-align: middle; |
| 134 | + width: 20px; |
| 135 | + height: 20px; |
| 136 | +} |
| 137 | + |
| 138 | + |
| 139 | +#secondary-controls button { |
| 140 | + margin-bottom: 15px; |
| 141 | + vertical-align: top; |
| 142 | +} |
| 143 | + |
| 144 | +.button { |
| 145 | + background-color: #b5c8c9; |
| 146 | + border: 1px solid #b5c8c9; |
| 147 | + border-radius: 2px 2px 0 0; |
| 148 | + box-shadow: 0 4px #95a5a6; |
| 149 | + margin-bottom: 4px; |
| 150 | + color: #000; |
| 151 | + cursor: pointer; |
| 152 | + font-size: 14px; |
| 153 | + letter-spacing: 1.28px; |
| 154 | + line-height: normal; |
| 155 | + outline: none; |
| 156 | + padding: 9px 18px; |
| 157 | + text-align: center; |
| 158 | + text-transform: uppercase; |
| 159 | + transition: box-shadow .1s ease-out, transform .1s ease-out; |
| 160 | +} |
| 161 | + |
| 162 | +.button:hover { |
| 163 | + box-shadow: 0 2px #95a5a6; |
| 164 | + outline: none; |
| 165 | + transform: translateY(2px); |
| 166 | +} |
| 167 | + |
| 168 | +.button:active { |
| 169 | + box-shadow: none; |
| 170 | + transform: translateY(4px); |
| 171 | +} |
| 172 | + |
| 173 | +.textfield { |
| 174 | + background-color: #dae3e3; |
| 175 | + width: auto; |
| 176 | + height: auto; |
| 177 | + padding: 10px 8px; |
| 178 | + margin-left: 8px; |
| 179 | + vertical-align: top; |
| 180 | + border: none; |
| 181 | + font-family: "Open Sans", "Lucida Grande", Lucida, Verdana, sans-serif; |
| 182 | + font-size: 1em; |
| 183 | + outline: none; |
80 | 184 | }
|
81 | 185 |
|
82 | 186 | </style>
|
83 | 187 | </head>
|
84 |
| -<body> |
85 |
| -<div id="log"></div> |
86 |
| -<form id="form"> |
87 |
| - <input type="submit" value="Send" /> |
88 |
| - <input type="text" id="msg" size="64"/> |
89 |
| -</form> |
90 |
| -</body> |
| 188 | + <body> |
| 189 | + <div id="container"> |
| 190 | + <div id="log">This is some random text This is some random textThis is some random textThis is some random textThis is some random textThis is some random textThis is some random text<br />This is some random text<br />This is some random text<br /></div> |
| 191 | + <div id="footer"> |
| 192 | + <form id="form"> |
| 193 | + <input type="submit" class="button" value="Send" /> |
| 194 | + <input type="text" id="input" class="textfield" /> |
| 195 | + </form> |
| 196 | + <div id="secondary-controls"> |
| 197 | + <div> |
| 198 | + <input name="pause" type="checkbox" checked id="autoscroll" /> |
| 199 | + <label for="autoscroll">Autoscroll</label> |
| 200 | + </div> |
| 201 | + <div> |
| 202 | + <input name="list" type="checkbox" checked id="list" /> |
| 203 | + <label for="list">Enable List Command</label> |
| 204 | + </div> |
| 205 | + <button id="clear" class="button">Clear Log</button> |
| 206 | + <button id="export" class="button">Export Log</button> |
| 207 | + </div> |
| 208 | + </div> |
| 209 | + </div> |
| 210 | + </body> |
91 | 211 | </html>
|
0 commit comments