Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api4 Explorer - Use metadata for field suffixes instead of guessing #24168

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions ang/api4Explorer/Explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
var fieldInfo = _.cloneDeep(_.findWhere(getEntity().actions, {name: action}).fields);
fieldList.length = 0;
if (addPseudoconstant) {
addPseudoconstants(fieldInfo, addPseudoconstant);
addPseudoconstants(fieldInfo);
}
if (addWriteJoins) {
addWriteJoinFields(fieldInfo);
Expand Down Expand Up @@ -198,7 +198,7 @@
});
}
if (addPseudoconstant) {
addPseudoconstants(joinFields, addPseudoconstant);
addPseudoconstants(joinFields);
}
fieldList.push({
text: join.entity + ' AS ' + join.alias,
Expand All @@ -213,7 +213,7 @@
var linkFields = _.cloneDeep(entityFields(field.fk_entity)),
wildCard = addWildcard ? [{id: field.name + '.*', text: field.name + '.*', 'description': 'All core ' + field.fk_entity + ' fields'}] : [];
if (addPseudoconstant) {
addPseudoconstants(linkFields, addPseudoconstant);
addPseudoconstants(linkFields);
}
fieldList.push({
text: field.name,
Expand All @@ -225,11 +225,11 @@
}

// Note: this function transforms a raw list a-la getFields; not a select2-formatted list
function addPseudoconstants(fieldList, toAdd) {
function addPseudoconstants(fieldList) {
var optionFields = _.filter(fieldList, 'options');
_.each(optionFields, function(field) {
var pos = _.findIndex(fieldList, {name: field.name}) + 1;
_.each(toAdd, function(suffix) {
_.each(field.suffixes, function(suffix) {
var newField = _.cloneDeep(field);
newField.name += ':' + suffix;
fieldList.splice(pos, 0, newField);
Expand Down Expand Up @@ -319,7 +319,7 @@
$scope.fieldList = function(param) {
return function() {
var fields = [];
getFieldList(fields, $scope.action === 'getFields' ? ($scope.params.action || 'get') : $scope.action, ['name'], true);
getFieldList(fields, $scope.action === 'getFields' ? ($scope.params.action || 'get') : $scope.action, true, true);
// Disable fields that are already in use
_.each($scope.params[param] || [], function(val) {
var usedField = val[0].replace(/[:.]name/, '');
Expand Down Expand Up @@ -482,10 +482,10 @@
this.buildFieldList = function() {
var actionInfo = _.findWhere(actions, {id: $scope.action});
getFieldList($scope.fields, $scope.action);
getFieldList($scope.fieldsAndJoins, $scope.action, ['name']);
getFieldList($scope.fieldsAndJoins, $scope.action, true);
getFieldList($scope.fieldsAndJoinsAndFunctions, $scope.action);
getFieldList($scope.fieldsAndJoinsAndFunctionsWithSuffixes, $scope.action, ['name', 'label']);
getFieldList($scope.fieldsAndJoinsAndFunctionsAndWildcards, $scope.action, ['name', 'label']);
getFieldList($scope.fieldsAndJoinsAndFunctionsWithSuffixes, $scope.action, true);
getFieldList($scope.fieldsAndJoinsAndFunctionsAndWildcards, $scope.action, true);
if (_.contains(['get', 'update', 'delete', 'replace'], $scope.action)) {
addJoins($scope.fieldsAndJoins);
// SQL functions are supported if HAVING is
Expand All @@ -506,8 +506,8 @@
$scope.fieldsAndJoinsAndFunctionsAndWildcards.push(functions);
}
addJoins($scope.fieldsAndJoinsAndFunctions, true);
addJoins($scope.fieldsAndJoinsAndFunctionsWithSuffixes, false, ['name', 'label']);
addJoins($scope.fieldsAndJoinsAndFunctionsAndWildcards, true, ['name', 'label']);
addJoins($scope.fieldsAndJoinsAndFunctionsWithSuffixes, false, true);
addJoins($scope.fieldsAndJoinsAndFunctionsAndWildcards, true, true);
}
// Custom fields are supported if HAVING is
if (actionInfo.params.having) {
Expand Down