Skip to content

Commit b5e5071

Browse files
committed
Remove old Theme::js calls in blade layouts. Persist checkboxes, Server Owner, Node, Default Allocation, and Additional Allocations on servers/new.blade.php
1 parent fb96d94 commit b5e5071

File tree

9 files changed

+209
-73
lines changed

9 files changed

+209
-73
lines changed

app/Contracts/Repository/UserRepositoryInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ public function getAllUsersWithCounts(): LengthAwarePaginator;
2222
* @return \Illuminate\Support\Collection
2323
*/
2424
public function filterUsersByQuery(?string $query): Collection;
25+
26+
/**
27+
* Returns a user with the given id in a format that can be used for dropdowns.
28+
*
29+
* @param int $id
30+
* @return \Pterodactyl\Models\Model
31+
*/
32+
public function filterById(int $id): \Pterodactyl\Models\Model;
2533
}

app/Helpers/Utilities.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Carbon\Carbon;
77
use Cron\CronExpression;
88
use Illuminate\Support\Facades\Log;
9+
use Illuminate\Support\ViewErrorBag;
910

1011
class Utilities
1112
{
@@ -50,4 +51,15 @@ public static function getScheduleNextRunDate(string $minute, string $hour, stri
5051
sprintf('%s %s %s * %s', $minute, $hour, $dayOfMonth, $dayOfWeek)
5152
)->getNextRunDate());
5253
}
54+
55+
public static function checked($name, $default)
56+
{
57+
$errors = session('errors');
58+
59+
if (isset($errors) && $errors instanceof ViewErrorBag && $errors->any()) {
60+
return old($name) ? 'checked' : '';
61+
}
62+
63+
return ($default) ? 'checked' : '';
64+
}
5365
}

app/Http/Controllers/Admin/UserController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,15 @@ public function update(UserFormRequest $request, User $user)
177177
* Get a JSON response of users on the system.
178178
*
179179
* @param \Illuminate\Http\Request $request
180-
* @return \Illuminate\Support\Collection
180+
* @return \Illuminate\Support\Collection|\Pterodactyl\Models\Model
181181
*/
182182
public function json(Request $request)
183183
{
184+
// Handle single user requests.
185+
if ($request->query('user_id')) {
186+
return $this->repository->filterById($request->input('user_id'));
187+
}
188+
184189
return $this->repository->filterUsersByQuery($request->input('q'));
185190
}
186191
}

app/Repositories/Eloquent/UserRepository.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,22 @@ public function filterUsersByQuery(?string $query): Collection
5454
return $item;
5555
});
5656
}
57+
58+
/**
59+
* Returns a user with the given id in a format that can be used for dropdowns.
60+
*
61+
* @param int $id
62+
* @return \Pterodactyl\Models\Model
63+
*/
64+
public function filterById(int $id): \Pterodactyl\Models\Model
65+
{
66+
$this->setColumns([
67+
'id', 'email', 'username', 'name_first', 'name_last',
68+
]);
69+
70+
$model = $this->getBuilder()->findOrFail($id, $this->getColumns())->getModel();
71+
$model->md5 = md5(strtolower($model->email));
72+
73+
return $model;
74+
}
5775
}

public/themes/pterodactyl/js/admin/new-server.js

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,6 @@ $(document).ready(function() {
4141
$('#pAllocationAdditional').select2({
4242
placeholder: 'Select Additional Allocations',
4343
});
44-
45-
$('#pUserId').select2({
46-
ajax: {
47-
url: '/admin/users/accounts.json',
48-
dataType: 'json',
49-
delay: 250,
50-
data: function (params) {
51-
return {
52-
q: params.term, // search term
53-
page: params.page,
54-
};
55-
},
56-
processResults: function (data, params) {
57-
return { results: data };
58-
},
59-
cache: true,
60-
},
61-
escapeMarkup: function (markup) { return markup; },
62-
minimumInputLength: 2,
63-
templateResult: function (data) {
64-
if (data.loading) return data.text;
65-
66-
return '<div class="user-block"> \
67-
<img class="img-circle img-bordered-xs" src="https://www.gravatar.com/avatar/' + data.md5 + '?s=120" alt="User Image"> \
68-
<span class="username"> \
69-
<a href="#">' + data.name_first + ' ' + data.name_last +'</a> \
70-
</span> \
71-
<span class="description"><strong>' + data.email + '</strong> - ' + data.username + '</span> \
72-
</div>';
73-
},
74-
templateSelection: function (data) {
75-
return '<div> \
76-
<span> \
77-
<img class="img-rounded img-bordered-xs" src="https://www.gravatar.com/avatar/' + data.md5 + '?s=120" style="height:28px;margin-top:-4px;" alt="User Image"> \
78-
</span> \
79-
<span style="padding-left:5px;"> \
80-
' + data.name_first + ' ' + data.name_last + ' (<strong>' + data.email + '</strong>) \
81-
</span> \
82-
</div>';
83-
}
84-
});
8544
});
8645

8746
var lastActiveBox = null;
@@ -185,3 +144,53 @@ function updateAdditionalAllocations() {
185144
}
186145
});
187146
}
147+
148+
function initUserIdSelect(data) {
149+
$('#pUserId').select2({
150+
ajax: {
151+
url: '/admin/users/accounts.json',
152+
dataType: 'json',
153+
delay: 250,
154+
155+
data: function (params) {
156+
return {
157+
q: params.term, // search term
158+
page: params.page,
159+
};
160+
},
161+
162+
processResults: function (data, params) {
163+
return { results: data };
164+
},
165+
166+
cache: true,
167+
},
168+
169+
data: data,
170+
escapeMarkup: function (markup) { return markup; },
171+
minimumInputLength: 2,
172+
173+
templateResult: function (data) {
174+
if (data.loading) return data.text;
175+
176+
return '<div class="user-block"> \
177+
<img class="img-circle img-bordered-xs" src="https://www.gravatar.com/avatar/' + data.md5 + '?s=120" alt="User Image"> \
178+
<span class="username"> \
179+
<a href="#">' + data.name_first + ' ' + data.name_last +'</a> \
180+
</span> \
181+
<span class="description"><strong>' + data.email + '</strong> - ' + data.username + '</span> \
182+
</div>';
183+
},
184+
185+
templateSelection: function (data) {
186+
return '<div> \
187+
<span> \
188+
<img class="img-rounded img-bordered-xs" src="https://www.gravatar.com/avatar/' + data.md5 + '?s=120" style="height:28px;margin-top:-4px;" alt="User Image"> \
189+
</span> \
190+
<span style="padding-left:5px;"> \
191+
' + data.name_first + ' ' + data.name_last + ' (<strong>' + data.email + '</strong>) \
192+
</span> \
193+
</div>';
194+
}
195+
});
196+
}

0 commit comments

Comments
 (0)