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

Inventories delete section #883

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 23 additions & 2 deletions app/Http/Controllers/Entity/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreInventory;
use App\Http\Requests\UpdateInventory;
use Illuminate\Http\Request;
use App\Models\Campaign;
use App\Models\Entity;
use App\Models\Inventory;
Expand Down Expand Up @@ -102,8 +103,6 @@ public function store(StoreInventory $request, Campaign $campaign, Entity $entit
]);
}



return redirect()
->route('entities.inventory', [$campaign, $entity])
->with('success_raw', $success);
Expand Down Expand Up @@ -156,6 +155,28 @@ public function update(UpdateInventory $request, Campaign $campaign, Entity $ent
]));
}

/**
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
*/
public function deleteSection(Campaign $campaign, Entity $entity, Request $request)
{
$this->authorize('update', $entity->child);

$position = $request->get('position');

if (isset($position) && $position !== __('entities/inventories.default_position')) {
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
Inventory::where('entity_id', $entity->id)->where('position', $position)->delete();
} else {
Inventory::where('entity_id', $entity->id)->where('position', '')->delete();
}

return redirect()
->route('entities.inventory', [$campaign, $entity])
->with('success_raw', __('entities/inventories.destroy.success_position', [
'position' => $position,
'entity' => $entity->name
]));
}

/**
*/
public function destroy(Campaign $campaign, Entity $entity, Inventory $inventory)
Expand Down
4 changes: 4 additions & 0 deletions app/View/Components/Button/DeleteConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DeleteConfirm extends Component
public ?string $size;
public ?string $text;
public ?string $css;
public ?bool $iconOnly;

/**
* Create a new component instance.
*/
Expand All @@ -20,11 +22,13 @@ public function __construct(
string $size = null,
string $text = null,
string $css = null,
bool $iconOnly = false,
) {
$this->target = $target;
$this->size = $size;
$this->text = $text;
$this->css = $css;
$this->iconOnly = $iconOnly;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lang/en/entities/inventories.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
'success_bulk' => '{0} No item added to :entity.|{1} Added :count item to :entity.|[2,*] Added :count items to :entity.',
'title' => 'Add an Item to :name',
],
'default_position' => 'Unorganised',
'destroy' => [
'success' => 'Item :item removed from :entity.',
'default_position' => 'Unorganised',
'destroy' => [
'success' => 'Item :item removed from :entity.',
'success_position' => 'Items in :position removed from :entity.',
],
'fields' => [
'amount' => 'Quantity',
Expand Down
1 change: 1 addition & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ function initDynamicDelete() {
}

$(this).data('confirming', 1);
$(this).find('span').addClass('md:inline');
$(this).find('span').html($(this).data('confirm'));
});

Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/button/delete-confirm.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
data-target="{{ $target }}"
>
<x-icon class="trash"></x-icon>
<span class="hidden md:inline">{{ $text ?? __('crud.remove') }}</span>
<span class="hidden @if(!$iconOnly) md:inline @endif">{{ $text ?? __('crud.remove') }}</span>
</a>
12 changes: 9 additions & 3 deletions resources/views/entities/pages/inventory/_grid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@foreach ($entity->orderedInventory() as $position => $items)
<div class="flex flex-col gap-4" data-position="{{ \Illuminate\Support\Str::slug($position) }}">
<div class="section-title flex gap-4 items-center">

<h2 class="grow text-2xl">
<x-icon class="fa-solid fa-arrow-right" />
{!! $position ?? "Unsorted" !!}
Expand All @@ -29,11 +28,18 @@ class="btn2 btn-default btn-sm"
<a href="#" class="rounded hidden link link-accent bg-box">
<x-icon class="fa-solid fa-times" />
</a>
<td class="text-right">
<x-button.delete-confirm size="sm" target="#delete-position-{{ \Illuminate\Support\Str::slug($position) }}" iconOnly=true />
{!! Form::open(['method' => 'DELETE',
'route' => ['entities.inventory.delete.section', $campaign, $entity, 'position' => $position],
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
'style'=>'display:inline',
'id' => 'delete-position-' . \Illuminate\Support\Str::slug($position)])
!!}
{!! Form::close() !!}
</td>
@endcan

</div>
</div>

<div class="flex gap-4 flex-wrap">
@foreach ($items as $item)
@include('entities.pages.inventory._item')
Expand Down
3 changes: 3 additions & 0 deletions routes/campaigns/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
->name('entities.inventory.copy');
Route::get('/w/{campaign}/entities/{entity}/inventory/{inventory}/details', 'Entity\Inventory\DetailController@index')
->name('entities.inventory.details');
Route::delete('/w/{campaign}/entities/{entity}/inventory/delete_section', 'Entity\InventoryController@deleteSection')
->name('entities.inventory.delete.section');


// Export
Route::get('/w/{campaign}/entities/{entity}/html-export', 'Entity\ExportController@html')->name('entities.html-export');
Expand Down
Loading