vue-laravel-crud 1.7.3 → 1.7.4
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/dist/vue-laravel-crud.esm.js +44 -21
- package/dist/vue-laravel-crud.min.js +1 -1
- package/dist/vue-laravel-crud.ssr.js +273 -228
- package/package.json +1 -1
- package/src/vue-laravel-crud.vue +48 -19
package/package.json
CHANGED
package/src/vue-laravel-crud.vue
CHANGED
|
@@ -748,6 +748,26 @@ export default /*#__PURE__*/ {
|
|
|
748
748
|
this.$emit("select", this.item);
|
|
749
749
|
this.$emit("selectItems", this.selectedItems);
|
|
750
750
|
},
|
|
751
|
+
|
|
752
|
+
updateData(data, allowCreate = true) {
|
|
753
|
+
// Convertir this.items a un mapa para acceso rápido por id
|
|
754
|
+
const itemsMap = new Map(this.items.map(item => [item.id, item]));
|
|
755
|
+
|
|
756
|
+
// Recorrer cada elemento de data
|
|
757
|
+
data.forEach(newItem => {
|
|
758
|
+
if (itemsMap.has(newItem.id)) {
|
|
759
|
+
// Actualizar el item existente
|
|
760
|
+
const existingItem = itemsMap.get(newItem.id);
|
|
761
|
+
Object.assign(existingItem, newItem);
|
|
762
|
+
} else if (allowCreate) {
|
|
763
|
+
// Agregar el nuevo item si allowCreate es true
|
|
764
|
+
this.items.push(newItem);
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
// Convertir el mapa de vuelta a un array, si es necesario
|
|
769
|
+
this.items = Array.from(itemsMap.values());
|
|
770
|
+
},
|
|
751
771
|
showItem(id, itemIndex = null) {
|
|
752
772
|
if (itemIndex == null) {
|
|
753
773
|
let item = this.items.find((it) => it.id == id);
|
|
@@ -1007,21 +1027,30 @@ export default /*#__PURE__*/ {
|
|
|
1007
1027
|
this.loading = false;
|
|
1008
1028
|
},
|
|
1009
1029
|
async deleteItemBulkVuex() {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
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
|
-
|
|
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,
|
|
1270
|
+
result = await this.model.$update(this.item.id, this.item);
|
|
1245
1271
|
create = false;
|
|
1246
1272
|
} else {
|
|
1247
|
-
result = await this.model.$create(
|
|
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;
|