Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
e401a1e4
Commit
e401a1e4
authored
May 19, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'standalone mode' 2: added possibility to choose the input file via a file input :)
parent
4ef05dd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
7 deletions
+56
-7
main.js
tinawebJS/main.js
+56
-7
No files found.
tinawebJS/main.js
View file @
e401a1e4
...
@@ -97,10 +97,61 @@ writeBrand(TW.branding)
...
@@ -97,10 +97,61 @@ writeBrand(TW.branding)
console
.
log
(
"Starting TWJS"
)
console
.
log
(
"Starting TWJS"
)
// choosing the input (WIP: currently refactoring for simpler handling)
// choosing the input
var
[
inFormat
,
inData
]
=
syncRemoteGraphData
()
// -------------------
// if page is being run locally ==> only possible source shall be via file input
if
(
window
.
location
.
protocol
==
'file:'
)
{
// POSS we could actually provide this local file chooser in all cases
var
graphFileInput
=
document
.
createElement
(
'input'
)
graphFileInput
.
id
=
'localgraphfile'
graphFileInput
.
type
=
'file'
graphFileInput
.
accept
=
'application/xml,application/gexf,application/json'
document
.
getElementById
(
'gexfs'
).
appendChild
(
graphFileInput
)
// NB file input will trigger mainStartGraph() when the user chooses something
graphFileInput
.
onchange
=
function
()
{
if
(
this
.
files
&&
this
.
files
[
0
])
{
console
.
log
(
this
.
files
[
0
])
let
clientLocalGraphFile
=
this
.
files
[
0
]
// determine the format
let
theFormat
if
(
/
\.(?:
gexf|xml
)
$/
.
test
(
clientLocalGraphFile
.
name
))
{
theFormat
=
'gexf'
}
else
if
(
/
\.
json$/
.
test
(
clientLocalGraphFile
.
name
))
{
theFormat
=
'json'
}
// retrieving the content
let
rdr
=
new
FileReader
()
rdr
.
onload
=
function
()
{
if
(
!
rdr
.
result
||
!
rdr
.
result
.
length
)
{
alert
(
'the selected file is not readable'
)
}
else
if
(
!
theFormat
)
{
alert
(
'unrecognized file format'
)
}
else
{
mainStartGraph
(
theFormat
,
rdr
.
result
)
}
}
rdr
.
readAsText
(
clientLocalGraphFile
)
}
}
}
// traditional cases: remote read from API or prepared server-side file
else
{
// NB it will use global urlParams and TW.settings to choose the source
var
[
inFormat
,
inData
]
=
syncRemoteGraphData
()
mainStartGraph
(
inFormat
,
inData
)
}
mainStartGraph
(
inFormat
,
inData
)
// === [ / what to do at start ] === //
// === [ / what to do at start ] === //
...
@@ -111,10 +162,8 @@ function syncRemoteGraphData () {
...
@@ -111,10 +162,8 @@ function syncRemoteGraphData () {
var
inData
;
// = {nodes: [....], edges: [....], cats:...}
var
inData
;
// = {nodes: [....], edges: [....], cats:...}
// case (1) read from DB => one ajax to api eg /services/api/graph?q=filters...
// case (1) read from DB => one ajax to api eg /services/api/graph?q=filters...
// this one is the API case
// sourcemode == "api"
if
(
getUrlParam
.
type
)
{
if
(
getUrlParam
.
type
)
{
console
.
warn
(
"input case: @type [future: @mode=api], using TW.bridge"
)
console
.
warn
(
"input case: @type [future: @
source
mode=api], using TW.bridge"
)
// the only API format, cf. inData
// the only API format, cf. inData
inFormat
=
'json'
inFormat
=
'json'
...
@@ -223,7 +272,7 @@ function syncRemoteGraphData () {
...
@@ -223,7 +272,7 @@ function syncRemoteGraphData () {
// case (2) gexf => in params or in preRes db.json, then 2nd ajax for a gexf file => covered here
// case (2) gexf => in params or in preRes db.json, then 2nd ajax for a gexf file => covered here
// sourcemode == "serverfile"
// sourcemode == "serverfile"
else
{
else
{
console
.
warn
(
"input case: @mode=db.json or @file=... [future: @mode=serverfile], using server's gexf(s)"
)
console
.
warn
(
"input case: @mode=db.json or @file=... [future: @
source
mode=serverfile], using server's gexf(s)"
)
// subcases:
// subcases:
// -> gexf file path is already specified in TW.mainfile
// -> gexf file path is already specified in TW.mainfile
// -> gexf file path is in the urlparam @file
// -> gexf file path is in the urlparam @file
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment