mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-09-09 19:55:22 -05:00
Fixed template and Js of the item-selector because it only worked if it was only one time on the page.
Added user-selector dropdown with data fetching from the backend. Fix a null error in the inbox-message component.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
@@ -31,6 +32,8 @@ class UsersController extends AdminToolController
|
||||
|
||||
const PER_PAGE = 15;
|
||||
|
||||
const USER_DROPDOWN_PER_PAGE = 20;
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if(!Auth::user()->can(Permissions::VIEW_USERS->value))
|
||||
@@ -91,6 +94,41 @@ public function edit(User $user, EditUserRequest $request)
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function getUsersForDropdown(Request $request)
|
||||
{
|
||||
if(!Auth::check() && Auth::user()->can(Permissions::VIEW_USERS->value))
|
||||
abort(403, 'No Permission to get this Data');
|
||||
|
||||
$searchTerm = $request->input('term');
|
||||
|
||||
if($searchTerm === null)
|
||||
abort(400, 'Search term must be provided.');
|
||||
|
||||
$query = User::orderBy('last_known_username')
|
||||
->orWhere('id', 'LIKE', '%'.$searchTerm.'%')
|
||||
->orWhere('steam_id', 'LIKE', '%'.$searchTerm.'%')
|
||||
->orWhere('last_known_username', 'LIKE', '%'.$searchTerm.'%')
|
||||
->select(['id', 'last_known_username']);
|
||||
|
||||
/** @var Collection|LengthAwarePaginator $users */
|
||||
$users = $query->paginate(static::USER_DROPDOWN_PER_PAGE);
|
||||
|
||||
$result = [];
|
||||
$users->each(function ($user) use (&$result) {
|
||||
$result[] = [
|
||||
'id' => $user->id,
|
||||
'text' => $user->last_known_username,
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'results' => $result,
|
||||
'pagination' => [
|
||||
'more' => $users->currentPage() < $users->lastPage(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function reset(User $user)
|
||||
{
|
||||
$canReset = Auth::check() && Auth::user()->can(Permissions::EDIT_USERS->value);
|
||||
|
||||
Reference in New Issue
Block a user