Commit 9603a31f authored by Romain Loth's avatar Romain Loth

project menu: use unique graph file identifiers and better labels

this allows to fix problems where db details from conf were not unique and only the last one was used
parent cd62bc11
...@@ -1250,8 +1250,7 @@ function resetTabs(activetypes, dbconf) { ...@@ -1250,8 +1250,7 @@ function resetTabs(activetypes, dbconf) {
} }
function jsActionOnGexfSelector(graphBasename){ function openGraph(graphPath){
let graphPath = TW.gmenuPaths[graphBasename] || graphBasename+".gexf"
let serverPrefix = '' let serverPrefix = ''
var pathcomponents = window.location.pathname.split('/') var pathcomponents = window.location.pathname.split('/')
for (var i in pathcomponents) { for (var i in pathcomponents) {
...@@ -1266,6 +1265,6 @@ function jsActionOnGexfSelector(graphBasename){ ...@@ -1266,6 +1265,6 @@ function jsActionOnGexfSelector(graphBasename){
TW.File = graphPath TW.File = graphPath
mainStartGraph(newDataRes["format"], newDataRes["data"], TW.File, TW.instance) mainStartGraph(newDataRes["format"], newDataRes["data"], TW.File, TW.instance)
writeLabel(graphBasename) writeLabel(graphPathToLabel(graphPath))
} }
//============================= </OTHER ACTIONS > =============================// //============================= </OTHER ACTIONS > =============================//
...@@ -80,7 +80,7 @@ else { ...@@ -80,7 +80,7 @@ else {
try { try {
// we'll first retrieve the menu of available sources in db.json, // we'll first retrieve the menu of available sources in db.json,
// then get the real data in a second ajax via API or server file // then get the real data in a second ajax via API or server file
[TW.gmenuPaths, TW.gmenuInfos, TW.File] = readMenu(TW.conf.paths.sourceMenu) [TW.gmenuInfos, TW.File] = readMenu(TW.conf.paths.sourceMenu)
// NB: this menu used to be a file list for only one sourcemode // NB: this menu used to be a file list for only one sourcemode
// but now also contains settings for nodetypes and for // but now also contains settings for nodetypes and for
...@@ -236,10 +236,10 @@ function syncRemoteGraphData () { ...@@ -236,10 +236,10 @@ function syncRemoteGraphData () {
console.log("using entire FILEMENU TW.conf.paths.sourceMenu") console.log("using entire FILEMENU TW.conf.paths.sourceMenu")
// chooser menu // chooser menu
var files_selector = '<select onchange="jsActionOnGexfSelector(this.value);">' var files_selector = '<select onchange="openGraph(this.options[this.selectedIndex].dataset.fullpath)">'
for (let shortname in TW.gmenuPaths) { for (let fullPath in TW.gmenuInfos) {
let fullPath = TW.gmenuPaths[shortname] let shortname = graphPathToLabel(fullPath)
files_selector += '<option>'+shortname+'</option>' files_selector += `<option data-fullpath="${fullPath}">`+shortname+'</option>'
} }
files_selector += "</select>" files_selector += "</select>"
$("#network").html(files_selector) $("#network").html(files_selector)
...@@ -264,7 +264,7 @@ function syncRemoteGraphData () { ...@@ -264,7 +264,7 @@ function syncRemoteGraphData () {
inData = finalRes["data"] inData = finalRes["data"]
inFormat = finalRes["format"] inFormat = finalRes["format"]
inConfKey = TW.File inConfKey = TW.File
mapLabel = TW.File mapLabel = graphPathToLabel(TW.File)
if (TW.conf.debug.logFetchers) { if (TW.conf.debug.logFetchers) {
console.warn('@TW.File', finalRes["OK"], TW.File) console.warn('@TW.File', finalRes["OK"], TW.File)
......
...@@ -109,6 +109,14 @@ TW.resetGraph = function() { ...@@ -109,6 +109,14 @@ TW.resetGraph = function() {
// remaining global vars will be reset by new graph mainStartGraph // remaining global vars will be reset by new graph mainStartGraph
} }
// create more human-readable graph labels for the menu
// data/project/coolgraph.gexf ==> "project: coolgraph"
function graphPathToLabel(fullPath) {
return fullPath.replace(
/^(?:data\/)?([^/]+)\/(.*)(?:\.(?:gexf|json))?/,
"$1: $2"
)
}
// read all sources' detailed confs // read all sources' detailed confs
// -> list of source paths available // -> list of source paths available
...@@ -156,39 +164,37 @@ function readMenu(infofile) { ...@@ -156,39 +164,37 @@ function readMenu(infofile) {
first_path = first_dir+"/"+first_file first_path = first_dir+"/"+first_file
// 2 - process all the paths and associated confs // 2 - process all the paths and associated confs
let paths = {}
let details = {} let details = {}
for( var path in preRES.data ) { for( var path in preRES.data ) {
var theGraphs = preRES.data[path]["graphs"] var theGraphs = preRES.data[path]["graphs"]
for(var aGraph in theGraphs) { for(var aGraph in theGraphs) {
var graphBasename = aGraph.replace(/\.gexf$/, "") // more human-readable in the menu let fullPath = path+"/"+aGraph
paths[graphBasename] = path+"/"+aGraph
// ex : "RiskV2PageRank1000.gexf":data/AXA/RiskV2PageRank1000.gexf // ex : "RiskV2PageRank1000.gexf":data/AXA/RiskV2PageRank1000.gexf
// (we assume there's no duplicate basenames) // (we assume there's no duplicate basenames)
if (TW.conf.debug.logSettings) if (TW.conf.debug.logSettings)
console.log("db conf entry: "+graphBasename) console.log("db conf entry: " + fullPath)
// for associated LocalDB php queries: CSV (or CortextDBs sql) // for associated LocalDB php queries: CSV (or CortextDBs sql)
if (theGraphs[aGraph]) { if (theGraphs[aGraph]) {
let gSrcEntry = theGraphs[aGraph] let gSrcEntry = theGraphs[aGraph]
details[path+"/"+aGraph] = new Array(2) details[fullPath] = new Array(2)
if (gSrcEntry.node0) { if (gSrcEntry.node0) {
details[path+"/"+aGraph][0] = gSrcEntry.node0 details[fullPath][0] = gSrcEntry.node0
} }
if (gSrcEntry.node1) { if (gSrcEntry.node1) {
details[path+"/"+aGraph][1] = gSrcEntry.node1 details[fullPath][1] = gSrcEntry.node1
} }
} }
else { else {
details[path+"/"+aGraph] = null details[fullPath] = null
} }
} }
} }
return [paths, details, first_path] return [details, first_path]
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment