Skip to content

Commit e47bb6e

Browse files
committed
Add multiplicators to certain inputs, closes pterodactyl#154
Allows for users to enter `10g` into a memory field and have it converted to 10GB equivalent in MB.
1 parent 90cd2b6 commit e47bb6e

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

public/js/admin.min.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,24 @@ $(document).ready(function () {
4646
centerModal($(this));
4747
});
4848
$(window).on('resize', centerModal);
49+
50+
// Idea code for multiplicators submitted by @Taronyuu on Github
51+
// https://github.com/Pterodactyl/Panel/issues/154#issuecomment-257116078
52+
$('input[data-multiplicator="true"]').on('change', function () {
53+
var value = $(this).val();
54+
if (!/^\d+$/.test(value)) {
55+
var multiplicator = value.replace(/[0-9]/g, '').toLowerCase();
56+
value = value.replace(/\D/g, '');
57+
58+
if (multiplicator === 't') {
59+
value = value * (1024 * 1024);
60+
}
61+
62+
if (multiplicator === 'g') {
63+
value = value * 1024;
64+
}
65+
}
66+
67+
$(this).val(value);
68+
});
4969
});

resources/views/admin/nodes/new.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@
9292
<div class="form-group col-md-6 col-xs-6">
9393
<label for="memory" class="control-label">Total Memory</label>
9494
<div class="input-group">
95-
<input type="text" name="memory" class="form-control" value="{{ old('memory') }}"/>
95+
<input type="text" name="memory" data-multiplicator="true" class="form-control" value="{{ old('memory') }}"/>
9696
<span class="input-group-addon">MB</span>
9797
</div>
9898
</div>
9999
<div class="form-group col-md-6 col-xs-6">
100100
<label for="memory_overallocate" class="control-label">Overallocate</label>
101101
<div class="input-group">
102-
<input type="text" name="memory_overallocate" class="form-control" value="{{ old('memory_overallocate', 0) }}"/>
102+
<input type="text" name="memory_overallocate" data-multiplicator="true" class="form-control" value="{{ old('memory_overallocate', 0) }}"/>
103103
<span class="input-group-addon">%</span>
104104
</div>
105105
</div>

resources/views/admin/nodes/view.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
<div class="form-group col-md-3 col-xs-6">
184184
<label for="memory" class="control-label">Total Memory</label>
185185
<div class="input-group">
186-
<input type="text" name="memory" class="form-control" value="{{ old('memory', $node->memory) }}"/>
186+
<input type="text" name="memory" class="form-control" data-multiplicator="true" value="{{ old('memory', $node->memory) }}"/>
187187
<span class="input-group-addon">MB</span>
188188
</div>
189189
</div>
@@ -197,7 +197,7 @@
197197
<div class="form-group col-md-3 col-xs-6">
198198
<label for="disk" class="control-label">Disk Space</label>
199199
<div class="input-group">
200-
<input type="text" name="disk" class="form-control" value="{{ old('disk', $node->disk) }}"/>
200+
<input type="text" name="disk" class="form-control" data-multiplicator="true" value="{{ old('disk', $node->disk) }}"/>
201201
<span class="input-group-addon">MB</span>
202202
</div>
203203
</div>

resources/views/admin/servers/new.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@
118118
<div class="form-group col-md-4 col-xs-4">
119119
<label for="memory" class="control-label">Memory</label>
120120
<div class="input-group">
121-
<input type="text" name="memory" class="form-control" value="{{ old('memory') }}"/>
121+
<input type="text" name="memory" data-multiplicator="true" class="form-control" value="{{ old('memory') }}"/>
122122
<span class="input-group-addon">MB</span>
123123
</div>
124124
</div>
125125
<div class="form-group col-md-4 col-xs-4">
126126
<label for="memory" class="control-label">Swap</label>
127127
<div class="input-group">
128-
<input type="text" name="swap" class="form-control" value="{{ old('swap', 0) }}"/>
128+
<input type="text" name="swap" data-multiplicator="true" class="form-control" value="{{ old('swap', 0) }}"/>
129129
<span class="input-group-addon">MB</span>
130130
</div>
131131
</div>
@@ -150,7 +150,7 @@
150150
<div class="form-group col-md-4 col-xs-4">
151151
<label for="disk" class="control-label">Disk Space</label>
152152
<div class="input-group">
153-
<input type="text" name="disk" class="form-control" value="{{ old('disk') }}"/>
153+
<input type="text" name="disk" data-multiplicator="true" class="form-control" value="{{ old('disk') }}"/>
154154
<span class="input-group-addon">MB</span>
155155
</div>
156156
</div>

resources/views/admin/servers/view.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@
228228
<div class="col-md-6 form-group {{ $errors->has('memory') ? 'has-error' : '' }}">
229229
<label for="memory" class="control-label">Allocated Memory</label>
230230
<div class="input-group">
231-
<input type="text" name="memory" class="form-control" value="{{ old('memory', $server->memory) }}"/>
231+
<input type="text" name="memory" data-multiplicator="true" class="form-control" value="{{ old('memory', $server->memory) }}"/>
232232
<span class="input-group-addon">MB</span>
233233
</div>
234234
</div>
235235
<div class="col-md-6 form-group {{ $errors->has('swap') ? 'has-error' : '' }}">
236236
<label for="swap" class="control-label">Allocated Swap</label>
237237
<div class="input-group">
238-
<input type="text" name="swap" class="form-control" value="{{ old('swap', $server->swap) }}"/>
238+
<input type="text" name="swap" data-multiplicator="true" class="form-control" value="{{ old('swap', $server->swap) }}"/>
239239
<span class="input-group-addon">MB</span>
240240
</div>
241241
<p class="text-muted"><small>Setting this to <code>0</code> will disable swap space on this server.</small></p>

0 commit comments

Comments
 (0)