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) {
}
function jsActionOnGexfSelector(graphBasename){
let graphPath = TW.gmenuPaths[graphBasename] || graphBasename+".gexf"
function openGraph(graphPath){
let serverPrefix = ''
var pathcomponents = window.location.pathname.split('/')
for (var i in pathcomponents) {
......@@ -1266,6 +1265,6 @@ function jsActionOnGexfSelector(graphBasename){
TW.File = graphPath
mainStartGraph(newDataRes["format"], newDataRes["data"], TW.File, TW.instance)
writeLabel(graphBasename)
writeLabel(graphPathToLabel(graphPath))
}
//============================= </OTHER ACTIONS > =============================//
......@@ -80,7 +80,7 @@ else {
try {
// 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
[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
// but now also contains settings for nodetypes and for
......@@ -236,10 +236,10 @@ function syncRemoteGraphData () {
console.log("using entire FILEMENU TW.conf.paths.sourceMenu")
// chooser menu
var files_selector = '<select onchange="jsActionOnGexfSelector(this.value);">'
for (let shortname in TW.gmenuPaths) {
let fullPath = TW.gmenuPaths[shortname]
files_selector += '<option>'+shortname+'</option>'
var files_selector = '<select onchange="openGraph(this.options[this.selectedIndex].dataset.fullpath)">'
for (let fullPath in TW.gmenuInfos) {
let shortname = graphPathToLabel(fullPath)
files_selector += `<option data-fullpath="${fullPath}">`+shortname+'</option>'
}
files_selector += "</select>"
$("#network").html(files_selector)
......@@ -264,7 +264,7 @@ function syncRemoteGraphData () {
inData = finalRes["data"]
inFormat = finalRes["format"]
inConfKey = TW.File
mapLabel = TW.File
mapLabel = graphPathToLabel(TW.File)
if (TW.conf.debug.logFetchers) {
console.warn('@TW.File', finalRes["OK"], TW.File)
......
......@@ -109,6 +109,14 @@ TW.resetGraph = function() {
// 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
// -> list of source paths available
......@@ -156,39 +164,37 @@ function readMenu(infofile) {
first_path = first_dir+"/"+first_file
// 2 - process all the paths and associated confs
let paths = {}
let details = {}
for( var path in preRES.data ) {
var theGraphs = preRES.data[path]["graphs"]
for(var aGraph in theGraphs) {
var graphBasename = aGraph.replace(/\.gexf$/, "") // more human-readable in the menu
paths[graphBasename] = path+"/"+aGraph
let fullPath = path+"/"+aGraph
// ex : "RiskV2PageRank1000.gexf":data/AXA/RiskV2PageRank1000.gexf
// (we assume there's no duplicate basenames)
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)
if (theGraphs[aGraph]) {
let gSrcEntry = theGraphs[aGraph]
details[path+"/"+aGraph] = new Array(2)
details[fullPath] = new Array(2)
if (gSrcEntry.node0) {
details[path+"/"+aGraph][0] = gSrcEntry.node0
details[fullPath][0] = gSrcEntry.node0
}
if (gSrcEntry.node1) {
details[path+"/"+aGraph][1] = gSrcEntry.node1
details[fullPath][1] = gSrcEntry.node1
}
}
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