Skip to content

Commit

Permalink
Merge pull request #883 from owlchester/delete-section-inventory
Browse files Browse the repository at this point in the history
Inventories delete section
  • Loading branch information
ilestis authored May 24, 2024
2 parents 34e7d41 + 4c09ddf commit f459ab7
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
2 changes: 0 additions & 2 deletions app/Http/Controllers/Entity/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public function store(StoreInventory $request, Campaign $campaign, Entity $entit
]);
}



return redirect()
->route('entities.inventory', [$campaign, $entity])
->with('success_raw', $success);
Expand Down
33 changes: 33 additions & 0 deletions app/Http/Controllers/Entity/InventorySectionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Controllers\Entity;

use App\Http\Controllers\Controller;
use App\Models\Campaign;
use App\Models\Entity;
use App\Models\Inventory;
use App\Traits\GuestAuthTrait;

class InventorySectionController extends Controller
{
use GuestAuthTrait;

/**
*/
public function delete(Campaign $campaign, Entity $entity, Inventory $inventory)
{
$this->authorize('update', $entity->child);
if ($inventory->position) {
Inventory::where('entity_id', $entity->id)->where('position', $inventory->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' => $inventory->position,
'entity' => $entity->name
]));
}
}
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, $items['0']],
'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/{inventory}/delete_section', 'Entity\InventorySectionController@delete')
->name('entities.inventory.delete.section');


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

0 comments on commit f459ab7

Please sign in to comment.