Skip to content

Commit

Permalink
make sure pattern_sources support same syntax as vis-col
Browse files Browse the repository at this point in the history
  • Loading branch information
RFSH committed Feb 17, 2024
1 parent 4a7ae30 commit 130d46c
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 63 deletions.
18 changes: 12 additions & 6 deletions docs/dev-docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ to use for ERMrest JavaScript agents.
* [.getAggregates(aggregateList)](#ERMrest.Reference+getAggregates) ⇒ <code>Promise</code>
* [.setSamePaging(page)](#ERMrest.Reference+setSamePaging)[<code>Reference</code>](#ERMrest.Reference)
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)
Expand Down Expand Up @@ -783,7 +783,7 @@ to use for ERMrest JavaScript agents.
* [.getAggregates(aggregateList)](#ERMrest.Reference+getAggregates) ⇒ <code>Promise</code>
* [.setSamePaging(page)](#ERMrest.Reference+setSamePaging)[<code>Reference</code>](#ERMrest.Reference)
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)
Expand Down Expand Up @@ -3198,7 +3198,7 @@ Constructor for a ParsedFilter.
* [.getAggregates(aggregateList)](#ERMrest.Reference+getAggregates) ⇒ <code>Promise</code>
* [.setSamePaging(page)](#ERMrest.Reference+setSamePaging)[<code>Reference</code>](#ERMrest.Reference)
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)
Expand Down Expand Up @@ -3910,7 +3910,7 @@ Will throw an error if

<a name="ERMrest.Reference+generateColumnsList"></a>

#### reference.generateColumnsList(tuple) ⇒ [<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
#### reference.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog) ⇒ [<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
Generates the list of visible columns
The logic is as follows:

Expand Down Expand Up @@ -3963,6 +3963,9 @@ NOTE:
| Param | Type | Description |
| --- | --- | --- |
| tuple | [<code>Tuple</code>](#ERMrest.Tuple) | the data for the current refe |
| columnsList | <code>Array.&lt;Object&gt;</code> | if passed, we will skip the annotation and heuristics and use this list instead. |
| dontChangeReference | <code>boolean</code> | whether we should mutate the reference or just return the generated list. |
| skipLog | <code>boolean</code> | whether we should skip logging the warning messages |

<a name="ERMrest.Reference+generateActiveList"></a>

Expand Down Expand Up @@ -7046,7 +7049,7 @@ get PathColumn object by column name
* [.getAggregates(aggregateList)](#ERMrest.Reference+getAggregates) ⇒ <code>Promise</code>
* [.setSamePaging(page)](#ERMrest.Reference+setSamePaging)[<code>Reference</code>](#ERMrest.Reference)
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)
Expand Down Expand Up @@ -7758,7 +7761,7 @@ Will throw an error if

<a name="ERMrest.Reference+generateColumnsList"></a>

#### reference.generateColumnsList(tuple) ⇒ [<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
#### reference.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog) ⇒ [<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
Generates the list of visible columns
The logic is as follows:

Expand Down Expand Up @@ -7811,6 +7814,9 @@ NOTE:
| Param | Type | Description |
| --- | --- | --- |
| tuple | [<code>Tuple</code>](#ERMrest.Tuple) | the data for the current refe |
| columnsList | <code>Array.&lt;Object&gt;</code> | if passed, we will skip the annotation and heuristics and use this list instead. |
| dontChangeReference | <code>boolean</code> | whether we should mutate the reference or just return the generated list. |
| skipLog | <code>boolean</code> | whether we should skip logging the warning messages |

<a name="ERMrest.Reference+generateActiveList"></a>

Expand Down
2 changes: 1 addition & 1 deletion docs/user-docs/annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ Supported _domainfilter_ syntax:

Supported _columnlist_ patterns:

- `[` ... _columndirective_ `,` ... `]`: The list of [columns directives](#column-directive) that are used in the pattern.
- `[` ... _columndirective_ `,` ... `]`: The list of [columns directives](#column-directive) that are used in the `ermrest_path_pattern`. Make sure to use the same column directive as visible columns. For example if you've used column named `fk_col` in the pattern, but the foreign key that this column is part of visible, you should include the foreign key column here (and not the `fk_col` itself).

Supported _filter_ syntax:

Expand Down
16 changes: 3 additions & 13 deletions js/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,8 @@ Object.defineProperty(ForeignKeyPseudoColumn.prototype, "hasDomainFilter", {
var populateDomainFilterProps = function (self) {
// the annotaion didn't exist
if (!self.foreignKey.annotations.contains(module._annotations.FOREIGN_KEY)) {
self._domainFilterRawString = '';
self._domainFilterUsedColumns = [];
return false;
}

Expand All @@ -1929,19 +1931,7 @@ Object.defineProperty(ForeignKeyPseudoColumn.prototype, "hasDomainFilter", {

var usedColumns = [];
if (Array.isArray(content.domain_filter.pattern_sources)) {
content.domain_filter.pattern_sources.forEach(function (col) {
var visCol;
try {
// TODO we might be more smart about this
// for example if a raw column is used but the fk is visible, should we mention the fk?
// TODO I should most probably move the vis-col logic somewhere so it can be called from here
// that way they can use sourcekey etc...
visCol = self._baseReference.getColumnByName(Array.isArray(col) ? col.join('_') : col);
} catch(exp) {
// fail silently
}
if (visCol) usedColumns.push(visCol);
});
usedColumns = self._baseReference.generateColumnsList(undefined, content.domain_filter.pattern_sources, true, true);
}
self._domainFilterUsedColumns = usedColumns;

Expand Down
57 changes: 33 additions & 24 deletions js/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3186,15 +3186,15 @@
* we should hide the foreign key (and all of its columns) that created the link.
*
* @param {ERMrest.Tuple} tuple the data for the current refe
* @param {Object[]} columnsList if passed, we will skip the annotation and heuristics and use this list instead.
* @param {boolean?} dontChangeReference whether we should mutate the reference or just return the generated list.
* @param {boolean?} skipLog whether we should skip logging the warning messages
* @return {ERMrest.ReferenceColumn[]} Array of {@link ERMrest.ReferenceColumn}.
*/
generateColumnsList: function(tuple) {

this._referenceColumns = [];
generateColumnsList: function(tuple, columnsList, dontChangeReference, skipLog) {
var resultColumns = [];

var self = this;


var columns = -1,
consideredColumns = {}, // to avoid duplicate pseudo columns
tableColumns = {}, // to make sure the hashes we genereate are not clashing with table column names
Expand Down Expand Up @@ -3230,7 +3230,7 @@
var _addAssetColumn = function (col, sourceObjectWrapper, name, heuristics) {
var assetCol = new AssetPseudoColumn(self, col, sourceObjectWrapper, name, tuple);
assetColumns.push(assetCol);
self._referenceColumns.push(assetCol);
resultColumns.push(assetCol);

// as part of heuristics we only want the asset be added and not the column,
// so adding it to considered ones to avoid adding it again.
Expand Down Expand Up @@ -3271,14 +3271,16 @@
}

// add it as a reference column
self._referenceColumns.push(new ReferenceColumn(self, [col], sourceObjectWrapper, name, tuple));
resultColumns.push(new ReferenceColumn(self, [col], sourceObjectWrapper, name, tuple));
};

// make sure generated hash is not the name of any columns in the table
var nameExistsInTable = function (name, obj) {
if (name in tableColumns) {
module._log.info("Generated Hash `" + name + "` for pseudo-column exists in table `" + self.table.name +"`.");
module._log.info("Ignoring the following in visible-columns: ", obj);
if (!skipLog) {
module._log.info("Generated Hash `" + name + "` for pseudo-column exists in table `" + self.table.name +"`.");
module._log.info("Ignoring the following in visible-columns: ", obj);
}
return true;
}
return false;
Expand All @@ -3287,7 +3289,7 @@
var pf = module._printf;
var wm = module._warningMessages;
var logCol = function (bool, message, i) {
if (bool) {
if (bool && !skipLog) {
module._log.info("columns list for table: " + self.table.name + ", context: " + context + ", column index:" + i);
module._log.info(message);
}
Expand All @@ -3299,8 +3301,12 @@
tableColumns[c.name] = true;
});

// get columns from the input (used when we just want to process the given list of columns)
if (Array.isArray(columnsList)) {
columns = columnsList;
}
// get column orders from annotation
if (this._table.annotations.contains(module._annotations.VISIBLE_COLUMNS)) {
else if (this._table.annotations.contains(module._annotations.VISIBLE_COLUMNS)) {
columns = module._getRecursiveAnnotationValue(this._context, this._table.annotations.get(module._annotations.VISIBLE_COLUMNS).content);
}

Expand All @@ -3323,7 +3329,7 @@
// avoid duplicate and same name in database
if (!logCol((fkName in consideredColumns), wm.DUPLICATE_FK, i) && !nameExistsInTable(fkName, col)) {
consideredColumns[fkName] = true;
this._referenceColumns.push(new ForeignKeyPseudoColumn(this, fk));
resultColumns.push(new ForeignKeyPseudoColumn(this, fk));
}
}
// inbound foreignkey
Expand All @@ -3332,7 +3338,7 @@
fkName = _sourceColumnHelpers.generateForeignKeyName(fk, true);
if (!logCol(fkName in consideredColumns, wm.DUPLICATE_FK, i) && !logCol(context !== module._contexts.DETAILED && context.indexOf(module._contexts.EXPORT) == -1, wm.NO_INBOUND_IN_NON_DETAILED, i) && !nameExistsInTable(fkName, col)) {
consideredColumns[fkName] = true;
this._referenceColumns.push(new InboundForeignKeyPseudoColumn(this, this._generateRelatedReference(fk, tuple, true), null, fkName));
resultColumns.push(new InboundForeignKeyPseudoColumn(this, this._generateRelatedReference(fk, tuple, true), null, fkName));
}
} else {
logCol(true, wm.FK_NOT_RELATED, i);
Expand All @@ -3355,7 +3361,7 @@
}
}
} else {
this._referenceColumns.push(new KeyPseudoColumn(this, fk));
resultColumns.push(new KeyPseudoColumn(this, fk));
}
}
break;
Expand All @@ -3382,7 +3388,7 @@
pseudoName += "-" + extra;
}
virtualColumnNames[pseudoName] = true;
this._referenceColumns.push(new VirtualColumn(this, new SourceObjectWrapper(col), pseudoName, tuple));
resultColumns.push(new VirtualColumn(this, new SourceObjectWrapper(col), pseudoName, tuple));
}
continue;
}
Expand Down Expand Up @@ -3474,7 +3480,7 @@

// in entry mode, pseudo-column, inbound fk, and key are not allowed
if (!removePseudo) {
this._referenceColumns.push(refCol);
resultColumns.push(refCol);
}
}
}
Expand Down Expand Up @@ -3524,7 +3530,7 @@
});

if (ridKey) {
this._referenceColumns.push(new KeyPseudoColumn(this, ridKey));
resultColumns.push(new KeyPseudoColumn(this, ridKey));
consideredColumns[ridKey.colset.columns[0].name] = true;
}
}
Expand Down Expand Up @@ -3553,7 +3559,7 @@
}
// otherwise just add the key pseudo-column
else {
this._referenceColumns.push(new KeyPseudoColumn(this, key));
resultColumns.push(new KeyPseudoColumn(this, key));
}
}
}
Expand Down Expand Up @@ -3633,7 +3639,7 @@
if (fk.simple) { // simple FKR
if (!(fkName in consideredColumns) && !nameExistsInTable(fkName, fk._constraintName)) {
consideredColumns[fkName] = true;
this._referenceColumns.push(new ForeignKeyPseudoColumn(this, fk));
resultColumns.push(new ForeignKeyPseudoColumn(this, fk));
}
} else { // composite FKR

Expand All @@ -3658,7 +3664,7 @@

// append composite FKRs
for (i = 0; i < compositeFKs.length; i++) {
this._referenceColumns.push(compositeFKs[i]);
resultColumns.push(compositeFKs[i]);
}

}
Expand All @@ -3667,8 +3673,8 @@
if (!isEntry) {

// Iterate over all reference columns
for (i = 0; i < this._referenceColumns.length; i++) {
refCol = this._referenceColumns[i];
for (i = 0; i < resultColumns.length; i++) {
refCol = resultColumns[i];
var isHidden = false;

// Iterate over the base columns. If any of them are hidden then hide the column
Expand All @@ -3681,13 +3687,16 @@

// If isHidden flag is true then remove the column at ith index
if (isHidden) {
this._referenceColumns.splice(i, 1);
resultColumns.splice(i, 1);
i--;
}
}
}

return this._referenceColumns;
if (!dontChangeReference) {
this._referenceColumns = resultColumns;
}
return resultColumns;
},

/**
Expand Down
Loading

0 comments on commit 130d46c

Please sign in to comment.