json-rules-filter 1.0.25 → 1.0.26

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.25",
3
+ "version": "1.0.26",
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": {
@@ -42,6 +42,7 @@
42
42
  title: { text: "Reglas de filtrado", className: "fs-6 fw-semibold" },
43
43
  buttons: {
44
44
  reset: { text: "Resetear", className: "fw-semibold link-danger link-offset-2 link-underline link-underline-opacity-0" },
45
+ save: { text: "Guardar", className: "fw-semibold link-primary link-offset-2 link-underline link-underline-opacity-0" },
45
46
  dropdown: { text: "Añadir regla", className: "btn btn-secondary" },
46
47
  apply: { text: "Aplicar regla", className: "btn btn-primary" },
47
48
  },
@@ -134,11 +135,26 @@
134
135
  return rulesAplicated;
135
136
  },
136
137
 
138
+ takeSnapshoot: function(){
139
+ const rules = this.getAplicatedRules();
140
+ localStorage.setItem("jsonRulesFilterData", JSON.stringify(rules));
141
+ console.log("Take snapshoot successfuly");
142
+ },
143
+
144
+ getSnapshoot: function(){
145
+ const rules = localStorage.getItem("jsonRulesFilterData");
146
+
147
+ if(rules != null){
148
+ this.preloadRules(JSON.parse(rules));
149
+ }
150
+ },
151
+
137
152
  // Initialize UI components
138
153
  init: function () {
139
154
  this.$contenedor.empty();
140
155
  this.render();
141
156
  this.bindEvents();
157
+ this.getSnapshoot();
142
158
  },
143
159
 
144
160
  // Render main plugin skeleton
@@ -167,7 +183,10 @@
167
183
  let template = `
168
184
  <div class="d-flex justify-content-between">
169
185
  <p class="${this.bs(this.settings.title.className)}">${this.settings.title.text}</p>
170
- <p><a class="${this.bs(this.settings.buttons.reset.className)} remove-rules-containers" href="#">${this.settings.buttons.reset.text}</a></p>
186
+ <div class="d-flex justify-content-between">
187
+ <p class="mr-2"><a class="${this.bs(this.settings.buttons.save.className)} save-rules-snapshot" href="#">${this.settings.buttons.save.text}</a></p>
188
+ <p><a class="${this.bs(this.settings.buttons.reset.className)} remove-rules-containers" href="#">${this.settings.buttons.reset.text}</a></p>
189
+ </div>
171
190
  </div>
172
191
  <div class="py-2 container-rules-filters"></div>
173
192
  <div class="mt-2">
@@ -183,6 +202,7 @@
183
202
  <button type="button" id="apply-rules-btn" class="${this.bs(this.settings.buttons.apply.className)}">${this.settings.buttons.apply.text}</button>
184
203
  </div>
185
204
  </div>`;
205
+
186
206
  this.$contenedor.append(template);
187
207
  if (this.settings.scrollY !== false) {
188
208
  const maxHeight = typeof this.settings.scrollY === 'number' ?
@@ -244,6 +264,12 @@
244
264
  self.reset();
245
265
  });
246
266
 
267
+ // Save all rules
268
+ this.$contenedor.find(".save-rules-snapshot").on("click", function (e) {
269
+ e.preventDefault();
270
+ self.takeSnapshoot();
271
+ });
272
+
247
273
  // Apply current filters to data
248
274
  this.$contenedor.find("#apply-rules-btn").on("click", function (e) {
249
275
  e.preventDefault();
@@ -337,7 +363,7 @@
337
363
 
338
364
  // 1. Extraemos los valores únicos de la base de datos actual
339
365
  let uniqueOptions = [...new Set(this.data.map(function (item) {
340
- const val = getValueByPath(item, dataField).toString();
366
+ const val = getValueByPath(item, dataField)?.toString();
341
367
  if (val !== undefined && val !== null) {
342
368
  return JSON.stringify({ id: val, text: val });
343
369
  }