Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory phase 2 #873

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/Http/Controllers/Entity/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ public function index(Campaign $campaign, Entity $entity)
public function create(Campaign $campaign, Entity $entity)
{
$this->authorize('update', $entity->child);

$positionPreset = request()->get('position');
$positionOptions = ['' => ''];
$positions = Inventory::positionList($campaign)->pluck('position')->all();
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
foreach ($positions as $position) {
$positionOptions[$position] = $position;
}
return view('entities.pages.inventory.create', compact(
'campaign',
'entity',
'positionPreset',
'positionOptions',
));
}

Expand Down Expand Up @@ -123,11 +130,17 @@ public function show(Campaign $campaign, Entity $entity, Inventory $inventory)
public function edit(Campaign $campaign, Entity $entity, Inventory $inventory)
{
$this->authorize('update', $entity->child);
$positionOptions = ['' => ''];
$positions = Inventory::positionList($campaign)->pluck('position')->all();
foreach ($positions as $position) {
$positionOptions[$position] = $position;
}

return view('entities.pages.inventory.update', compact(
'campaign',
'entity',
'inventory',
'positionOptions'
));
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function scopePositionList(Builder $builder, Campaign $campaign): Builder
->leftJoin('entities as e', 'e.id', 'inventories.entity_id')
->where('e.campaign_id', $campaign->id)
->orderBy('position', 'ASC')
->limit(20)
->limit(50)
;
}

Expand Down
24 changes: 24 additions & 0 deletions resources/js/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ $(document).ready(function() {
},
});
});
$.each($('.position-dropdown'), function () {
if ($(this).hasClass("select2-hidden-accessible")) {
return;
}
$(this).select2({
tags: true,
allowClear: true,
dropdownParent: $(this).data('dropdown-parent') || '',
placeholder: $(this).data('placeholder'),
minimumInputLength: 0,
createTag: function (params) {
let term = $.trim(params.term);

if (term === '') {
return null;
}
return {
id: term,
text: term,
newTag: true // add additional parameters
};
},
});
});
};

window.initTags();
Expand Down
18 changes: 6 additions & 12 deletions resources/views/entities/pages/inventory/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
if (isset($inventory) && $inventory->image_uuid) {
$preset = $inventory->image;
}
if (isset($inventory)) {
$positionPreset = $inventory->position;
}
@endphp
<x-grid>
<input type="hidden" name="item_id" value="" />
Expand Down Expand Up @@ -42,19 +45,10 @@
<x-forms.field
field="position"
:label="__('entities/inventories.fields.position')">
{!! Form::text('position', null, [
'placeholder' => __('entities/inventories.placeholders.position'),
'class' => '',
'maxlength' => 191,
'list' => 'position-list',
'autocomplete' => 'off'
{!! Form::select('position', $positionOptions, $positionPreset, [
'data-placeholder' => __('entities/inventories.placeholders.position'),
'class' => 'position-dropdown',
]) !!}

<datalist id="position-list">
@foreach (\App\Models\Inventory::positionList($campaign)->pluck('position')->all() as $name)
<option value="{{ e($name) }}">{{ e($name) }}</option>
@endforeach
</datalist>
</x-forms.field>

<x-forms.field field="description" css="col-span-2" :label="__('entities/inventories.fields.description')">
Expand Down
7 changes: 7 additions & 0 deletions resources/views/entities/pages/inventory/_inventory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<tr class="active cursor-pointer" data-animate="collapse" data-target=".inventory-group-{{ $posCount }}">
<th colspan="@if (auth()->check())5 @else 4 @endif" class="text-neutral-content text-left">
{!! $item->position ?: '<i>' . __('entities/inventories.show.unsorted') . '</i>' !!}

<a href="{{ route('entities.inventories.create', [$campaign, $entity, 'position' => $item->position]) }}"
data-toggle="dialog" data-target="inventory-dialog"
data-url="{{ route('entities.inventories.create', [$campaign, $entity, 'position' => $item->position]) }}"
>
<x-icon class="plus"></x-icon>
</a>
</th>
</tr>
<?php $previousPosition = $item->position; ?>
Expand Down
Loading