vue-laravel-crud 1.4.14 → 1.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -271,6 +271,8 @@ export default /*#__PURE__*/ {
271
271
 
272
272
  if (this.useVuexORM) {
273
273
  //this.useVuexORM = true;
274
+ this.item = new this.model();
275
+
274
276
  } else {
275
277
  this.item = this.model;
276
278
  this.itemDefault = JSON.parse(JSON.stringify(this.item));
@@ -305,44 +307,31 @@ export default /*#__PURE__*/ {
305
307
  };
306
308
  },
307
309
  itemsList() {
308
-
309
310
  if (this.ajax) {
310
311
  return this.items;
311
312
  } else {
312
313
  return this.items.slice(this.paginationIndexStart, this.paginationIndexEnd);
313
314
  }
314
315
  },
315
-
316
-
317
-
318
316
  paginationIndexStart() {
319
317
  return (this.pagination.current_page - 1) * this.pagination.per_page;
320
318
  },
321
319
  paginationIndexEnd() {
322
320
  return this.paginationIndexStart + this.pagination.per_page;
323
321
  },
324
-
325
-
326
- /* filteredItems() {
327
- return this.items;
328
- },*/
329
-
330
322
  finalFilters() {
331
-
332
323
  return [
333
324
  ...this.filters,
334
325
  ...this.filter,
335
326
  ...this.internalFilter
336
327
  ];
337
328
  },
338
-
339
329
  internalFilter() {
340
330
  let filter = [];
341
331
  this.forceRecomputeCounter;
342
332
  this.internalFilters.forEach((f) => {
343
333
  if (f.value) filter.push([f.column, f.op, f.value]);
344
334
  });
345
-
346
335
  return filter;
347
336
  },
348
337
  internalFilterByProp() {
@@ -375,7 +364,6 @@ export default /*#__PURE__*/ {
375
364
  });
376
365
  }
377
366
  }
378
-
379
367
  if (this.sortable) {
380
368
  this.internalFilters.push({
381
369
  column: column.prop + "_sort",
@@ -388,7 +376,6 @@ export default /*#__PURE__*/ {
388
376
 
389
377
  toggleSortFilter(column) {
390
378
  let value = this.internalFilterByProp(column.prop + "_sort").value;
391
-
392
379
  if (!value) {
393
380
  this.internalFilterByProp(column.prop + "_sort").value = "ASC";
394
381
  } else if (value == "ASC") {
@@ -540,7 +527,6 @@ export default /*#__PURE__*/ {
540
527
  async fetchItemsVuex(page = 1) {
541
528
  this.loading = true;
542
529
  this.$emit("beforeFetch", {});
543
-
544
530
  const result = await this.model.api().get('', {
545
531
  params: {
546
532
  page: page,
@@ -548,10 +534,7 @@ export default /*#__PURE__*/ {
548
534
  filters: JSON.stringify(this.finalFilters),
549
535
  }
550
536
  });
551
-
552
537
  this.items = result.entities[this.model.entity];
553
-
554
-
555
538
  console.debug("fetch page vuex ", page, this.items);
556
539
  this.loading = false;
557
540
  },
@@ -617,7 +600,7 @@ export default /*#__PURE__*/ {
617
600
  });
618
601
  },
619
602
 
620
- removeItem: function (id, index) {
603
+ removeItem(id, index) {
621
604
  this.$bvModal
622
605
  .msgBoxConfirm(this.messageRemoveConfirm, {
623
606
  size: "sm",
@@ -629,18 +612,7 @@ export default /*#__PURE__*/ {
629
612
  })
630
613
  .then((value) => {
631
614
  if (value) {
632
- this.loading = true;
633
- axios
634
- .delete(this.apiUrl + "/" + this.modelName + "/" + id)
635
- .then((response) => {
636
- this.items.splice(index, 1);
637
- this.toastSuccess("Elemento eliminado.");
638
- this.loading = false;
639
- })
640
- .catch((error) => {
641
- this.toastError(error);
642
- this.loading = false;
643
- });
615
+ this.deleteItem(id, index);
644
616
  }
645
617
  })
646
618
  .catch((error) => {
@@ -649,6 +621,40 @@ export default /*#__PURE__*/ {
649
621
  });
650
622
  },
651
623
 
624
+ deleteItem(id, index) {
625
+
626
+ if (this.useVuexORM) {
627
+ return this.deleteItemVuex(id, index);
628
+ }
629
+ this.loading = true;
630
+ axios
631
+ .delete(this.apiUrl + "/" + this.modelName + "/" + id)
632
+ .then((response) => {
633
+ this.items.splice(index, 1);
634
+ this.toastSuccess("Elemento eliminado.");
635
+ this.loading = false;
636
+ })
637
+ .catch((error) => {
638
+ this.toastError(error);
639
+ this.loading = false;
640
+ });
641
+ },
642
+ async deleteItemVuex(id, index) {
643
+
644
+ let result = await this.model.api().delete('/' + id, {
645
+ delete: 1
646
+ });
647
+
648
+ console.debug("delete item vuex",result);
649
+ let responseStatus = result.response.status;
650
+
651
+ if (result.response.data.error) {
652
+ this.toastError(result.response.data.error);
653
+ return;
654
+ }
655
+
656
+ this.toastSuccess("Elemento eliminado.");
657
+ },
652
658
  saveSort() {
653
659
  if (this.orderable) {
654
660
  this.loading = true;
@@ -656,7 +662,6 @@ export default /*#__PURE__*/ {
656
662
  this.items.forEach((v, k) => {
657
663
  order.push({ id: v.id, order: v[this.orderProp] });
658
664
  });
659
-
660
665
  axios
661
666
  .post(this.apiUrl + "/" + this.modelName + "/sort", {
662
667
  order: order,
@@ -696,7 +701,6 @@ export default /*#__PURE__*/ {
696
701
  );
697
702
  return value;
698
703
  }
699
-
700
704
  let ops = options.filter((option) => {
701
705
  if (Array.isArray(value)) {
702
706
  return value.includes(option.id);
@@ -704,20 +708,43 @@ export default /*#__PURE__*/ {
704
708
  return option.id == value;
705
709
  }
706
710
  });
707
-
708
711
  ops = ops.map((option) => {
709
712
  return option.text ? option.text : option.label ? option.label : "";
710
713
  });
711
-
712
714
  return ops.join(", ");
713
715
  },
716
+ async saveItemVuex(event = null) {
717
+ let jsondata = this.item.$toJson();
718
+
719
+
720
+ console.debug("save item ", this.item, jsondata);
721
+ let result;
722
+
723
+ if (this.item.id) {
724
+ result = await this.model.api().put('/' + this.item.id, jsondata);
725
+ } else {
726
+ result = await this.model.api().post('', jsondata);
727
+ }
728
+
729
+ let responseStatus = result.response.status;
730
+ if (result.response.data.error) {
731
+ this.toastError(result.response.data.error);
732
+ return;
733
+ //throw new Error('Something is wrong.')
734
+ }
735
+
736
+ result.save();
737
+
738
+ if (this.refreshAfterSave) this.refresh();
739
+ this.toastSuccess("Elemento Modificado");
740
+ },
741
+
742
+
714
743
  async saveItem(event = null) {
715
744
  this.loading = true;
716
-
717
745
  if (this.validate) {
718
746
  let validation_result = true;
719
747
  let validation_error_message = this.messageDefaultValidationError;
720
-
721
748
  if (!validation_result) {
722
749
  this.toastError(validation_error_message);
723
750
  return;
@@ -726,6 +753,10 @@ export default /*#__PURE__*/ {
726
753
  if (event) event.preventDefault();
727
754
  }
728
755
 
756
+ if (this.useVuexORM) {
757
+ return this.saveItemVuex();
758
+ }
759
+
729
760
  if (this.item.id) {
730
761
  axios
731
762
  .put(
@@ -736,7 +767,6 @@ export default /*#__PURE__*/ {
736
767
  if (this.hideModalAfterSave) {
737
768
  this.$bvModal.hide("modal-form-item-" + this.modelName);
738
769
  }
739
-
740
770
  let itemSv = response.data;
741
771
  let itemIndex = this.items.findIndex(
742
772
  (item) => item.id == this.item.id
@@ -754,7 +784,6 @@ export default /*#__PURE__*/ {
754
784
  } else {
755
785
  if (this.createMultipart) {
756
786
  const formData = new FormData();
757
-
758
787
  Object.keys(this.item).forEach((key) => {
759
788
  if (this.item[key][0] && this.item[key][0].name) {
760
789
  let files = this.item[key];
@@ -781,9 +810,7 @@ export default /*#__PURE__*/ {
781
810
  }
782
811
  return;
783
812
  }
784
-
785
813
  let itemSv = response.data;
786
-
787
814
  this.items.push(itemSv);
788
815
  this.item = itemSv;
789
816
  if (this.refreshAfterSave) this.refresh();
@@ -809,7 +836,6 @@ export default /*#__PURE__*/ {
809
836
  }
810
837
 
811
838
  let itemSv = response.data;
812
-
813
839
  this.items.push(itemSv);
814
840
  this.item = itemSv;
815
841
  if (this.refreshAfterSave) this.refresh();
@@ -1096,16 +1122,13 @@ export default /*#__PURE__*/ {
1096
1122
 
1097
1123
  <span v-else>{{ column.label }}</span>
1098
1124
 
1099
- <span v-if="
1100
- sortable && internalFilterByProp(column.prop + '_sort')
1101
- " class="sort-filter" @click="toggleSortFilter(column)"><b-icon-sort
1125
+ <span v-if="sortable && internalFilterByProp(column.prop + '_sort')" class="sort-filter"
1126
+ @click="toggleSortFilter(column)"><b-icon-sort
1102
1127
  v-if="!internalFilterByProp(column.prop + '_sort').value"></b-icon-sort><b-icon-sort-up v-if="
1103
- internalFilterByProp(column.prop + '_sort').value ==
1104
- 'ASC'
1105
- "></b-icon-sort-up><b-icon-sort-down v-if="
1106
- internalFilterByProp(column.prop + '_sort').value ==
1107
- 'DESC'
1108
- "></b-icon-sort-down></span>
1128
+ internalFilterByProp(column.prop + '_sort').value == 'ASC'"></b-icon-sort-up>
1129
+ <b-icon-sort-down
1130
+ v-if="internalFilterByProp(column.prop + '_sort').value == 'DESC'"></b-icon-sort-down>
1131
+ </span>
1109
1132
  </th>
1110
1133
  </slot>
1111
1134
  </tr>
@@ -1150,13 +1173,11 @@ export default /*#__PURE__*/ {
1150
1173
  <b-form-checkbox v-model="item.selected" @change="onCheckSelect($event, item)">
1151
1174
  </b-form-checkbox>
1152
1175
  </span>
1153
-
1154
1176
  <span v-else-if="column.type == 'state'">
1155
1177
  {{
1156
1178
  getStateValue(itemValue(column, item), column.options)
1157
1179
  }}
1158
1180
  </span>
1159
-
1160
1181
  <span v-else-if="column.type == 'array'">
1161
1182
  {{
1162
1183
  getArrayValue(
@@ -1165,7 +1186,6 @@ export default /*#__PURE__*/ {
1165
1186
  )
1166
1187
  }}
1167
1188
  </span>
1168
-
1169
1189
  <span v-else>
1170
1190
  {{ itemValue(column, item) }}
1171
1191
  </span>
@@ -1224,7 +1244,6 @@ export default /*#__PURE__*/ {
1224
1244
  itemValue(column, item) == 'false'
1225
1245
  "><b-icon-x-circle></b-icon-x-circle></b-badge>
1226
1246
  </span>
1227
-
1228
1247
  <span v-else-if="column.type == 'date'">
1229
1248
  {{ itemValue(column, item) }}
1230
1249
  </span>
@@ -1275,7 +1294,6 @@ export default /*#__PURE__*/ {
1275
1294
  <p v-if="itemsList.length == 0" class="p-3">
1276
1295
  {{ messageEmptyResults }}
1277
1296
  </p>
1278
-
1279
1297
  <div :class="listItemClass" v-for="(item, index) in itemsList" v-bind:key="index">
1280
1298
  <slot name="card" v-bind:item="item"> </slot>
1281
1299
  </div>