Skip to content

Commit

Permalink
Merge pull request #1748 from informatics-isi-edu/cleanup-log
Browse files Browse the repository at this point in the history
Fix Log Issues
  • Loading branch information
RFSH authored Apr 18, 2019
2 parents ced0a7f + d1cbba0 commit 777febb
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 110 deletions.
44 changes: 39 additions & 5 deletions common/faceting.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,28 @@
}
};

/**
* Generate the object that we want to be logged alongside the action
* This function does not attach action, after calling this function
* we should attach the action.
* @param {object} scope the scope object
*/
function getDefaultLogInfo(scope) {
var res = scope.facetColumn.sourceReference.defaultLogInfo;

// remove unnecessary attributes
// these attributes exist on the referrer as well
delete res.facet;
delete res.cfacet;
delete res.cfacet_str;
delete res.cfacet_path;

res.referrer = scope.facetColumn.reference.defaultLogInfo;
res.source = scope.facetColumn.dataSource;
res.column = scope.facetColumn.column.name;
return res;
}

// range is defined by the x values of the bar graph because layout.xaxis.type is `linear` or 'category'
function setHistogramRange() {
if (isColumnOfType("timestamp")) {
Expand Down Expand Up @@ -584,7 +606,9 @@
var requestMin = isColumnOfType("timestamp") ? dateTimeToTimestamp(scope.rangeOptions.absMin) : scope.rangeOptions.absMin,
requestMax = isColumnOfType("timestamp") ? dateTimeToTimestamp(scope.rangeOptions.absMax) : scope.rangeOptions.absMax;

scope.facetColumn.column.groupAggregate.histogram(numBuckets, requestMin, requestMax).read().then(function (response) {
var facetLog = getDefaultLogInfo(scope);
facetLog.action = logActions.recordsetFacetHistogram;
scope.facetColumn.column.groupAggregate.histogram(numBuckets, requestMin, requestMax).read(facetLog).then(function (response) {
if (scope.facetColumn.sourceReference.uri !== uri) {
// return breaks out of the current callback function
defer.resolve(false);
Expand Down Expand Up @@ -642,10 +666,8 @@
agg.maxAgg
];

var facetLog = scope.facetColumn.sourceReference.defaultLogInfo;
facetLog.referrer = scope.facetColumn.reference.defaultLogInfo;
facetLog.source = scope.facetColumn.dataSource;
facetLog.action = logActions.recordsetFacetRead,
var facetLog = getDefaultLogInfo(scope);
facetLog.action = logActions.recordsetFacetRead;
scope.facetColumn.sourceReference.getAggregates(aggregateList, facetLog).then(function(response) {
if (scope.facetColumn.sourceReference.uri !== uri) {
// return false to defer.resolve() in .then() callback
Expand Down Expand Up @@ -894,6 +916,8 @@
if (scope.facetColumn.hasNullFilter) {
scope.facetModel.appliedFilters.push(facetingUtils.getNullFilter(true));
}
var facetLog = getDefaultLogInfo(scope);
facetLog.action = logActions.recordsetFacetInit;
scope.facetColumn.getChoiceDisplaynames().then(function (filters) {
filters.forEach(function (f) {
scope.facetModel.appliedFilters.push({
Expand Down Expand Up @@ -1091,6 +1115,16 @@
var res = scope.facetColumn.sourceReference.defaultLogInfo;
res.referrer = scope.facetColumn.reference.defaultLogInfo;
res.source = scope.facetColumn.dataSource;
if (!scope.facetColumn.isEntityMode) {
res.column = scope.facetColumn.column.name;
}

// remove unnecessary attributes
// these attributes exist on the referrer as well
delete res.facet;
delete res.cfacet;
delete res.cfacet_str;
delete res.cfacet_path;
return res;
}

Expand Down
67 changes: 52 additions & 15 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@

.constant("logActions", {
"recordRead": "record/main", // read the main entity (record)
"recordUpdate": "record/main/update", // read the main entity (record)
"recordRelatedRead": "record/related", // secondary
"recordRelatedUpdate": "record/related/update", // secondary
"recordRelatedAggregate": "record/related/aggregate", // secondary
Expand All @@ -135,7 +136,7 @@
"preCreateAssociation": "pre-create/prefill/association", // read the association values to add new ones (record) has referrer
"preCreateAssociationSelected": "pre-create/prefill/association/disabled", // secondary
"preCopy": "pre-create/copy", // read the current data before copy (recordedit)
"recordeditDefault": "recordedit/default",
"recordeditDefault": "default",

"update": "update", // update entity (recordedit)
"preUpdate": "pre-update", // read entity to be updated (recordedit)
Expand All @@ -150,13 +151,20 @@
"recordsetFacet": "recordset/main/facet", // recordset main data read on changing facet (recordset)
"recordsetFacetDetails": "recordset/viewmore", // getting facet details in modal (recordset)
"recordsetFacetRead": "recordset/facet", // secondary
"recordsetFacetInit": "recordset/facet/init", // secondary (getting the rowname of preselected facets)
"recordsetFacetHistogram": "recordset/facet/histogram", // secondary (getting the histogrma buckets)

"recordDelete": "delete/record", // delete record (record)
"recordEditDelete": "delete/recordedit", // delete record (recordedit)
"recordsetDelete": "delete/recordset", // delete a row (recordset)
"recordRelatedDelete": "delete/recordset/related", // delete a row from related entities (record) has referrer
"recordRelatedDelete": "delete/record/related", // delete a row from related entities (record) has referrer

"export": "recordset/export"
"export": "export",

"viewerMain": "main",
"viewerAnnotation": "annotation",
"viewerComment": "comment",
"viewerAnatomy": "anatomy"

})

Expand All @@ -182,7 +190,7 @@
* @return {String}
*/
function getCatalogIDFromLocation() {
var hash = getLocationHash($window.location);
var hash = getLocationHash($window.location).hash;
return hash.split('/')[0].slice(1);
}

Expand All @@ -192,31 +200,35 @@
* TODO we might want to refactor the different places that are using this
* function, we should not keep parsing the same location
* @param {Object} location the $window.location
* @return {String} hash string
* @return {Object} with 'hash' and 'isQueryParameter'
*/
function getLocationHash(location) {
var hash = location.hash;
var hash = location.hash, isQueryParameter = false;
// allow ? to be used in place of #
if ((hash == '' || hash == undefined) && location.href.indexOf("?") !== -1) {
hash = "#" + location.href.substring(location.href.indexOf("?") + 1);
isQueryParameter = true;
}
return hash;
return {hash: hash, isQueryParameter: isQueryParameter};
}

/**
* @function
* @param {Object} location - location Object from the $window resource
* @desc
* Converts a chaise URI to an ermrest resource URI object.
* @returns {Object} an object that has 'ermrestURI', `ppid`, 'pcid', and `isQueryParameter`
* @throws {MalformedUriError} if table or catalog data are missing.
*/
function chaiseURItoErmrestURI(location) {
var tableMissing = messageMap.tableMissing,
catalogMissing = messageMap.catalogMissing;

var hash = getLocationHash(location),
var hashObj = getLocationHash(location),
ermrestUri = {},
catalogId;
catalogId, ppid, pcid;

var hash = hashObj.hash, isQueryParameter = hashObj.isQueryParameter;

// remove query params other than limit
if (hash.indexOf('?') !== -1) {
Expand All @@ -228,6 +240,12 @@
if (queries[i].indexOf("limit=") === 0) {
acceptedQueries.push(queries[i]);
}
if (queries[i].indexOf("pcid=") === 0) {
pcid = queries[i].split("=")[1];
}
if (queries[i].indexOf("ppid=") === 0) {
ppid = queries[i].split("=")[1];
}
}
if (acceptedQueries.length != 0) {
hash = hash + "?" + acceptedQueries.join("&");
Expand Down Expand Up @@ -319,7 +337,7 @@

var baseUri = chaiseConfig.ermrestLocation;
var path = '/catalog/' + catalogId + '/entity' + hash;
return baseUri + path;
return {ermrestUri: baseUri + path, ppid: ppid, pcid: pcid, isQueryParameter: isQueryParameter};
}

/**
Expand Down Expand Up @@ -348,10 +366,24 @@
} else {
appPath = ContextUtils.getValueFromContext(appContextMapping, context);
}

var url = chaiseBaseURL() + appPath + "/#" + location.catalog + "/" + location.path;
if (location.queryParamsString && (context.indexOf("compact") === 0)) {
var pcontext = [];
if ($rootScope.context) {
if ($rootScope.context.appName) {
pcontext.push("pcid=" + $rootScope.context.appName);
}
if ($rootScope.context.pageId) {
pcontext.push("ppid=" + $rootScope.context.pageId);
}
}
// TODO we might want to allow only certian query parameters
if (location.queryParamsString) {
url = url + "?" + location.queryParamsString;
}
if (pcontext.length > 0) {
url = url + (location.queryParamsString ? "&" : "?") + pcontext.join("&");
}
return url;
}

Expand All @@ -363,7 +395,7 @@
*/
function getQueryParams(location) {
var queryParams = {},
modifierPath = getLocationHash(location),
modifierPath = getLocationHash(location).hash,
q_parts, i;

if (modifierPath.indexOf("?") !== -1) {
Expand Down Expand Up @@ -403,7 +435,7 @@

// Then, parse the URL fragment id (aka, hash). Expected format:
// "#catalog_id/[schema_name:]table_name[/{attribute::op::value}{&attribute::op::value}*][@sort(column[::desc::])]"
var hash = getLocationHash(location);
var hash = getLocationHash(location).hash;
var uri = hash;
if (hash === undefined || hash == '' || hash.length == 1) {
return context;
Expand Down Expand Up @@ -761,7 +793,7 @@

// Takes path and creates full redirect links with catalogId
function createRedirectLinkFromPath(path){
var hash = getLocationHash($window.location);
var hash = getLocationHash($window.location).hash;
var catalogString = hash.slice(0, hash.search("/"));
return $window.location.origin + $window.location.pathname + catalogString + "/" + path;
}
Expand Down Expand Up @@ -836,6 +868,11 @@
return $window.location.origin + "/id/" + currCatalog + "/" + tuple.data.RID + (version ? version : "");
}

function removeParentContext(url) {
url = url.substring(0, url.lastIndexOf("?"));
$window.history.replaceState('', '', url);
}

return {
appNamefromUrlPathname: appNamefromUrlPathname,
appTagToURL: appTagToURL,
Expand All @@ -845,12 +882,12 @@
createRedirectLinkFromPath: createRedirectLinkFromPath,
fixedEncodeURIComponent: fixedEncodeURIComponent,
getCatalogIDFromLocation: getCatalogIDFromLocation,
getLocationHash: getLocationHash,
getQueryParams: getQueryParams,
isBrowserIE: isBrowserIE,
parseURLFragment: parseURLFragment,
parsedFilterToERMrestFilter: parsedFilterToERMrestFilter,
queryStringToJSON: queryStringToJSON,
removeParentContext: removeParentContext,
resolvePermalink: resolvePermalink,
setLocationChangeHandling: setLocationChangeHandling,
setOrigin: setOrigin
Expand Down
Loading

0 comments on commit 777febb

Please sign in to comment.