vue-laravel-crud 1.7.3 → 1.7.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-laravel-crud",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/clonixdev/vue-laravel-crud",
6
6
  "main": "dist/vue-laravel-crud.ssr.js",
@@ -438,21 +438,7 @@ export default /*#__PURE__*/ {
438
438
  console.debug("crud mounted columns", this.columns);
439
439
  this.internalFilters = [];
440
440
  this.setupFilters();
441
-
442
- if (this.ajax) {
443
- this.fetchItems();
444
- } else {
445
-
446
- if (this.grouped) {
447
- this.groupItems(this.models);
448
- } else {
449
- this.items = this.models;
450
- }
451
-
452
- this.pagination.total = this.items.length;
453
- this.firstLoad = true;
454
- }
455
-
441
+ this.fetchItems();
456
442
  this.loadOptions();
457
443
  },
458
444
  computed: {
@@ -748,6 +734,26 @@ export default /*#__PURE__*/ {
748
734
  this.$emit("select", this.item);
749
735
  this.$emit("selectItems", this.selectedItems);
750
736
  },
737
+
738
+ updateData(data, allowCreate = true) {
739
+ // Convertir this.items a un mapa para acceso rápido por id
740
+ const itemsMap = new Map(this.items.map(item => [item.id, item]));
741
+
742
+ // Recorrer cada elemento de data
743
+ data.forEach(newItem => {
744
+ if (itemsMap.has(newItem.id)) {
745
+ // Actualizar el item existente
746
+ const existingItem = itemsMap.get(newItem.id);
747
+ Object.assign(existingItem, newItem);
748
+ } else if (allowCreate) {
749
+ // Agregar el nuevo item si allowCreate es true
750
+ this.items.push(newItem);
751
+ }
752
+ });
753
+
754
+ // Convertir el mapa de vuelta a un array, si es necesario
755
+ this.items = Array.from(itemsMap.values());
756
+ },
751
757
  showItem(id, itemIndex = null) {
752
758
  if (itemIndex == null) {
753
759
  let item = this.items.find((it) => it.id == id);
@@ -787,9 +793,7 @@ export default /*#__PURE__*/ {
787
793
 
788
794
  refresh() {
789
795
  this.$emit("refresh", {});
790
- if (!this.ajax) {
791
- return;
792
- }
796
+
793
797
  if (this.infiniteScroll) {
794
798
  this.pagination.current_page = 1;
795
799
  this.infiniteScrollKey++;
@@ -855,14 +859,30 @@ export default /*#__PURE__*/ {
855
859
  this.loading = false;
856
860
  this.firstLoad = true;
857
861
  },
858
- fetchItems(page = 1, concat = false) {
859
- if (!this.ajax) {
860
- return;
862
+ fetchItemsLocal(){
863
+ if (this.grouped) {
864
+ this.groupItems(this.models);
865
+ } else {
866
+ this.items = this.models;
861
867
  }
868
+
869
+ this.pagination.total = this.items.length;
870
+ this.firstLoad = true;
871
+
872
+ },
873
+ fetchItems(page = 1, concat = false) {
874
+
875
+
862
876
  this.$emit("beforeFetch", {});
863
877
  if (this.useVuexORM) {
864
878
  return this.fetchItemsVuex(page, concat);
865
879
  }
880
+
881
+
882
+ if (!this.ajax) {
883
+ return this.fetchItemsLocal(page,concat);
884
+ }
885
+
866
886
  this.loading = true;
867
887
  return axios
868
888
  .get(this.apiUrl + "/" + this.modelName, {
@@ -1007,21 +1027,30 @@ export default /*#__PURE__*/ {
1007
1027
  this.loading = false;
1008
1028
  },
1009
1029
  async deleteItemBulkVuex() {
1010
- /*
1011
- let result = await this.model.api().delete('/' + id, {
1012
- delete: 1
1013
- });
1014
-
1015
- console.debug("delete item vuex", result);
1016
- let responseStatus = result.response.status;
1017
-
1018
- if (result.response.data.error) {
1019
- this.toastError(result.response.data.error);
1020
- this.loading = false;
1021
- return;
1022
- }
1030
+
1031
+ let ids = this.selectedItems.map(it => it.id);
1032
+
1033
+
1034
+ if (this.vuexLocalforage) {
1035
+ await this.model.$delete(ids);
1036
+
1037
+ } else {
1038
+ let result = await this.model.api().delete('/bulk-destroy' , {
1039
+ params: { ids: ids},
1040
+ delete: ids
1041
+ });
1042
+
1043
+ console.debug("delete item vuex", result);
1044
+ let responseStatus = result.response.status;
1045
+
1046
+ if (result.response.data.error) {
1047
+ this.toastError(result.response.data.error);
1048
+ this.loading = false;
1049
+ return;
1050
+ }
1051
+ }
1023
1052
 
1024
- this.toastSuccess("Elemento eliminado.");*/
1053
+ this.toastSuccess("Elemento eliminados.");
1025
1054
  },
1026
1055
  deleteItem(id, index) {
1027
1056
 
@@ -1231,24 +1260,24 @@ export default /*#__PURE__*/ {
1231
1260
  },
1232
1261
  async saveItemVuex(event = null) {
1233
1262
  console.debug("save item 1", this.item);
1234
- let jsondata = this.item.$toJson();
1235
- console.debug("save item 2", this.item, jsondata);
1236
1263
  let result;
1237
-
1238
1264
  let create = false;
1239
1265
 
1240
1266
 
1241
1267
  if (this.vuexLocalforage) {
1242
1268
 
1243
1269
  if (this.item.id) {
1244
- result = await this.model.$update(this.item.id, jsondata);
1270
+ result = await this.model.$update(this.item.id, this.item);
1245
1271
  create = false;
1246
1272
  } else {
1247
- result = await this.model.$create(jsondata);
1273
+ result = await this.model.$create(this.item);
1248
1274
  create = true;
1249
1275
  }
1250
1276
 
1251
1277
  } else {
1278
+
1279
+ let jsondata = this.item.$toJson();
1280
+ console.debug("save item 2", this.item, jsondata);
1252
1281
  if (this.item.id) {
1253
1282
  result = await this.model.api().put('/' + this.item.id, jsondata);
1254
1283
  create = false;