feat(DiscountProductDto): add picture property and update fromModel method
feat(ProductDragAndDropComponent): enhance product display with picture and improve layout
This commit is contained in:
parent
f9ded6d01c
commit
44ffc4d34e
3 changed files with 66 additions and 60 deletions
|
|
@ -15,6 +15,7 @@ final readonly class DiscountProductDto implements \JsonSerializable, Arrayable
|
|||
public function __construct(
|
||||
public string $id,
|
||||
public string $name,
|
||||
public ?string $picture,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ final readonly class DiscountProductDto implements \JsonSerializable, Arrayable
|
|||
return new self(
|
||||
id: (string) $product->id,
|
||||
name: (string) $product->name,
|
||||
picture: $product->picture,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -33,8 +35,9 @@ final readonly class DiscountProductDto implements \JsonSerializable, Arrayable
|
|||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'picture' => $this->picture,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ final readonly class GetDiscountFormDataQuery implements Query
|
|||
|
||||
if ($input->discount !== null) {
|
||||
$selectedProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->select(['id', 'name', 'picture'])
|
||||
->where('discount_id', $input->discount->id)
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn (Product $p): DiscountProductDto => DiscountProductDto::fromModel($p));
|
||||
|
||||
$existingProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->select(['id', 'name', 'picture'])
|
||||
->whereNotIn('id', $selectedProds->pluck('id'))
|
||||
->orderBy('name')
|
||||
->get()
|
||||
|
|
@ -46,7 +46,7 @@ final readonly class GetDiscountFormDataQuery implements Query
|
|||
} else {
|
||||
$selectedProds = collect();
|
||||
$existingProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->select(['id', 'name', 'picture'])
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn (Product $p): DiscountProductDto => DiscountProductDto::fromModel($p));
|
||||
|
|
|
|||
|
|
@ -1,58 +1,61 @@
|
|||
<template>
|
||||
<div class="product-drag-drop">
|
||||
<div class="mb-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h5 class="mb-0">
|
||||
<fieldset class="border border-secondary-subtle rounded p-2">
|
||||
<legend class="mb-3 h5">
|
||||
{{ __('Available products') }}
|
||||
</h5>
|
||||
<div
|
||||
class="input-group input-group-sm w-auto"
|
||||
style="max-width: 250px;"
|
||||
>
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
class="form-control"
|
||||
:placeholder="__('Search...')"
|
||||
</legend>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div
|
||||
class="input-group input-group-sm w-auto"
|
||||
style="max-width: 250px;"
|
||||
>
|
||||
<button
|
||||
v-if="searchQuery"
|
||||
class="btn btn-outline-secondary"
|
||||
type="button"
|
||||
:title="__('Clear')"
|
||||
@click="searchQuery = ''"
|
||||
>
|
||||
<i class="fa-solid fa-xmark" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<draggable
|
||||
v-model="filteredAvailable"
|
||||
group="products"
|
||||
item-key="id"
|
||||
class="drag-container"
|
||||
ghost-class="ghost-card"
|
||||
animation="200"
|
||||
>
|
||||
<template #item="{ element }">
|
||||
<div class="card product-card">
|
||||
<img
|
||||
v-if="element.picture"
|
||||
:src="`/${element.picture}`"
|
||||
:alt="element.name"
|
||||
class="card-img-top product-img"
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
class="form-control"
|
||||
:placeholder="__('Search...')"
|
||||
:aria-label="__('Search...')"
|
||||
>
|
||||
<div class="card-body p-2 text-center">
|
||||
<p
|
||||
class="card-title m-0 product-name"
|
||||
:title="element.name"
|
||||
>
|
||||
{{ element.name }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
v-if="searchQuery"
|
||||
class="btn btn-outline-secondary"
|
||||
type="button"
|
||||
:title="__('Clear')"
|
||||
@click="searchQuery = ''"
|
||||
>
|
||||
<i class="fa-solid fa-xmark" />
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</div>
|
||||
<draggable
|
||||
v-model="filteredAvailable"
|
||||
group="products"
|
||||
item-key="id"
|
||||
class="drag-container"
|
||||
ghost-class="ghost-card"
|
||||
animation="200"
|
||||
>
|
||||
<template #item="{ element }">
|
||||
<div class="card product-card">
|
||||
<img
|
||||
v-if="element.picture"
|
||||
:src="`/${element.picture}`"
|
||||
:alt="element.name"
|
||||
class="card-img-top product-img"
|
||||
>
|
||||
<div class="card-body p-2 text-center">
|
||||
<p
|
||||
class="card-title m-0 product-name"
|
||||
:title="element.name"
|
||||
>
|
||||
{{ element.name }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</fieldset>
|
||||
|
||||
<p
|
||||
v-if="filteredAvailable.length === 0"
|
||||
|
|
@ -63,10 +66,10 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h5 class="mb-3">
|
||||
<fieldset class="border border-primary-subtle rounded p-2">
|
||||
<legend class="mb-3 h5">
|
||||
{{ __('Selected products') }}
|
||||
</h5>
|
||||
</legend>
|
||||
<draggable
|
||||
v-model="selected"
|
||||
group="products"
|
||||
|
|
@ -95,13 +98,13 @@
|
|||
</template>
|
||||
</draggable>
|
||||
|
||||
<p
|
||||
<small
|
||||
v-if="selected.length === 0"
|
||||
class="text-muted small mt-2"
|
||||
class="text-muted small fst-italic text-center d-block"
|
||||
>
|
||||
{{ __('Drag products here to select them.') }}
|
||||
</p>
|
||||
</div>
|
||||
</small>
|
||||
</fieldset>
|
||||
|
||||
<input
|
||||
v-for="(sel, selIdx) of selected"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue