json-rules-filter 1.0.26 → 1.0.27

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": "json-rules-filter",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "para crear reglas avanzadas de filtrado sobre datasets JSON de forma dinámica y visual.",
5
5
  "main": "src/jquery.jsonRulesFilter.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -88,6 +88,10 @@ $("#miFiltro").jsonRulesFilter(data,
88
88
  onApply: function (rules, filteredData) {
89
89
  console.log("Reglas:", rules);
90
90
  console.log("Resultados:", filteredData);
91
+ },
92
+ onTakeSnapshot: function (reglas) {
93
+ console.log("Reglas:", rules);
94
+ console.log("Configuración de filtrado aplicada")
91
95
  }
92
96
  });
93
97
  ```
@@ -198,6 +202,16 @@ onApply: function (rules, filteredData) {
198
202
  }
199
203
  ```
200
204
 
205
+ ---
206
+ ### onTakeSnapshot
207
+
208
+ Callback ejecutado al guardar filtros.
209
+
210
+ ```javascript
211
+ onTakeSnapshot: function (rules) {
212
+ }
213
+ ```
214
+
201
215
  ---
202
216
 
203
217
  ## 🧩 Tipos de filtros
@@ -277,6 +291,9 @@ $("#container-rules").jsonRulesFilter(empleados, {
277
291
  });
278
292
 
279
293
  $("#num-filters").html(reglas.length);
294
+ },
295
+ onTakeSnapshot: function (reglas) {
296
+ alert("Configuración de filtrado aplicada");
280
297
  }
281
298
  });
282
299
  ```
@@ -310,11 +327,11 @@ $("#container-rules").jsonRulesFilter(empleados, {
310
327
  - Usa lógica AND entre reglas
311
328
  - Basado en Select2
312
329
  - Permite múltiples instancias
330
+ - Guardado de filtros en localStorage
331
+ - Exportar/importar reglas
313
332
 
314
333
  ---
315
334
 
316
335
  ## 💡 Ideas futuras
317
336
 
318
337
  - Lógica OR
319
- - Guardado de filtros
320
- - Exportar/importar reglas
@@ -9,10 +9,12 @@
9
9
  }(function ($) {
10
10
  $.fn.jsonRulesFilter = function (data, options) {
11
11
 
12
+ const publicMethods = ['updateData', 'preloadRules', 'reset'];
13
+
12
14
  // --- COMMAND MANAGEMENT (Method calling via string) ---
13
15
  if (typeof data === 'string') {
14
16
  const instance = $(this).data('rulesControl');
15
- if (instance && typeof instance[data] === 'function') {
17
+ if (instance && typeof instance[data] === 'function' && publicMethods.includes(data)) {
16
18
  return instance[data].apply(instance, Array.prototype.slice.call(arguments, 1));
17
19
  }
18
20
  return this;
@@ -46,7 +48,8 @@
46
48
  dropdown: { text: "Añadir regla", className: "btn btn-secondary" },
47
49
  apply: { text: "Aplicar regla", className: "btn btn-primary" },
48
50
  },
49
- onApply: function (filtros, datosFiltrados) { }
51
+ onApply: function (filtros, datosFiltrados) { },
52
+ onTakeSnapshot: function (filtros) { }
50
53
  }, options);
51
54
 
52
55
  return this.each(function () {
@@ -135,13 +138,18 @@
135
138
  return rulesAplicated;
136
139
  },
137
140
 
138
- takeSnapshoot: function(){
141
+ takeSnapshot: function(){
142
+ const self = this;
139
143
  const rules = this.getAplicatedRules();
140
144
  localStorage.setItem("jsonRulesFilterData", JSON.stringify(rules));
141
- console.log("Take snapshoot successfuly");
145
+ // EXECUTE onTakeSnapshot CALLBACK
146
+ if (typeof self.settings.onTakeSnapshot === 'function') {
147
+ // Pass rules summary and filtered array to the main program
148
+ self.settings.onTakeSnapshot.call(self.$contenedor, rules);
149
+ }
142
150
  },
143
151
 
144
- getSnapshoot: function(){
152
+ getSnapshot: function(){
145
153
  const rules = localStorage.getItem("jsonRulesFilterData");
146
154
 
147
155
  if(rules != null){
@@ -154,7 +162,7 @@
154
162
  this.$contenedor.empty();
155
163
  this.render();
156
164
  this.bindEvents();
157
- this.getSnapshoot();
165
+ this.getSnapshot();
158
166
  },
159
167
 
160
168
  // Render main plugin skeleton
@@ -267,7 +275,7 @@
267
275
  // Save all rules
268
276
  this.$contenedor.find(".save-rules-snapshot").on("click", function (e) {
269
277
  e.preventDefault();
270
- self.takeSnapshoot();
278
+ self.takeSnapshot();
271
279
  });
272
280
 
273
281
  // Apply current filters to data