vue-laravel-crud 1.4.13 → 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));
@@ -304,7 +306,6 @@ export default /*#__PURE__*/ {
304
306
  }
305
307
  };
306
308
  },
307
-
308
309
  itemsList() {
309
310
  if (this.ajax) {
310
311
  return this.items;
@@ -312,35 +313,25 @@ export default /*#__PURE__*/ {
312
313
  return this.items.slice(this.paginationIndexStart, this.paginationIndexEnd);
313
314
  }
314
315
  },
315
-
316
316
  paginationIndexStart() {
317
317
  return (this.pagination.current_page - 1) * this.pagination.per_page;
318
318
  },
319
319
  paginationIndexEnd() {
320
320
  return this.paginationIndexStart + this.pagination.per_page;
321
321
  },
322
-
323
-
324
- /* filteredItems() {
325
- return this.items;
326
- },*/
327
-
328
322
  finalFilters() {
329
-
330
323
  return [
331
324
  ...this.filters,
332
325
  ...this.filter,
333
326
  ...this.internalFilter
334
327
  ];
335
328
  },
336
-
337
329
  internalFilter() {
338
330
  let filter = [];
339
331
  this.forceRecomputeCounter;
340
332
  this.internalFilters.forEach((f) => {
341
333
  if (f.value) filter.push([f.column, f.op, f.value]);
342
334
  });
343
-
344
335
  return filter;
345
336
  },
346
337
  internalFilterByProp() {
@@ -373,7 +364,6 @@ export default /*#__PURE__*/ {
373
364
  });
374
365
  }
375
366
  }
376
-
377
367
  if (this.sortable) {
378
368
  this.internalFilters.push({
379
369
  column: column.prop + "_sort",
@@ -386,7 +376,6 @@ export default /*#__PURE__*/ {
386
376
 
387
377
  toggleSortFilter(column) {
388
378
  let value = this.internalFilterByProp(column.prop + "_sort").value;
389
-
390
379
  if (!value) {
391
380
  this.internalFilterByProp(column.prop + "_sort").value = "ASC";
392
381
  } else if (value == "ASC") {
@@ -538,7 +527,6 @@ export default /*#__PURE__*/ {
538
527
  async fetchItemsVuex(page = 1) {
539
528
  this.loading = true;
540
529
  this.$emit("beforeFetch", {});
541
-
542
530
  const result = await this.model.api().get('', {
543
531
  params: {
544
532
  page: page,
@@ -546,11 +534,8 @@ export default /*#__PURE__*/ {
546
534
  filters: JSON.stringify(this.finalFilters),
547
535
  }
548
536
  });
549
-
550
- this.collection = result.entities[this.model.entity];
551
-
552
-
553
- console.debug("fetch page vuex ", page, this.collection);
537
+ this.items = result.entities[this.model.entity];
538
+ console.debug("fetch page vuex ", page, this.items);
554
539
  this.loading = false;
555
540
  },
556
541
  fetchItems(page = 1) {
@@ -615,7 +600,7 @@ export default /*#__PURE__*/ {
615
600
  });
616
601
  },
617
602
 
618
- removeItem: function (id, index) {
603
+ removeItem(id, index) {
619
604
  this.$bvModal
620
605
  .msgBoxConfirm(this.messageRemoveConfirm, {
621
606
  size: "sm",
@@ -627,18 +612,7 @@ export default /*#__PURE__*/ {
627
612
  })
628
613
  .then((value) => {
629
614
  if (value) {
630
- this.loading = true;
631
- axios
632
- .delete(this.apiUrl + "/" + this.modelName + "/" + id)
633
- .then((response) => {
634
- this.items.splice(index, 1);
635
- this.toastSuccess("Elemento eliminado.");
636
- this.loading = false;
637
- })
638
- .catch((error) => {
639
- this.toastError(error);
640
- this.loading = false;
641
- });
615
+ this.deleteItem(id, index);
642
616
  }
643
617
  })
644
618
  .catch((error) => {
@@ -647,6 +621,40 @@ export default /*#__PURE__*/ {
647
621
  });
648
622
  },
649
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
+ },
650
658
  saveSort() {
651
659
  if (this.orderable) {
652
660
  this.loading = true;
@@ -654,7 +662,6 @@ export default /*#__PURE__*/ {
654
662
  this.items.forEach((v, k) => {
655
663
  order.push({ id: v.id, order: v[this.orderProp] });
656
664
  });
657
-
658
665
  axios
659
666
  .post(this.apiUrl + "/" + this.modelName + "/sort", {
660
667
  order: order,
@@ -694,7 +701,6 @@ export default /*#__PURE__*/ {
694
701
  );
695
702
  return value;
696
703
  }
697
-
698
704
  let ops = options.filter((option) => {
699
705
  if (Array.isArray(value)) {
700
706
  return value.includes(option.id);
@@ -702,20 +708,43 @@ export default /*#__PURE__*/ {
702
708
  return option.id == value;
703
709
  }
704
710
  });
705
-
706
711
  ops = ops.map((option) => {
707
712
  return option.text ? option.text : option.label ? option.label : "";
708
713
  });
709
-
710
714
  return ops.join(", ");
711
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
+
712
743
  async saveItem(event = null) {
713
744
  this.loading = true;
714
-
715
745
  if (this.validate) {
716
746
  let validation_result = true;
717
747
  let validation_error_message = this.messageDefaultValidationError;
718
-
719
748
  if (!validation_result) {
720
749
  this.toastError(validation_error_message);
721
750
  return;
@@ -724,6 +753,10 @@ export default /*#__PURE__*/ {
724
753
  if (event) event.preventDefault();
725
754
  }
726
755
 
756
+ if (this.useVuexORM) {
757
+ return this.saveItemVuex();
758
+ }
759
+
727
760
  if (this.item.id) {
728
761
  axios
729
762
  .put(
@@ -734,7 +767,6 @@ export default /*#__PURE__*/ {
734
767
  if (this.hideModalAfterSave) {
735
768
  this.$bvModal.hide("modal-form-item-" + this.modelName);
736
769
  }
737
-
738
770
  let itemSv = response.data;
739
771
  let itemIndex = this.items.findIndex(
740
772
  (item) => item.id == this.item.id
@@ -752,7 +784,6 @@ export default /*#__PURE__*/ {
752
784
  } else {
753
785
  if (this.createMultipart) {
754
786
  const formData = new FormData();
755
-
756
787
  Object.keys(this.item).forEach((key) => {
757
788
  if (this.item[key][0] && this.item[key][0].name) {
758
789
  let files = this.item[key];
@@ -779,9 +810,7 @@ export default /*#__PURE__*/ {
779
810
  }
780
811
  return;
781
812
  }
782
-
783
813
  let itemSv = response.data;
784
-
785
814
  this.items.push(itemSv);
786
815
  this.item = itemSv;
787
816
  if (this.refreshAfterSave) this.refresh();
@@ -807,7 +836,6 @@ export default /*#__PURE__*/ {
807
836
  }
808
837
 
809
838
  let itemSv = response.data;
810
-
811
839
  this.items.push(itemSv);
812
840
  this.item = itemSv;
813
841
  if (this.refreshAfterSave) this.refresh();
@@ -1094,24 +1122,21 @@ export default /*#__PURE__*/ {
1094
1122
 
1095
1123
  <span v-else>{{ column.label }}</span>
1096
1124
 
1097
- <span v-if="
1098
- sortable && internalFilterByProp(column.prop + '_sort')
1099
- " 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
1100
1127
  v-if="!internalFilterByProp(column.prop + '_sort').value"></b-icon-sort><b-icon-sort-up v-if="
1101
- internalFilterByProp(column.prop + '_sort').value ==
1102
- 'ASC'
1103
- "></b-icon-sort-up><b-icon-sort-down v-if="
1104
- internalFilterByProp(column.prop + '_sort').value ==
1105
- 'DESC'
1106
- "></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>
1107
1132
  </th>
1108
1133
  </slot>
1109
1134
  </tr>
1110
1135
  </thead>
1111
1136
 
1112
- <draggable v-model="items" group="people" tag="tbody" :draggable="orderable ? '.item' : '.none'"
1137
+ <draggable v-model="itemsList" group="people" tag="tbody" :draggable="orderable ? '.item' : '.none'"
1113
1138
  @start="drag = true" @end="drag = false" @sort="onSort()">
1114
- <tr v-for="(item, index) in items" v-bind:key="index" @mouseover="onRowHover(item, index)"
1139
+ <tr v-for="(item, index) in itemsList" v-bind:key="index" @mouseover="onRowHover(item, index)"
1115
1140
  @click="onRowClick(item, index)" class="item">
1116
1141
  <template v-if="item.group">
1117
1142
  <th :colspan="columns.length">
@@ -1148,13 +1173,11 @@ export default /*#__PURE__*/ {
1148
1173
  <b-form-checkbox v-model="item.selected" @change="onCheckSelect($event, item)">
1149
1174
  </b-form-checkbox>
1150
1175
  </span>
1151
-
1152
1176
  <span v-else-if="column.type == 'state'">
1153
1177
  {{
1154
1178
  getStateValue(itemValue(column, item), column.options)
1155
1179
  }}
1156
1180
  </span>
1157
-
1158
1181
  <span v-else-if="column.type == 'array'">
1159
1182
  {{
1160
1183
  getArrayValue(
@@ -1163,7 +1186,6 @@ export default /*#__PURE__*/ {
1163
1186
  )
1164
1187
  }}
1165
1188
  </span>
1166
-
1167
1189
  <span v-else>
1168
1190
  {{ itemValue(column, item) }}
1169
1191
  </span>
@@ -1189,19 +1211,19 @@ export default /*#__PURE__*/ {
1189
1211
  </tr>
1190
1212
  </draggable>
1191
1213
  </table>
1192
- <p v-if="items.length == 0" class="p-3">
1214
+ <p v-if="itemsList.length == 0" class="p-3">
1193
1215
  {{ messageEmptyResults }}
1194
1216
  </p>
1195
1217
  </div>
1196
1218
 
1197
1219
  <div v-if="displayMode == displayModes.MODE_CARDS">
1198
- <p v-if="items.length == 0" class="p-3">
1220
+ <p v-if="itemsList.length == 0" class="p-3">
1199
1221
  {{ messageEmptyResults }}
1200
1222
  </p>
1201
1223
 
1202
- <draggable v-model="items" group="people" class="row" :draggable="orderable ? '.item' : '.none'"
1224
+ <draggable v-model="itemsList" group="people" class="row" :draggable="orderable ? '.item' : '.none'"
1203
1225
  @start="drag = true" @end="drag = false" @sort="onSort()">
1204
- <b-col v-for="(item, index) in items" v-bind:key="index" :cols="colXs" :sm="colSm" :md="colMd" :lg="colLg"
1226
+ <b-col v-for="(item, index) in itemsList" v-bind:key="index" :cols="colXs" :sm="colSm" :md="colMd" :lg="colLg"
1205
1227
  :xl="colXl" class="item">
1206
1228
  <b-card :title="item.title" tag="article" class="mb-2 card-crud" :class="cardClass"
1207
1229
  :hideFooter="cardHideFooter">
@@ -1222,7 +1244,6 @@ export default /*#__PURE__*/ {
1222
1244
  itemValue(column, item) == 'false'
1223
1245
  "><b-icon-x-circle></b-icon-x-circle></b-badge>
1224
1246
  </span>
1225
-
1226
1247
  <span v-else-if="column.type == 'date'">
1227
1248
  {{ itemValue(column, item) }}
1228
1249
  </span>
@@ -1270,11 +1291,10 @@ export default /*#__PURE__*/ {
1270
1291
 
1271
1292
  <div v-if="displayMode == displayModes.MODE_CUSTOM">
1272
1293
  <div :class="listContainerClass">
1273
- <p v-if="items.length == 0" class="p-3">
1294
+ <p v-if="itemsList.length == 0" class="p-3">
1274
1295
  {{ messageEmptyResults }}
1275
1296
  </p>
1276
-
1277
- <div :class="listItemClass" v-for="(item, index) in items" v-bind:key="index">
1297
+ <div :class="listItemClass" v-for="(item, index) in itemsList" v-bind:key="index">
1278
1298
  <slot name="card" v-bind:item="item"> </slot>
1279
1299
  </div>
1280
1300
  </div>