Skip to content

Commit

Permalink
feat(filters): add extra filtering in various locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Sep 16, 2024
1 parent 0d5aa3a commit 7aa04e5
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 9 deletions.
10 changes: 8 additions & 2 deletions app/Http/Controllers/Admin/Data/LootTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ class LootTableController extends Controller {
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getIndex() {
public function getIndex(Request $request) {
$query = LootTable::query();

if ($request->get('name')) {
$query->where('name', 'LIKE', '%'.$request->get('name').'%');
}

return view('admin.loot_tables.loot_tables', [
'tables' => LootTable::paginate(20),
'tables' => $query->paginate(20)->appends($request->query()),
]);
}

Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/Characters/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,33 @@ public function getCharacterImages($slug) {
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getCharacterInventory($slug) {
public function getCharacterInventory(Request $request, $slug) {
$categories = ItemCategory::visible(Auth::user() ?? null)->where('is_character_owned', '1')->orderBy('sort', 'DESC')->get();
$itemOptions = Item::whereIn('item_category_id', $categories->pluck('id'));

$query = Item::query();
$data = $request->only(['item_category_id', 'name', 'artist']);
if (isset($data['item_category_id']) && $data['item_category_id'] != 'none') {
$query->where('item_category_id', $data['item_category_id']);
}
if (isset($data['name'])) {
$query->where('name', 'LIKE', '%'.$data['name'].'%');
}
if (isset($data['artist']) && $data['artist'] != 'none') {
$query->where('artist_id', $data['artist']);
}

$items = count($categories) ?
$this->character->items()
->whereIn('items.id', $query->pluck('id')->toArray())
->where('count', '>', 0)
->orderByRaw('FIELD(item_category_id,'.implode(',', $categories->pluck('id')->toArray()).')')
->orderBy('name')
->orderBy('updated_at')
->get()
->groupBy(['item_category_id', 'id']) :
$this->character->items()
->whereIn('items.id', $query->pluck('id')->toArray())
->where('count', '>', 0)
->orderBy('name')
->orderBy('updated_at')
Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/Users/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,31 @@ class InventoryController extends Controller {
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getIndex() {
public function getIndex(Request $request) {
$categories = ItemCategory::visible(Auth::user() ?? null)->orderBy('sort', 'DESC')->get();
$query = Item::query();
$data = $request->only(['item_category_id', 'name', 'artist']);
if (isset($data['item_category_id']) && $data['item_category_id'] != 'none') {
$query->where('item_category_id', $data['item_category_id']);
}
if (isset($data['name'])) {
$query->where('name', 'LIKE', '%'.$data['name'].'%');
}
if (isset($data['artist']) && $data['artist'] != 'none') {
$query->where('artist_id', $data['artist']);
}

$items = count($categories) ?
Auth::user()->items()
->whereIn('items.id', $query->pluck('id')->toArray())
->where('count', '>', 0)
->orderByRaw('FIELD(item_category_id,'.implode(',', $categories->pluck('id')->toArray()).')')
->orderBy('name')
->orderBy('updated_at')
->get()
->groupBy(['item_category_id', 'id']) :
Auth::user()->items()
->whereIn('items.id', $query->pluck('id')->toArray())
->where('count', '>', 0)
->orderBy('name')
->orderBy('updated_at')
Expand Down
30 changes: 27 additions & 3 deletions app/Http/Controllers/Users/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\Gallery\GallerySubmission;
use App\Models\Item\Item;
use App\Models\Item\ItemCategory;
use App\Models\Prompt\Prompt;
use App\Models\User\User;
use App\Models\User\UserCurrency;
use App\Models\User\UserUpdateLog;
Expand Down Expand Up @@ -197,17 +198,31 @@ public function getUserMyoSlots($name) {
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getUserInventory($name) {
public function getUserInventory(Request $request, $name) {
$categories = ItemCategory::visible(Auth::user() ?? null)->orderBy('sort', 'DESC')->get();
$query = Item::query();
$data = $request->only(['item_category_id', 'name', 'artist']);
if (isset($data['item_category_id']) && $data['item_category_id'] != 'none') {
$query->where('item_category_id', $data['item_category_id']);
}
if (isset($data['name'])) {
$query->where('name', 'LIKE', '%'.$data['name'].'%');
}
if (isset($data['artist']) && $data['artist'] != 'none') {
$query->where('artist_id', $data['artist']);
}

$items = count($categories) ?
$this->user->items()
->whereIn('items.id', $query->pluck('id')->toArray())
->where('count', '>', 0)
->orderByRaw('FIELD(item_category_id,'.implode(',', $categories->pluck('id')->toArray()).')')
->orderBy('name')
->orderBy('updated_at')
->get()
->groupBy(['item_category_id', 'id']) :
$this->user->items()
->whereIn('items.id', $query->pluck('id')->toArray())
->where('count', '>', 0)
->orderBy('name')
->orderBy('updated_at')
Expand Down Expand Up @@ -296,10 +311,19 @@ public function getUserOwnershipLogs($name) {
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getUserSubmissions($name) {
public function getUserSubmissions(Request $request, $name) {
$logs = $this->user->getSubmissions(Auth::user() ?? null);
if ($request->get('prompt_ids')) {
$logs->whereIn('prompt_id', $request->get('prompt_ids'));
}
if ($request->get('sort')) {
$logs->orderBy('created_at', $request->get('sort') == 'newest' ? 'DESC' : 'ASC');
}

return view('user.submission_logs', [
'user' => $this->user,
'logs' => $this->user->getSubmissions(Auth::user() ?? null),
'logs' => $logs->paginate(30)->appends($request->query()),
'prompts' => Prompt::active()->pluck('name', 'id'),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public function updateArtDesignCredits() {
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
public function getSubmissions($user = null) {
return Submission::with('user')->with('prompt')->viewable($user ? $user : null)->where('user_id', $this->id)->orderBy('id', 'DESC')->paginate(30);
return Submission::with('user')->with('prompt')->viewable($user ? $user : null)->where('user_id', $this->id)->orderBy('id', 'DESC');
}

/**
Expand Down
14 changes: 14 additions & 0 deletions resources/views/admin/loot_tables/loot_tables.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
<p>Loot tables can be attached to prompts as a reward for doing the prompt. This will roll a random reward from the contents of the table. Tables can be chained as well.</p>

<div class="text-right mb-3"><a class="btn btn-primary" href="{{ url('admin/data/loot-tables/create') }}"><i class="fas fa-plus"></i> Create New Loot Table</a></div>

<div>
{!! Form::open(['method' => 'GET', 'class' => '']) !!}
<div class="form-inline justify-content-end">
<div class="form-group ml-3 mb-3">
{!! Form::text('name', Request::get('name'), ['class' => 'form-control', 'placeholder' => 'Name']) !!}
</div>
<div class="form-group ml-3 mb-3">
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>

@if (!count($tables))
<p>No loot tables found.</p>
@else
Expand Down
23 changes: 22 additions & 1 deletion resources/views/character/inventory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@
</div>
</div>

<div>
{!! Form::open(['method' => 'GET', 'class' => '']) !!}
<div class="form-inline justify-content-end">
<div class="form-group ml-3 mb-3">
{!! Form::text('name', Request::get('name'), ['class' => 'form-control', 'placeholder' => 'Name']) !!}
</div>
<div class="form-group ml-3 mb-3">
{!! Form::select('item_category_id', $categories->pluck('name', 'id'), Request::get('item_category_id'), ['class' => 'form-control', 'placeholder' => 'Any Category']) !!}
</div>
@if (config('lorekeeper.extensions.item_entry_expansion.extra_fields'))
<div class="form-group ml-3 mb-3">
{!! Form::select('artist', $artists, Request::get('artist'), ['class' => 'form-control']) !!}
</div>
@endif
<div class="form-group ml-3 mb-3">
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>

<div id="defView" class="hide">
@foreach ($items as $categoryId => $categoryItems)
<div class="card mb-3 inventory-category">
Expand Down Expand Up @@ -174,7 +195,7 @@
<a href="#" class="remove-item btn btn-danger mb-2 disabled">×</a>
</div>
</div>
<div><a href="#" class="btn btn-primary" id="add-item">Add Item</a></div>
<div class="mb-2"><a href="#" class="btn btn-primary" id="add-item">Add Item</a></div>
<div class="item-row hide mb-2">
{!! Form::select('item_ids[]', $itemOptions, null, ['class' => 'form-control mr-2 item-select', 'placeholder' => 'Select Item']) !!}
{!! Form::text('quantities[]', 1, ['class' => 'form-control mr-2', 'placeholder' => 'Quantity']) !!}
Expand Down
21 changes: 21 additions & 0 deletions resources/views/home/inventory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@
</div>
</div>

<div>
{!! Form::open(['method' => 'GET', 'class' => '']) !!}
<div class="form-inline justify-content-end">
<div class="form-group ml-3 mb-3">
{!! Form::text('name', Request::get('name'), ['class' => 'form-control', 'placeholder' => 'Name']) !!}
</div>
<div class="form-group ml-3 mb-3">
{!! Form::select('item_category_id', $categories->pluck('name', 'id'), Request::get('item_category_id'), ['class' => 'form-control', 'placeholder' => 'Any Category']) !!}
</div>
@if (config('lorekeeper.extensions.item_entry_expansion.extra_fields'))
<div class="form-group ml-3 mb-3">
{!! Form::select('artist', $artists, Request::get('artist'), ['class' => 'form-control']) !!}
</div>
@endif
<div class="form-group ml-3 mb-3">
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>

<div id="defView" class="hide">
@foreach ($items as $categoryId => $categoryItems)
<div class="card mb-3 inventory-category">
Expand Down
21 changes: 21 additions & 0 deletions resources/views/user/inventory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
</div>
</div>

<div>
{!! Form::open(['method' => 'GET', 'class' => '']) !!}
<div class="form-inline justify-content-end">
<div class="form-group ml-3 mb-3">
{!! Form::text('name', Request::get('name'), ['class' => 'form-control', 'placeholder' => 'Name']) !!}
</div>
<div class="form-group ml-3 mb-3">
{!! Form::select('item_category_id', $categories->pluck('name', 'id'), Request::get('item_category_id'), ['class' => 'form-control', 'placeholder' => 'Any Category']) !!}
</div>
@if (config('lorekeeper.extensions.item_entry_expansion.extra_fields'))
<div class="form-group ml-3 mb-3">
{!! Form::select('artist', $artists, Request::get('artist'), ['class' => 'form-control']) !!}
</div>
@endif
<div class="form-group ml-3 mb-3">
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>

<div id="defView" class="hide">
@foreach ($items as $categoryId => $categoryItems)
<div class="card mb-3 inventory-category">
Expand Down
31 changes: 31 additions & 0 deletions resources/views/user/submission_logs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
{!! $user->displayName !!}'s Submissions
</h1>

<div>
{!! Form::open(['method' => 'GET', 'class' => '']) !!}
<div class="form-inline justify-content-end">
<div class="form-group ml-3 mb-2 col-3">
{!! Form::select('prompt_ids[]', $prompts, Request::get('prompt_ids'), ['class' => 'form-control selectize col-12', 'multiple', 'placeholder' => 'Any Prompt']) !!}
</div>
<div class="form-group ml-1 mb-3">
{!! Form::select(
'sort',
[
'newest' => 'Newest First',
'oldest' => 'Oldest First',
],
Request::get('sort') ?: 'newest',
['class' => 'form-control'],
) !!}
</div>
<div class="form-group ml-3 mb-3">
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>

{!! $logs->render() !!}
<div class="mb-4 logs-table">
<div class="logs-table-header">
Expand Down Expand Up @@ -57,3 +81,10 @@
</div>
{!! $logs->render() !!}
@endsection
@section('scripts')
<script>
$(document).ready(function() {
$('.selectize').selectize();
});
</script>
@endsection

0 comments on commit 7aa04e5

Please sign in to comment.