backend-plus 1.16.19 → 1.16.21

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.
@@ -846,11 +846,11 @@ myOwn.DataColumnGrid.prototype.cellAttributes = function cellAttributes(specific
846
846
  attr["my-mandatory"]="normal";
847
847
  }
848
848
  }
849
- if(grid.connector.fixedField[fieldDef.name]){
849
+ if(grid.connector.fixedField[fieldDef.name] != null){
850
850
  attr["inherited-pk-column"]="yes";
851
851
  }
852
852
  if(fieldDef.referencesField){
853
- if(grid.connector.fixedField[fieldDef.referencesField]){
853
+ if(grid.connector.fixedField[fieldDef.referencesField] != null){
854
854
  attr["inherited-pk-column"]="yes";
855
855
  }
856
856
  if(grid.def.field[fieldDef.referencesField].isPk){
@@ -1001,45 +1001,17 @@ myOwn.DataColumnGrid.prototype.td = function td(depot, iColumn, tr, saveRow){
1001
1001
  if(grid.modes.saveByField){
1002
1002
  saveRow(depot,{visiblyLogErrors:false});
1003
1003
  }
1004
- var promiseArray = [];
1005
- if(fieldDef.references){
1006
- //busco FKs que tengan referencien a la tabla, que tengan como source a fieldDef y tengan displayFields
1007
- grid.def.foreignKeys.filter(function(fkDef){
1004
+ var promiseChain = Promise.resolve();
1005
+ if (fieldDef.references) {
1006
+ promiseChain.then(grid.setInheritedFields(depot, function(fkDef){
1008
1007
  return fkDef.references == fieldDef.references &&
1009
1008
  fkDef.fields.find(function(field){
1010
1009
  return field.source == fieldDef.name
1011
1010
  }) &&
1012
- fkDef.displayFields.length
1013
- }).forEach(function(fkDef){
1014
- var fixedFields = fkDef.fields.map(function(field){
1015
- return {fieldName: field.target, value: depot.row[field.source]};
1016
- })
1017
- var dummyElement = html.div().create();
1018
- var Connector = my.offline.mode?my.TableConnectorLocal:my.TableConnector;
1019
- var myConnector = new Connector({
1020
- my:my,
1021
- tableName: fieldDef.references,
1022
- getElementToDisplayCount:function(){ return dummyElement }
1023
- }, {fixedFields: fixedFields});
1024
- myConnector.getStructure();
1025
- //cargo registro y actualizo displayFields
1026
- promiseArray.push(
1027
- myConnector.getData().then(function(data){
1028
- var referencedRow = data[0];
1029
- fkDef.displayFields.forEach(function(displayFieldName){
1030
- var lookupValue=referencedRow?referencedRow[displayFieldName]:null;
1031
- var fieldName = fkDef.alias + '__' + displayFieldName;
1032
- depot.row[fieldName]=lookupValue;
1033
- if(depot.rowControls[fieldName]){
1034
- depot.rowControls[fieldName].setTypedValue(lookupValue);
1035
- }
1036
- })
1037
-
1038
- })
1039
- )
1040
- });
1011
+ fkDef.displayFields.length >= 0
1012
+ }));
1041
1013
  }
1042
- Promise.all(promiseArray).then(function(){
1014
+ promiseChain.then(function(){
1043
1015
  grid.updateRowData(depot,true);
1044
1016
  });
1045
1017
  }
@@ -2008,8 +1980,8 @@ myOwn.TableGrid.prototype.prepareGrid = function prepareGrid(){
2008
1980
  grid.actualName = (grid.def.gridAlias || grid.def.name) + (grid.connector.fixedFields.length ? '-' + JSON4all.stringify(grid.connector.fixedFields.map(function(pair){ return pair.value; })) : '')
2009
1981
  var captionTitle = grid.def.title;
2010
1982
  grid.connector.fixedFields.forEach(function(pair){
2011
- var toCaption = grid.def.field[pair.fieldName].toCaption || my.config.config['grid-smart-caption']
2012
- if(toCaption && pair.value){
1983
+ var toCaption = grid.def.field[pair.fieldName].toCaption ?? my.config.config['grid-smart-caption']
1984
+ if(toCaption && pair.value != null){
2013
1985
  var typeName = grid.def.field[pair.fieldName].typeName;
2014
1986
  captionTitle += ' '
2015
1987
  if(toCaption == 'labeled' || toCaption != 'alone' && (typeName == 'boolean' || typeName == 'integer' || typeName == 'bigint' || typeName == 'decimal')){
@@ -2061,6 +2033,43 @@ myOwn.TableGrid.prototype.prepareGrid = function prepareGrid(){
2061
2033
  // [html.tr([html.th([buttonInsert]),grid.dom.footInfo])]
2062
2034
  ]).create();
2063
2035
  }
2036
+ grid.setInheritedFields = function(depot, filterFun){
2037
+ var promiseArray = [];
2038
+ grid.def.foreignKeys.filter(filterFun||(x=>x)).forEach(function(fkDef){
2039
+ var fixedFields = fkDef.fields.map(function(field){
2040
+ return {fieldName: field.target, value: depot.row[field.source]};
2041
+ })
2042
+ var dummyElement = html.div().create();
2043
+ var Connector = my.offline.mode?my.TableConnectorLocal:my.TableConnector;
2044
+ var myConnector = new Connector({
2045
+ my:my,
2046
+ tableName: fkDef.references,
2047
+ getElementToDisplayCount:function(){ return dummyElement }
2048
+ }, {fixedFields: fixedFields});
2049
+ myConnector.getStructure();
2050
+ //cargo registro y actualizo displayFields
2051
+ promiseArray.push(
2052
+ myConnector.getData().then(function(data){
2053
+ var referencedRow = data[0];
2054
+ grid.def.fields.forEach(function(fieldDef){
2055
+ var foreignFieldName = fieldDef.references == fkDef.references ? fieldDef.referencedName : fieldDef.inherited ? fieldDef.name : null;
2056
+ if (referencedRow && foreignFieldName in referencedRow) {
2057
+ var lookupValue = referencedRow[foreignFieldName];
2058
+ var fieldName = fieldDef.name;
2059
+ depot.row[fieldName]=lookupValue;
2060
+ if(fieldDef.inherited){
2061
+ depot.rowPendingForUpdate[fieldName] = lookupValue;
2062
+ }
2063
+ if(depot.rowControls[fieldName]){
2064
+ depot.rowControls[fieldName].setTypedValue(lookupValue);
2065
+ }
2066
+ }
2067
+ })
2068
+ })
2069
+ )
2070
+ });
2071
+ return Promise.all(promiseArray);
2072
+ }
2064
2073
  grid.dom.main.innerHTML='';
2065
2074
  grid.dom.main.appendChild(grid.dom.table);
2066
2075
  };
@@ -2201,8 +2210,12 @@ myOwn.TableGrid.prototype.displayGrid = function displayGrid(){
2201
2210
  grid.my.clientSides[grid.def.clientSide].prepare(depot);
2202
2211
  };
2203
2212
  depot.clientSidePrepared=true;
2204
- grid.my.clientSides[grid.def.clientSide].update(depot);
2205
2213
  }
2214
+ grid.setInheritedFields(depot).then(function(){
2215
+ if(grid.def.clientSide){
2216
+ grid.my.clientSides[grid.def.clientSide].update(depot);
2217
+ }
2218
+ });
2206
2219
  };
2207
2220
  var changeIoStatus = function changeIoStatus(depot,newStatus, objectWithFieldsOrListOfFieldNames, title){
2208
2221
  var fieldNames=typeof objectWithFieldsOrListOfFieldNames === "string"?[objectWithFieldsOrListOfFieldNames]:(
@@ -199,6 +199,7 @@ export type FieldDefinition = EditableDbDefinition & {
199
199
  inJoin?:string /* alias from sql.join; implies inTable:false */
200
200
  transformer?:string
201
201
  table?:string
202
+ inherited?:boolean
202
203
  } & ({} | {
203
204
  sequence:SequenceDefinition
204
205
  nullable:true
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "backend-plus",
3
3
  "description": "Backend for typed controls",
4
- "version": "1.16.19",
4
+ "version": "1.16.21",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/backend-plus",
@@ -31,7 +31,7 @@
31
31
  "@upgraded/locate-path": "^6.0.0-alfa.1",
32
32
  "ajax-best-promise": "^0.3.7",
33
33
  "backend-skins": "^0.1.15",
34
- "best-globals": "^1.0.3",
34
+ "best-globals": "^1.0.4",
35
35
  "big.js": "^6.2.1",
36
36
  "body-parser": "^1.20.1",
37
37
  "cast-error": "^0.1.0",
@@ -78,11 +78,11 @@
78
78
  "@types/expect.js": "~0.3.29",
79
79
  "@types/express": "^4.17.15",
80
80
  "@types/express-useragent": "^1.0.2",
81
- "@types/fs-extra": "^9.0.13",
81
+ "@types/fs-extra": "^11.0.0",
82
82
  "@types/js-yaml": "^4.0.5",
83
83
  "@types/mocha": "^10.0.1",
84
84
  "@types/multiparty": "~0.0.33",
85
- "@types/node": "^18.11.17",
85
+ "@types/node": "^18.11.18",
86
86
  "@types/nodemailer": "^6.4.7",
87
87
  "@types/numeral": "~2.0.2",
88
88
  "@types/session-file-store": "^1.2.2",
@@ -102,7 +102,7 @@
102
102
  "puppeteer": "^19.4.1",
103
103
  "sinon": "^15.0.1",
104
104
  "supertest": "^6.3.3",
105
- "types.d.ts": "~0.6.9",
105
+ "types.d.ts": "~0.6.11",
106
106
  "typescript": "^4.9.4",
107
107
  "why-is-node-running": "^2.2.2"
108
108
  },
@@ -582,7 +582,7 @@ function noChange(x){ return x; }
582
582
  myAjax.UriSearchToObjectParams={
583
583
  i :{ showInMenu:true , encode:function(value,menu){ return menu.name?(menu.parents||[]).concat(menu.name).join(','):value }},
584
584
  fc :{ encode:function(x){ return JSON.stringify(x); }, U:function(x){ return JSON.parse(x)} },
585
- ff :{ encode:function(x){ return JSON.stringify(x); }, decode:function(x){ return JSON.parse(x)} },
585
+ ff :{ encode:function(x){ return json4all.stringify(x); }, decode:function(x){ return json4all.parse(x)} },
586
586
  up :{ encode:function(x){ return json4all.stringify(x); }, decode:function(x){ return json4all.parse(x)} },
587
587
  pf :{ encode:function(x){ return JSON.stringify(x); }, decode:function(x){ return JSON.parse(x)} },
588
588
  today :{ encode:function(x){ return JSON.stringify(x); }, decode:function(x){ return bestGlobals.date.iso((x+'').substr(0,10))} },
@@ -592,7 +592,7 @@ myAjax.UriSearchToObjectParams={
592
592
  showParams :{ hide:true },
593
593
  parents :{ hide:true },
594
594
  button :{ hide:true },
595
- fixedFields :{ varName:'ff' , encode:function(pairs){ return JSON.stringify(likeAr.toPlainObject(pairs, 'fieldName')); }},
595
+ fixedFields :{ varName:'ff' , encode:function(pairs){ return json4all.stringify(likeAr.toPlainObject(pairs, 'fieldName')); }},
596
596
  detailing :{ encode:function(x){ return JSON.stringify(x); }, decode:function(x){ return JSON.parse(x)} },
597
597
  }
598
598