Product DnD fix bug

This commit is contained in:
Olivier Legat 2021-04-21 11:26:49 +02:00
parent da1e9670bf
commit 9af3852583
4 changed files with 33 additions and 26 deletions

View file

@ -29,7 +29,13 @@ class PromotionsController extends Controller
public function create()
{
$discTypes = DiscountType::all();
return view('bo.promotions.create', compact('discTypes'));
$existingProds = Product::all();
$promotion = new Promotion();
$selectedProds = $promotion->products;
//$existingProds = $existingProds->diff($selectedProds);
return view('bo.promotions.create', compact('discTypes', 'existingProds', 'selectedProds'));
}
/**
@ -40,14 +46,17 @@ class PromotionsController extends Controller
*/
public function store(Request $request)
{
$request->validate([
'product_id' => 'required',
]);
$productIds = explode(",", $request->product_id);
$discType = $request->discount_type_id;
$value = $request->discount_value;
$date_start = $request->date_start_date . " " . $request->date_start_time;
$date_end = $request->date_end_date . " " . $request->date_end_time;
$request->validate([]);
$promotion = new Promotion();
$promotion->discount_type_id = $discType;
$promotion->discount_value = $value;
@ -101,14 +110,16 @@ class PromotionsController extends Controller
{
$promotion = Promotion::findOrFail($id);
$request->validate([
'product_id' => 'required',
]);
$productIds = explode(",", $request->product_id);
$discType = $request->discount_type_id;
$value = $request->discount_value;
$date_start = $request->date_start_date . " " . $request->date_start_time;
$date_end = $request->date_end_date . " " . $request->date_end_time;
$request->validate([]);
$promotion->discount_type_id = $discType;
$promotion->discount_value = $value;
$promotion->date_start = $date_start;

15
public/b-o/js/app.js vendored
View file

@ -12438,7 +12438,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
return {
selectedProds: [],
existingProds: [],
product_id: ''
product_id: '',
dropOptions: {
className: "ghost",
animationDuration: 300,
showOnTop: true
}
};
},
mounted: function mounted() {
@ -12453,7 +12458,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
methods: {
onDrop: function onDrop(collection, dropResult) {
this[collection] = this.applyDrag(this[collection], dropResult);
console.log(this[collection]);
this.product_id = this.selectedProds.map(function (_ref2) {
var id = _ref2.id;
return id;
@ -12465,13 +12469,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
getChildPayload2: function getChildPayload2(index) {
return this.selectedProds[index];
},
dropOptions: function dropOptions() {
return {
className: "ghost",
animationDuration: 300,
showOnTop: true
};
},
applyDrag: function applyDrag(arr, dragResult) {
var removedIndex = dragResult.removedIndex,
addedIndex = dragResult.addedIndex,

View file

@ -55,6 +55,11 @@ export default {
selectedProds: [],
existingProds: [],
product_id: '',
dropOptions: {
className: "ghost",
animationDuration: 300,
showOnTop: true,
},
}
},
mounted() {
@ -66,7 +71,6 @@ export default {
methods: {
onDrop (collection, dropResult) {
this[collection] = this.applyDrag(this[collection], dropResult);
console.log(this[collection]);
this.product_id = this.selectedProds.map(({ id }) => id );
},
@ -78,14 +82,6 @@ export default {
return this.selectedProds[index]
},
dropOptions() {
return {
className: "ghost",
animationDuration: 300,
showOnTop: true,
}
},
applyDrag(arr, dragResult) {
const { removedIndex, addedIndex, payload } = dragResult
if (removedIndex === null && addedIndex === null) return arr

View file

@ -19,11 +19,14 @@
</div>
@endif
{{-- //TODO implementer plus tard <products-cards-dnd></products-cards-dnd> --}}
<div class="form-group">
<label for="name">Produit *</label>
<input type="text" id="product_id" name="product_id" class="form-control" placeholder="Produit * " value="{{ old('product_id') }}" required>
<products-cards-dnd
dbexistingprods='@json($existingProds)'
dbselectedprods='@json($selectedProds)'
element-id="product_id"
></products-cards-dnd>
{{--<input type="text" id="product_id" name="product_id" class="form-control" placeholder="Produit * " value="{{ old('product_id') }}" required>--}}
</div>
<div class="form-row">
<div class="form-group col">