Created
August 12, 2016 14:46
-
-
Save adufilie/914cfc15d6e56051f2222983d300e71b to your computer and use it in GitHub Desktop.
WeaveFlash script for listing tables used by current visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'weave.data.AttributeColumns.ReferencedColumn'; | |
import 'weave.api.data.ColumnMetadata'; | |
import 'weave.utils.ColumnUtils'; | |
import 'weave.data.DataSources.WeaveDataSource'; | |
import 'weave.utils.HierarchyUtils'; | |
import 'weave.compiler.Compiler'; | |
var listTables = function(){ | |
var ready = true; | |
var list = WeaveAPI.SessionManager.getLinkableDescendants(WeaveAPI.globalHashMap, ReferencedColumn).map(function(refcol){ | |
return Object( | |
'refcol', refcol, | |
'path', WeaveAPI.SessionManager.getPath(WeaveAPI.globalHashMap, refcol), | |
'dataSource', refcol.hasOwnProperty('getDataSource') ? refcol.getDataSource() : WeaveAPI.globalHashMap.getObject(refcol.dynamicColumnReference.internalObject.dataSourceName.value), | |
'metadata', refcol.hasOwnProperty('metadata') ? refcol.metadata.getSessionState() : ColumnMetadata.getAllMetadata(refcol) | |
); | |
}).filter(function(o){ return !!o.path }).sortOn('path').map(function(o){ | |
var toolName = o.path; | |
var colName = ColumnUtils.getTitle(o.refcol); | |
var tableName = WeaveAPI.globalHashMap.getName(o.dataSource); | |
if (o.refcol.hasOwnProperty('metadata') && o.metadata && typeof o.metadata == 'object') | |
{ | |
var id = o.metadata.weaveEntityId; | |
if (id && o.dataSource is WeaveDataSource) | |
{ | |
var cache = o.dataSource.entityCache; | |
var entity = cache.getEntity(id); | |
var branchInfo = entity && entity.parentIds && cache.getBranchInfo(entity.parentIds[0]); | |
tableName = branchInfo && branchInfo.title; | |
if (!branchInfo) | |
ready = false; | |
} | |
else if (o.metadata.dataTable) | |
tableName = o.metadata.dataTable; | |
} | |
else if (o.refcol.hasOwnProperty('dynamicColumnReference')) | |
{ | |
var xmlpath = o.refcol.dynamicColumnReference.internalObject.hierarchyPath.value; | |
var parentNode = HierarchyUtils.getLeafNodeFromPath(xmlpath, HierarchyUtils.getPathDepth(xmlpath) - 1); | |
tableName = parentNode ? parentNode.@title : '???'; | |
} | |
return `TABLE: {tableName}, COLUMN: {colName}, PATH: {Compiler.hasOwnProperty('stringify') ? Compiler.stringify(toolName) : JSON.stringify(toolName)}`; | |
}).join('\n'); | |
if (!ready) | |
{ | |
setTimeout(listTables, 200); | |
return 'Retrieving information from server...'; | |
} | |
else | |
trace(list); | |
}; | |
listTables(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listTables = () => { | |
var ready = true; | |
var list = WeaveAPI.SessionManager.getLinkableDescendants(WeaveAPI.globalHashMap, ReferencedColumn).map(refcol => { | |
refcol: refcol, | |
path: WeaveAPI.SessionManager.getPath(WeaveAPI.globalHashMap, refcol), | |
dataSource: refcol.getDataSource(), | |
metadata: refcol.metadata.getSessionState() | |
}).filter(o => !!o.path).sortOn('path').map(o => { | |
var toolName = o.path; | |
var colName = ColumnUtils.getTitle(o.refcol); | |
var tableName = o.refcol.dataSourceName.value; | |
if (o.metadata && typeof o.metadata == 'object') | |
{ | |
var id = o.metadata.weaveEntityId; | |
if (id && o.dataSource is WeaveDataSource) | |
{ | |
var cache = o.dataSource.entityCache; | |
var entity = cache.getEntity(id); | |
var branchInfo = entity && entity.parentIds && cache.getBranchInfo(entity.parentIds[0]); | |
tableName = branchInfo && branchInfo.title; | |
if (!branchInfo) | |
ready = false; | |
} | |
else if (o.metadata.dataTable) | |
tableName = o.metadata.dataTable; | |
} | |
return `TABLE: {tableName}, COLUMN: {colName}, PATH: {Compiler.stringify(toolName)}`; | |
}).join('\n'); | |
if (!ready) | |
{ | |
setTimeout(listTables, 200); | |
return 'Retrieving information from server...'; | |
} | |
else | |
trace(list); | |
}; | |
listTables(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment