Skip to content

Commit 344e3b4

Browse files
committed
add console notification on new output that is out of view
fix the revealing module pattern (browser cache 😒) change graph colors to theme primary color move Socket.on(‚console’) to console.js
1 parent 5142dce commit 344e3b4

File tree

4 files changed

+75
-32
lines changed

4 files changed

+75
-32
lines changed

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,24 @@ td.has-progress {
125125
.no-margin {
126126
margin: 0 !important;
127127
}
128+
129+
.position-relative {
130+
position: relative;
131+
}
132+
133+
.terminal-notify {
134+
position: absolute;
135+
right: 10px;
136+
bottom: 10px;
137+
/* Browsers usually have a 17px scrollbar which is visible in the terminal */
138+
padding: 7px 24px 7px 7px;
139+
border-top-left-radius: 3px;
140+
background: white;
141+
color: black;
142+
opacity: .5;
143+
cursor: pointer;
144+
}
145+
146+
.terminal-notify:hover {
147+
opacity: .9;
148+
}

public/themes/pterodactyl/js/frontend/console.js

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
20-
var CONSOLE_PUSH_COUNT = 50;
21-
var CONSOLE_PUSH_FREQ = 200;
2220

23-
const Console = (function () {
21+
var Console = (function () {
22+
var CONSOLE_PUSH_COUNT = 50;
23+
var CONSOLE_PUSH_FREQ = 200;
2424

2525
var terminalQueue;
2626
var terminal;
@@ -31,8 +31,10 @@ const Console = (function () {
3131
var memoryData;
3232
var timeLabels;
3333

34+
var $terminalNotify;
35+
3436
function initConsole() {
35-
termianlQueue = [];
37+
terminalQueue = [];
3638
terminal = $('#terminal').terminal(function (command, term) {
3739
Socket.emit('send command', command);
3840
}, {
@@ -47,13 +49,25 @@ const Console = (function () {
4749
return false;
4850
}
4951
});
52+
53+
$terminalNotify = $('#terminalNotify');
54+
$terminalNotify.on('click', function () {
55+
terminal.scroll_to_bottom();
56+
$terminalNotify.addClass('hidden');
57+
})
58+
59+
terminal.on('scroll', function () {
60+
if (terminal.is_bottom()) {
61+
$terminalNotify.addClass('hidden');
62+
}
63+
})
5064
}
5165

5266
function initGraphs() {
5367
var ctc = $('#chart_cpu');
54-
var timeLabels = [];
55-
var cpuData = [];
56-
var CPUChart = new Chart(ctc, {
68+
timeLabels = [];
69+
cpuData = [];
70+
cpuChart = new Chart(ctc, {
5771
type: 'line',
5872
data: {
5973
labels: timeLabels,
@@ -62,17 +76,17 @@ const Console = (function () {
6276
label: "Percent Use",
6377
fill: false,
6478
lineTension: 0.03,
65-
backgroundColor: "#00A1CB",
66-
borderColor: "#00A1CB",
79+
backgroundColor: "#3c8dbc",
80+
borderColor: "#3c8dbc",
6781
borderCapStyle: 'butt',
6882
borderDash: [],
6983
borderDashOffset: 0.0,
7084
borderJoinStyle: 'miter',
71-
pointBorderColor: "rgba(75,192,192,1)",
85+
pointBorderColor: "#3c8dbc",
7286
pointBackgroundColor: "#fff",
7387
pointBorderWidth: 1,
7488
pointHoverRadius: 5,
75-
pointHoverBackgroundColor: "rgba(75,192,192,1)",
89+
pointHoverBackgroundColor: "#3c8dbc",
7690
pointHoverBorderColor: "rgba(220,220,220,1)",
7791
pointHoverBorderWidth: 2,
7892
pointRadius: 1,
@@ -97,8 +111,8 @@ const Console = (function () {
97111
});
98112

99113
var ctm = $('#chart_memory');
100-
var memoryData = [];
101-
var MemoryChart = new Chart(ctm, {
114+
memoryData = [];
115+
memoryChart = new Chart(ctm, {
102116
type: 'line',
103117
data: {
104118
labels: timeLabels,
@@ -107,17 +121,17 @@ const Console = (function () {
107121
label: "Memory Use",
108122
fill: false,
109123
lineTension: 0.03,
110-
backgroundColor: "#01A4A4",
111-
borderColor: "#01A4A4",
124+
backgroundColor: "#3c8dbc",
125+
borderColor: "#3c8dbc",
112126
borderCapStyle: 'butt',
113127
borderDash: [],
114128
borderDashOffset: 0.0,
115129
borderJoinStyle: 'miter',
116-
pointBorderColor: "rgba(75,192,192,1)",
130+
pointBorderColor: "#3c8dbc",
117131
pointBackgroundColor: "#fff",
118132
pointBorderWidth: 1,
119133
pointHoverRadius: 5,
120-
pointHoverBackgroundColor: "rgba(75,192,192,1)",
134+
pointHoverBackgroundColor: "#3c8dbc",
121135
pointHoverBorderColor: "rgba(220,220,220,1)",
122136
pointHoverBorderWidth: 2,
123137
pointRadius: 1,
@@ -158,6 +172,10 @@ const Console = (function () {
158172
updateServerPowerControls(data.status);
159173
});
160174

175+
Socket.on('console', function (data) {
176+
terminalQueue.push(data.line);
177+
});
178+
161179
Socket.on('proc', function (proc) {
162180
if (cpuData.length > 10) {
163181
cpuData.shift();
@@ -172,20 +190,25 @@ const Console = (function () {
172190
var m = new Date();
173191
timeLabels.push($.format.date(new Date(), 'HH:mm:ss'));
174192

175-
CPUChart.update();
176-
MemoryChart.update();
193+
cpuChart.update();
194+
memoryChart.update();
177195
});
178196
}
179197

180198
function pushOutputQueue() {
181-
if (termianlQueue.length > CONSOLE_PUSH_COUNT) {
199+
if (terminalQueue.length > CONSOLE_PUSH_COUNT) {
182200
// console throttled warning show
183201
}
184202

185-
if (termianlQueue.length > 0) {
186-
for (var i = 0; i < CONSOLE_PUSH_COUNT && termianlQueue.length > 0; i++) {
187-
terminal.echo(termianlQueue[0]);
188-
termianlQueue.shift();
203+
if (terminalQueue.length > 0) {
204+
for (var i = 0; i < CONSOLE_PUSH_COUNT && terminalQueue.length > 0; i++) {
205+
terminal.echo(terminalQueue[0]);
206+
terminalQueue.shift();
207+
}
208+
209+
// Show
210+
if (!terminal.is_bottom()) {
211+
$terminalNotify.removeClass('hidden');
189212
}
190213
}
191214

@@ -226,16 +249,16 @@ const Console = (function () {
226249
});
227250
},
228251

229-
getTerminal: function() {
252+
getTerminal: function () {
230253
return terminal
231254
},
232255

233-
getTerminalQueue: function() {
256+
getTerminalQueue: function () {
234257
return terminalQueue
235258
},
236259
}
237260

238-
});
261+
})();
239262

240263
$(document).ready(function () {
241264
Console.init();

public/themes/pterodactyl/js/frontend/server.socket.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
Socket.on('status', function (data) {
7474
setStatusIcon(data.status);
7575
});
76-
77-
Socket.on('console', function (data) {
78-
TerminalQueue.push(data.line);
79-
});
8076
})();
8177

8278
function setStatusIcon(status) {

resources/themes/pterodactyl/server/index.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
<div class="row">
4141
<div class="col-xs-12">
4242
<div class="box">
43-
<div class="box-body">
43+
<div class="box-body position-relative">
4444
<div id="terminal" style="width:100%;"></div>
45+
<div id="terminalNotify" class="terminal-notify hidden">
46+
<i class="fa fa-bell"></i>
47+
</div>
4548
</div>
4649
<div class="box-footer text-center">
4750
@can('power-start', $server)<button class="btn btn-success disabled" data-attr="power" data-action="start">Start</button>@endcan

0 commit comments

Comments
 (0)