From b5e50719acd05b3abb7daa5687a397eb6095e350 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 11 Apr 2020 13:56:03 -0600 Subject: [PATCH] Remove old Theme::js calls in blade layouts. Persist checkboxes, Server Owner, Node, Default Allocation, and Additional Allocations on servers/new.blade.php --- .../Repository/UserRepositoryInterface.php | 8 ++ app/Helpers/Utilities.php | 12 ++ app/Http/Controllers/Admin/UserController.php | 7 +- app/Repositories/Eloquent/UserRepository.php | 18 +++ .../themes/pterodactyl/js/admin/new-server.js | 91 ++++++------ resources/views/admin/servers/new.blade.php | 132 ++++++++++++++---- resources/views/layouts/admin.blade.php | 6 +- resources/views/layouts/auth.blade.php | 2 +- resources/views/layouts/master.blade.php | 6 +- 9 files changed, 209 insertions(+), 73 deletions(-) diff --git a/app/Contracts/Repository/UserRepositoryInterface.php b/app/Contracts/Repository/UserRepositoryInterface.php index 41649f48b..f5ba47b4b 100644 --- a/app/Contracts/Repository/UserRepositoryInterface.php +++ b/app/Contracts/Repository/UserRepositoryInterface.php @@ -22,4 +22,12 @@ interface UserRepositoryInterface extends RepositoryInterface, SearchableInterfa * @return \Illuminate\Support\Collection */ public function filterUsersByQuery(?string $query): Collection; + + /** + * Returns a user with the given id in a format that can be used for dropdowns. + * + * @param int $id + * @return \Pterodactyl\Models\Model + */ + public function filterById(int $id): \Pterodactyl\Models\Model; } diff --git a/app/Helpers/Utilities.php b/app/Helpers/Utilities.php index 2a0689124..d900425d9 100644 --- a/app/Helpers/Utilities.php +++ b/app/Helpers/Utilities.php @@ -6,6 +6,7 @@ use Exception; use Carbon\Carbon; use Cron\CronExpression; use Illuminate\Support\Facades\Log; +use Illuminate\Support\ViewErrorBag; class Utilities { @@ -50,4 +51,15 @@ class Utilities sprintf('%s %s %s * %s', $minute, $hour, $dayOfMonth, $dayOfWeek) )->getNextRunDate()); } + + public static function checked($name, $default) + { + $errors = session('errors'); + + if (isset($errors) && $errors instanceof ViewErrorBag && $errors->any()) { + return old($name) ? 'checked' : ''; + } + + return ($default) ? 'checked' : ''; + } } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 14b3b594f..18e7e3b43 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -177,10 +177,15 @@ class UserController extends Controller * Get a JSON response of users on the system. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection|\Pterodactyl\Models\Model */ public function json(Request $request) { + // Handle single user requests. + if ($request->query('user_id')) { + return $this->repository->filterById($request->input('user_id')); + } + return $this->repository->filterUsersByQuery($request->input('q')); } } diff --git a/app/Repositories/Eloquent/UserRepository.php b/app/Repositories/Eloquent/UserRepository.php index 1ed6c5b74..b6468b5bb 100644 --- a/app/Repositories/Eloquent/UserRepository.php +++ b/app/Repositories/Eloquent/UserRepository.php @@ -54,4 +54,22 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa return $item; }); } + + /** + * Returns a user with the given id in a format that can be used for dropdowns. + * + * @param int $id + * @return \Pterodactyl\Models\Model + */ + public function filterById(int $id): \Pterodactyl\Models\Model + { + $this->setColumns([ + 'id', 'email', 'username', 'name_first', 'name_last', + ]); + + $model = $this->getBuilder()->findOrFail($id, $this->getColumns())->getModel(); + $model->md5 = md5(strtolower($model->email)); + + return $model; + } } diff --git a/public/themes/pterodactyl/js/admin/new-server.js b/public/themes/pterodactyl/js/admin/new-server.js index 3da41da0f..cf8766356 100644 --- a/public/themes/pterodactyl/js/admin/new-server.js +++ b/public/themes/pterodactyl/js/admin/new-server.js @@ -41,47 +41,6 @@ $(document).ready(function() { $('#pAllocationAdditional').select2({ placeholder: 'Select Additional Allocations', }); - - $('#pUserId').select2({ - ajax: { - url: '/admin/users/accounts.json', - dataType: 'json', - delay: 250, - data: function (params) { - return { - q: params.term, // search term - page: params.page, - }; - }, - processResults: function (data, params) { - return { results: data }; - }, - cache: true, - }, - escapeMarkup: function (markup) { return markup; }, - minimumInputLength: 2, - templateResult: function (data) { - if (data.loading) return data.text; - - return '
\ - User Image \ - \ - ' + data.name_first + ' ' + data.name_last +' \ - \ - ' + data.email + ' - ' + data.username + ' \ -
'; - }, - templateSelection: function (data) { - return '
\ - \ - User Image \ - \ - \ - ' + data.name_first + ' ' + data.name_last + ' (' + data.email + ') \ - \ -
'; - } - }); }); var lastActiveBox = null; @@ -185,3 +144,53 @@ function updateAdditionalAllocations() { } }); } + +function initUserIdSelect(data) { + $('#pUserId').select2({ + ajax: { + url: '/admin/users/accounts.json', + dataType: 'json', + delay: 250, + + data: function (params) { + return { + q: params.term, // search term + page: params.page, + }; + }, + + processResults: function (data, params) { + return { results: data }; + }, + + cache: true, + }, + + data: data, + escapeMarkup: function (markup) { return markup; }, + minimumInputLength: 2, + + templateResult: function (data) { + if (data.loading) return data.text; + + return '
\ + User Image \ + \ + ' + data.name_first + ' ' + data.name_last +' \ + \ + ' + data.email + ' - ' + data.username + ' \ +
'; + }, + + templateSelection: function (data) { + return '
\ + \ + User Image \ + \ + \ + ' + data.name_first + ' ' + data.name_last + ' (' + data.email + ') \ + \ +
'; + } + }); +} diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 7aa4477e9..59011aa46 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -26,6 +26,7 @@

Core Details

+
@@ -33,20 +34,23 @@

Character limits: a-z A-Z 0-9 _ - . and [Space] (max 200 characters).

+
- +
+
- - + +

A brief description of this server.

+
- +
@@ -55,6 +59,7 @@
+
@@ -62,6 +67,7 @@

Allocation Management

+
@@ -78,22 +84,26 @@ @endforeach +

The node which this server will be deployed to.

+
- +

The main allocation that will be assigned to this server.

+
- +

Additional allocations to assign to this server on creation.

+
@@ -101,18 +111,20 @@

Application Feature Limits

+
- +
- +

The total number of databases a user is allowed to create for this server. Leave blank to allow unlimited.

+
- +
- +

The total number of allocations a user is allowed to create for this server. Leave blank to allow unlimited.

@@ -126,71 +138,90 @@

Resource Management

+
+
- + %
-

If you do not want to limit CPU usage, set the value to 0. To determine a value, take the number of physical cores and multiply it by 100. For example, on a quad core system (4 * 100 = 400) there is 400% available. To limit a server to using half of a single core, you would set the value to 50. To allow a server to use up to two physical cores, set the value to 200. BlockIO should be a value between 10 and 1000. Please see this documentation for more information about it.

+ +

If you do not want to limit CPU usage, set the value to 0. To determine a value, take the number of physical cores and multiply it by 100. For example, on a quad core system (4 * 100 = 400) there is 400% available. To limit a server to using half of a single core, you would set the value to 50. To allow a server to use up to two physical cores, set the value to 200. BlockIO should be a value between 10 and 1000. Please see this documentation for more information about it.

+
+
- +
+

Advanced: Enter the specific CPU cores that this process can run on, or leave blank to allow all cores. This can be a single number, or a comma seperated list. Example: 0, 0-1,3, or 0,1,3,4.

+
+
- + MB
+
+
- + MB
+ +
+
- - MB + + MB
+
+
- +
-

Advanced: The IO performance of this server relative to other running containers on the system. Value should be between 10 and 1000.

+ +

Advanced: The IO performance of this server relative to other running containers on the system. Value should be between 10 and 1000.

+

Nest Configuration

+
- @foreach($nests as $nest) @endforeach +

Select the Nest that this server will be grouped under.

+
- +

Select the Egg that will define how this server should operate.

+
- +

Select a data pack to be automatically installed on this server when first created.

+
- +
+

If the selected Egg has an install script attached to it, the script will run during install after the pack is installed. If you would like to skip this step, check this box.

+

Docker Configuration

+
@@ -236,23 +274,28 @@
+

Startup Configuration

+
- +

The following data substitutes are available for the startup command: @{{SERVER_MEMORY}}, @{{SERVER_IP}}, and @{{SERVER_PORT}}. They will be replaced with the allocated memory, server IP, and server port respectively.

+

Service Variables

+
+ @section('footer-scripts') - {!! Theme::js('js/keyboard.polyfill.js') !!} - + {{--{!! Theme::js('js/keyboard.polyfill.js') !!} + --}} {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} @@ -185,7 +185,7 @@ {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js?t={cache-version}') !!} {!! Theme::js('vendor/select2/select2.full.min.js?t={cache-version}') !!} {!! Theme::js('js/admin/functions.js?t={cache-version}') !!} - {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} + {{-- {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} --}} @if(Auth::user()->root_admin) + {{--{!! Theme::js('js/keyboard.polyfill.js?t={cache-version}') !!} + --}} {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} @@ -284,7 +284,7 @@ {!! Theme::js('vendor/adminlte/app.min.js?t={cache-version}') !!} {!! Theme::js('vendor/socketio/socket.io.v203.min.js?t={cache-version}') !!} {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js?t={cache-version}') !!} - {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} + {{-- {!! Theme::js('js/autocomplete.js?t={cache-version}') !!} --}} @if(Auth::user()->root_admin)