@esfaenza/forms-and-validations 12.2.11 → 12.2.12

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.
@@ -1871,32 +1871,35 @@
1871
1871
  if (this.Source.length == 0 && !this.FirstBind)
1872
1872
  this.BoundSource = [];
1873
1873
  this.FirstBind = false;
1874
+ // Cache locale per evitare di rifare dei regex.match ogni santa volta
1874
1875
  if (this.Source.length > 0) {
1875
1876
  this.BoundSource = [];
1876
- var conditions_1 = /:([a-z]+)\?\(([^\(\)]+)\)/g;
1877
- var conditionDetails_1 = /:([a-z]+)\?\(([^\(\)]+)\)/i;
1878
- var bindings_1 = /{[a-z]+}/gi;
1877
+ // Blocco per tirare fuori le condizioni scritte tipo --> :prop?(Roba con {prop})
1878
+ var iffedMatches = this.Display.match(/:([a-z]+)\?\(([^\(\)]+)\)/g);
1879
+ var bindCheckingGroups = [];
1880
+ if (iffedMatches) {
1881
+ iffedMatches.forEach(function (m) {
1882
+ // Stessa regex di sopra ma il tag "i" serve per tirare fuori i singoli capturing group e per qualche motivo
1883
+ // new RegExp(baseRegex, "g") non funziona quindi non ho potuto razionalizzarlo
1884
+ var groups = m.match(/:([a-z]+)\?\(([^\(\)]+)\)/i);
1885
+ bindCheckingGroups.push({ global: m, prop: groups[1], whenexists: groups[2] });
1886
+ });
1887
+ }
1888
+ // Blocco per tirare fuori le proprietà scritte tipo --> {prop}
1889
+ var bindProperties = [];
1890
+ var matches = this.Display.match(/{[a-z]+}/gi);
1891
+ if (matches)
1892
+ matches.forEach(function (m) { bindProperties.push({ global: m, prop: m.substring(1, m.length - 1) }); });
1893
+ // Blocco per generare la descrizione finale di un elemento
1879
1894
  this.Source.forEach(function (s) {
1880
- var tmpDescription = _this.Display;
1881
- var iffedMatches = tmpDescription.match(conditions_1);
1882
- // Considerando di avere qualcosa del tipo --> :sqi?({sqi})
1883
- if (iffedMatches) {
1884
- for (var i = 0; i < iffedMatches.length; i++) {
1885
- var m = iffedMatches[i];
1886
- var groups = m.match(conditionDetails_1);
1887
- // Se è presente la proprietà "sqi" nell'oggetto della source e non è falsy sostituisco con {sqi} per poterlo parsare al ciclo dopo
1888
- // altrimenti elimino il blocco completamente
1889
- tmpDescription = tmpDescription.replace(m[0], s[groups[1]] ? groups[2] : "");
1890
- }
1891
- }
1892
- var matches = tmpDescription.match(bindings_1);
1893
- if (matches) {
1894
- for (var i = 0; i < matches.length; i++) {
1895
- var m = matches[i];
1896
- tmpDescription = tmpDescription.replace(m, s[m.substring(1, m.length - 1)]);
1897
- }
1898
- }
1899
- _this.BoundSource.push({ id: s[_this.IdField], description: tmpDescription });
1895
+ // Parto sempre dalla variabile di Display, poi sostituisco pezzo per pezzo
1896
+ var desc = _this.Display;
1897
+ // Taglio o mantengo le condizioni in base alla proprietà su cui fare check
1898
+ // Dopodiché scrivo tutte le proprietà
1899
+ bindCheckingGroups.forEach(function (t) { desc = desc.replace(t.global, (s[t.prop] != null && s[t.prop] != undefined) ? t.whenexists : ""); });
1900
+ bindProperties.forEach(function (t) { desc = desc.replace(t.global, s[t.prop]); });
1901
+ // Aggiungo alla BoundSource in formato standard KeyValue
1902
+ _this.BoundSource.push({ id: s[_this.IdField], description: desc });
1900
1903
  });
1901
1904
  }
1902
1905
  };