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

Log changes #829

Merged
merged 7 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This document is a summary of code changes in Chaise. This is the vocabulary use
- [Changed] how we encode search filter in the url to use the new `search-box` sourcekey.
- [Added] `comment` support to display annotation.
- [Changed] `comment` behavior in annotations so that `false` is treated the same as empty string.
- [Added] `elapsed_s` attribute to `Deriva-Client-Context` header object for all the http requests.
- [Added] `elapsed_ms` attribute to `Deriva-Client-Context` header object for all the http requests.
- [Added] `show_foreign_key_link` support.
- [Changed] `show_nulls` to `show_null` in display annotation.

Expand Down
162 changes: 148 additions & 14 deletions docs/dev-docs/api.md

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions js/ag_reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,11 @@ AttributeGroupReference.prototype = {
uri += "?limit=" + (limit+1);
}

var currRef = this;
var currRef = this, action = "read";
if (!contextHeaderParams || !isObject(contextHeaderParams)) {
contextHeaderParams = {"action": "read"};
contextHeaderParams = {"action": action};
} else if (typeof contextHeaderParams.action === "string") {
action = contextHeaderParams.action;
}
var config = {
headers: this._generateContextHeader(contextHeaderParams, limit)
Expand Down Expand Up @@ -395,7 +397,10 @@ AttributeGroupReference.prototype = {
// a new location without paging
var newLocation = currRef.location.changePage();
var referenceWithoutPaging = new AttributeGroupReference(currRef._keyColumns, currRef._aggregateColumns, newLocation, currRef._catalog, currRef.table, currRef._context);
referenceWithoutPaging.read(limit).then(function rereadReference(rereadPage) {

// remove the function and replace it with auto-reload
contextHeaderParams.action = action.substring(0,action.lastIndexOf(";")+1) + "auto-reload";
referenceWithoutPaging.read(limit, contextHeaderParams).then(function rereadReference(rereadPage) {
defer.resolve(rereadPage);
}, function error(err) {
throw err;
Expand Down Expand Up @@ -533,6 +538,19 @@ AttributeGroupReference.prototype = {
return obj;
},

/**
* The filter information that should be logged
* Currently only includes the search term.
* @type {Object}
*/
get filterLogInfo() {
var obj = {};
if (isObjectAndNotNull(this.location.searchObject) && typeof this.location.searchTerm === "string" && this.location.searchTerm) {
obj.filters = _compressFacetObject({"and": [{"source": "search-box", "search": [this.location.searchTerm]}]});
}
return obj;
},

_generateContextHeader: function (contextHeaderParams, page_size) {
if (!contextHeaderParams || !isObject(contextHeaderParams)) {
contextHeaderParams = {};
Expand Down
95 changes: 57 additions & 38 deletions js/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,23 @@ ReferenceColumn.prototype = {
},

/**
* the source path from the main reference to this column
* the compressed source path from the main reference to this column
* @type{Object}
*/
get dataSource() {
if (this._dataSource === undefined) {
get compressedDataSource() {
if (this._compressedDataSource === undefined) {
var ds;
if (this.sourceObject && this.sourceObject.source) {
this._dataSource = this.sourceObject.source;
ds = this.sourceObject.source;
} else if (this._simple) {
this._dataSource = this._baseCols[0].name;
ds = this._baseCols[0].name;
} else {
this._dataSource = null;
ds = null;
}

this._compressedDataSource = _compressSource(ds);
}
return this._dataSource;
return this._compressedDataSource;
},

/**
Expand Down Expand Up @@ -1455,6 +1458,14 @@ Object.defineProperty(PseudoColumn.prototype, "hasAggregate", {
return this._hasAggregate;
}
});
Object.defineProperty(PseudoColumn.prototype, "aggregateFn", {
get: function () {
if (this._aggregateFn === undefined) {
this._aggregateFn = this.hasAggregate ? this.sourceObject.aggregate : null;
}
return this._aggregateFn;
}
});

/**
* Returns a reference to the current pseudo-column
Expand Down Expand Up @@ -1541,7 +1552,7 @@ Object.defineProperty(PseudoColumn.prototype, "reference", {
// make sure data-source is available on the reference
// TODO this has been added to be consistent with the old related reference apis
// other apis are not available, maybe we should add them as well? (origFKR, etc.)
self._reference.dataSource = self.dataSource;
self._reference.compressedDataSource = self.compressedDataSource;

// make sure the refernece has the correct displayname
if (self.hasPath) {
Expand Down Expand Up @@ -1960,21 +1971,23 @@ Object.defineProperty(ForeignKeyPseudoColumn.prototype, "display", {
return this._display_cached;
}
});
Object.defineProperty(ForeignKeyPseudoColumn.prototype, "dataSource", {
Object.defineProperty(ForeignKeyPseudoColumn.prototype, "compressedDataSource", {
get: function () {
if (this._dataSource === undefined) {
if (this._compressedDataSource === undefined) {
var ds;
if (this.sourceObject && this.sourceObject.source) {
this._dataSource = this.sourceObject.source;
ds = this.sourceObject.source;
} else if (this.table.shortestKey.length === 1){
this._dataSource = [
ds = [
{"outbound": this.foreignKey.constraint_names[0]},
this.table.shortestKey[0].name
];
} else {
this._dataSource = null;
ds = null;
}
this._compressedDataSource = _compressSource(ds);
}
return this._dataSource;
return this._compressedDataSource;
}
});

Expand Down Expand Up @@ -2635,18 +2648,18 @@ Object.defineProperty(InboundForeignKeyPseudoColumn.prototype, "nullok", {
throw new Error("can not use this type of column in entry mode.");
}
});
Object.defineProperty(InboundForeignKeyPseudoColumn.prototype, "dataSource", {
Object.defineProperty(InboundForeignKeyPseudoColumn.prototype, "compressedDataSource", {
get: function () {
if (this._dataSource === undefined) {
if (this._compressedDataSource === undefined) {
var ds = null;
if (this.sourceObject && this.sourceObject.source) {
this._dataSource = this.sourceObject.source;
} else if (this.reference.dataSource){
this._dataSource = this.reference.dataSource;
} else {
this._dataSource = null;
ds = _compressSource(this.sourceObject.source);
} else if (this.reference.compressedDataSource){
ds = this.reference.compressedDataSource;
}
this._compressedDataSource = ds;
}
return this._dataSource;
return this._compressedDataSource;
}
});

Expand Down Expand Up @@ -2696,6 +2709,12 @@ function FacetColumn (reference, index, column, facetObject, filters) {
*/
this.dataSource = facetObject.source;

/**
* the compressed version of data source data-source path
* @type {obj|string}
*/
this.compressedDataSource = _compressSource(facetObject.source);

/**
* Filters that are applied to this facet.
* @type{FacetFilter[]}
Expand Down Expand Up @@ -3327,8 +3346,21 @@ FacetColumn.prototype = {
* @return {Promise} A promise resolved with list of objects that have `uniqueId`, and `displayname`.
*/
getChoiceDisplaynames: function (contextHeaderParams) {
var defer = module._q.defer();
var filters = [];
var defer = module._q.defer(), filters = [];
var table = this._column.table, columnName = this._column.name;

var createRef = function (filterStrs) {
var uri = [
table.schema.catalog.server.uri ,"catalog" ,
table.schema.catalog.id, "entity",
module._fixedEncodeURIComponent(table.schema.name) + ":" + module._fixedEncodeURIComponent(table.name),
filterStrs.join(";")
].join("/");

var ref = new Reference(module.parse(uri), table.schema.catalog).contextualize.compactSelect;
ref = ref.sort([{"column": columnName, "descending": false}]);
return ref;
};

// if no filter, just resolve with empty list.
if (this.choiceFilters.length === 0) {
Expand All @@ -3347,8 +3379,6 @@ FacetColumn.prototype = {
}
// otherwise generate an ermrest request to get the displaynames.
else {

var table = this._column.table, columnName = this._column.name;
var filterStr = [];

// list of filters that we want their displaynames.
Expand All @@ -3369,18 +3399,7 @@ FacetColumn.prototype = {
}

// create a url
var uri = [
table.schema.catalog.server.uri ,"catalog" ,
table.schema.catalog.id, "entity",
module._fixedEncodeURIComponent(table.schema.name) + ":" + module._fixedEncodeURIComponent(table.name),
filterStr.join(";")
].join("/");

var ref = new Reference(module.parse(uri), table.schema.catalog).contextualize.compactSelect;

ref = ref.sort([{"column": columnName, "descending": false}]);

ref.read(this.choiceFilters.length, contextHeaderParams, true).then(function (page) {
createRef(filterStr).read(this.choiceFilters.length, contextHeaderParams, true).then(function (page) {
// create the response
page.tuples.forEach(function (t) {
filters.push({uniqueId: t.data[columnName], displayname: t.displayname, tuple: t});
Expand Down
65 changes: 60 additions & 5 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
headers[module.contextHeaderName] = contextHeaderParams;
} else {
headers[module.contextHeaderName] = {
action: "model/snaptime",
action: ":,catalog/snaptime;load",
catalog: self.id
};
}
Expand Down Expand Up @@ -357,7 +357,7 @@
self.snaptime = snaptime;
var headers = {};
headers[module.contextHeaderName] = {
action: "model/schema",
action: ":,catalog/schema;load",
catalog: self.id
};
return self.server.http.get(self._uri + "/schema", {headers: headers});
Expand Down Expand Up @@ -594,10 +594,17 @@
this.catalog = catalog;

/**
*
* @desc the database name of the schema
* @type {string}
*/
this.name = jsonSchema.schema_name;

/**
* @desc The RID of this schema (might not be defined)
* @type {?string}
*/
this.RID = jsonSchema.RID;

//this._uri = catalog._uri + "/schema/" + module._fixedEncodeURIComponent(this.name);

/**
Expand Down Expand Up @@ -807,11 +814,18 @@
this.schema = schema;

/**
*
* @desc the database name of the table
* @type {string}
*/
this.name = jsonTable.table_name;
this._jsonTable = jsonTable;

/**
* @desc The RID of this table (might not be defined)
* @type {?string}
*/
this.RID = jsonTable.RID;


this._nullValue = {}; // used to avoid recomputation of null value for different contexts.

Expand Down Expand Up @@ -2458,10 +2472,17 @@
this.isImmutable = this.rights.update === false;

/**
* The database name of this column
* @type {string}
*/
this.name = jsonColumn.name;

/**
* @desc The RID of this column (might not be defined)
* @type {?string}
*/
this.RID = jsonColumn.RID;

/**
*
* @type {ERMrest.Type}
Expand Down Expand Up @@ -3048,6 +3069,12 @@
}
}

/**
* @desc The RID of this key (might not be defined)
* @type {?string}
*/
this.RID = jsonKey.RID;

/**
* The exact `names` array in key definition
* @type {Array}
Expand Down Expand Up @@ -3558,8 +3585,18 @@
*/
this._table = table;

/**
* @desc The table that this foreignkey is defined on (from table)
* @type {ERMrest.Table}
*/
this.table = table;

/**
* @desc The RID of this column (might not be defined)
* @type {?string}
*/
this.RID = jsonFKR.RID;

var catalog = table.schema.catalog;

// create ColSet for foreign key columns
Expand Down Expand Up @@ -3678,7 +3715,25 @@
constructor: ForeignKeyRef,

/**
* A unique nam that can be used for referring to this foreignkey.
* the compressed source path from the main reference to this column
* @type{Object}
*/
get compressedDataSource() {
if (this._compressedDataSource === undefined) {
var ds = null;
if (this.table.shortestKey.length === 1) {
ds = [
{"outbound": this.constraint_names[0]},
this.table.shortestKey[0].name
];
}
this._compressedDataSource = _compressSource(ds);
}
return this._compressedDataSource;
},

/**
* A unique name that can be used for referring to this foreignkey.
* @type {string}
*/
get name () {
Expand Down
5 changes: 0 additions & 5 deletions js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ var ERMrest = (function(module) {
if (key in contextHeaderParams) continue;
contextHeaderParams[key] = self.reference.defaultLogInfo[key];
}
// add the displayname and type of template
contextHeaderParams.template = {
displayname: self.template.displayname,
type: self.template.type
};
headers[module.contextHeaderName] = contextHeaderParams;

self.canceled = false;
Expand Down
3 changes: 1 addition & 2 deletions js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
function wrap(method, fn, scope) {
scope = scope || window;
var cfg_idx = _method_to_config_idx[method];
var startTime = Date.now();
return function() {
var args;

Expand Down Expand Up @@ -171,7 +170,7 @@
*
**/
if (typeof config.headers[module.contextHeaderName] === 'object') {
config.headers[module.contextHeaderName].elapsed_s = Date.now() - startTime;
config.headers[module.contextHeaderName].elapsed_ms = module.getElapsedTime();
// encode and make sure it's not very lengthy
config.headers[module.contextHeaderName] = module._certifyContextHeader(config.headers[module.contextHeaderName]);
}
Expand Down
Loading