form view - find by ID

This commit is contained in:
Jan Prochazka
2021-01-14 19:36:03 +01:00
parent ad4fa77e46
commit 4328107a1d
4 changed files with 103 additions and 30 deletions

View File

@@ -73,4 +73,44 @@ export class FormViewDisplay {
refreshTime: new Date().getTime(),
}));
}
getKeyValue(columnName) {
const { formViewKey, formViewKeyRequested } = this.config;
if (formViewKeyRequested && formViewKeyRequested[columnName]) return formViewKeyRequested[columnName];
if (formViewKey && formViewKey[columnName]) return formViewKey[columnName];
return null;
}
requestKeyValue(columnName, value) {
if (this.getKeyValue(columnName) == value) return;
this.setConfig((cfg) => ({
...cfg,
formViewKeyRequested: {
...cfg.formViewKey,
...cfg.formViewKeyRequested,
[columnName]: value,
},
}));
this.reload();
}
extractKey(row) {
if (!row || !this.baseTable || !this.baseTable.primaryKey) {
return null;
}
const formViewKey = _.pick(
row,
this.baseTable.primaryKey.columns.map((x) => x.columnName)
);
return formViewKey;
}
cancelRequestKey(rowData) {
this.setConfig((cfg) => ({
...cfg,
formViewKeyRequested: null,
formViewKey: rowData ? this.extractKey(rowData) : cfg.formViewKey,
}));
}
}

View File

@@ -39,7 +39,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
}
getPrimaryKeyEqualCondition(row = null): Condition {
if (!row) row = this.config.formViewKey;
if (!row) row = this.config.formViewKeyRequested || this.config.formViewKey;
if (!row) return null;
const { primaryKey } = this.gridDisplay.baseTable;
if (!primaryKey) return null;
@@ -57,7 +57,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
},
right: {
exprType: 'value',
value: this.config.formViewKey[columnName],
value: row[columnName],
},
})),
};
@@ -166,17 +166,6 @@ export class TableFormViewDisplay extends FormViewDisplay {
return sql;
}
extractKey(row) {
if (!row || !this.gridDisplay.baseTable || !this.gridDisplay.baseTable.primaryKey) {
return null;
}
const formViewKey = _.pick(
row,
this.gridDisplay.baseTable.primaryKey.columns.map((x) => x.columnName)
);
return formViewKey;
}
navigate(row) {
const formViewKey = this.extractKey(row);
this.setConfig((cfg) => ({