Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
XRF-App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabio Proietti
XRF-App
Commits
f43f9cd1
Commit
f43f9cd1
authored
7 years ago
by
Laura Cappelli
Browse files
Options
Downloads
Patches
Plain Diff
Prova eliminazione file .js
parent
cef4de16
No related branches found
Branches containing commit
No related tags found
Loading
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
loaddir.js
+0
-172
0 additions, 172 deletions
loaddir.js
start.js
+0
-779
0 additions, 779 deletions
start.js
with
0 additions
and
951 deletions
loaddir.js
deleted
100644 → 0
+
0
−
172
View file @
cef4de16
//funzione che definisce tutti gli elementi responsabili dell'apertura di un file.
//Sono definiti quindi l'albero e il bottone per l'importazione da locale
function
setImportFile
()
{
//genero e leggo il contenuto della directory "filesystem"
var
jsonResponse
;
var
xmlListingFile
=
new
XMLHttpRequest
();
xmlListingFile
.
open
(
"
GET
"
,
"
https://baltig.infn.it/api/v4/projects/819/repository/tree?recursive=1&path=XRF-File-System
"
,
false
);
xmlListingFile
.
onreadystatechange
=
function
()
{
if
(
xmlListingFile
.
readyState
===
4
)
{
if
(
xmlListingFile
.
status
===
200
)
{
jsonResponse
=
JSON
.
parse
(
xmlListingFile
.
responseText
);
}
}
};
xmlListingFile
.
send
(
null
);
//ora genero l'albero e definisco l'evento in caso di selezione di un nodo
$
(
'
#FileTreeview
'
).
treeview
({
data
:
generateTree
(
jsonResponse
)
});
$
(
'
#FileTreeview
'
).
on
(
'
nodeSelected
'
,
function
(
e
,
node
)
{
if
(
node
[
'
url
'
]
!=
undefined
)
{
openFileFromServer
(
node
[
'
url
'
]);
}
});
//bottone per l'importazione locale
var
fileInputButton
=
document
.
getElementById
(
'
myImport
'
);
fileInputButton
.
onchange
=
function
()
{
var
fileName
=
fileInputButton
.
files
[
0
];
var
readerObject
=
new
FileReader
();
readerObject
.
readAsBinaryString
(
fileName
);
readerObject
.
onload
=
function
()
{
var
fileString
=
readerObject
.
result
;
readData
(
fileString
);
};
};
}
//funzione che genera automaticamente l'albero
function
generateTree
(
jsonDoc
)
{
var
tree
=
[{
text
:
"
XRF-File-System
"
,
nodes
:
[]
}];
//scorro ogni elemento dell'albero
for
(
var
i
=
0
;
i
<
jsonDoc
.
length
;
i
++
)
{
if
(
jsonDoc
[
i
].
type
==
"
tree
"
)
{
var
Folder
=
{
text
:
jsonDoc
[
i
].
name
,
relativePath
:
jsonDoc
[
i
].
path
,
nodes
:
[]
};
insertOBJinFS
(
Folder
,
tree
);
}
else
{
var
File
=
{
text
:
jsonDoc
[
i
].
name
,
relativePath
:
jsonDoc
[
i
].
path
,
icon
:
"
glyphicon glyphicon-file
"
,
selectedIcon
:
"
glyphicon glyphicon-file
"
,
url
:
jsonDoc
[
i
].
path
};
//inserisco il file nella giusta posizione
insertOBJinFS
(
File
,
tree
);
}
}
return
tree
;
}
//funzione che posiziona l'oggetto passato in input nell'albero
function
insertOBJinFS
(
objfs
,
tree
)
{
//tree[0].nodes.push(objfs);
var
parentPath
=
objfs
.
relativePath
.
slice
(
0
,
objfs
.
relativePath
.
lastIndexOf
(
"
/
"
));
//se l'oggetto è figlio della radice lo colloco subito
if
(
parentPath
==
tree
[
0
].
text
)
{
tree
[
0
].
nodes
.
push
(
objfs
);
}
else
{
//ricavo la profondità e posiziono l'oggetto
var
splitPath
=
parentPath
.
split
(
"
/
"
);
var
depth
=
splitPath
.
length
;
switch
(
depth
)
{
case
2
:
var
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
];
for
(
var
i
=
0
;
i
<
tree
[
0
].
nodes
.
length
;
i
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
relativePath
)
{
tree
[
0
].
nodes
[
i
].
nodes
.
push
(
objfs
);
break
;
}
}
break
;
case
3
:
var
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
];
for
(
var
i
=
0
;
i
<
tree
[
0
].
nodes
.
length
;
i
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
relativePath
)
{
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
]
+
"
/
"
+
splitPath
[
2
];
for
(
var
j
=
0
;
j
<
tree
[
0
].
nodes
[
i
].
nodes
.
length
;
j
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
relativePath
)
{
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
.
push
(
objfs
);
break
;
}
}
break
;
}
}
break
;
case
4
:
var
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
];
for
(
var
i
=
0
;
i
<
tree
[
0
].
nodes
.
length
;
i
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
relativePath
)
{
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
]
+
"
/
"
+
splitPath
[
2
];
for
(
var
j
=
0
;
j
<
tree
[
0
].
nodes
[
i
].
nodes
.
length
;
j
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
relativePath
)
{
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
]
+
"
/
"
+
splitPath
[
2
]
+
"
/
"
+
splitPath
[
3
];
for
(
var
k
=
0
;
k
<
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
.
length
;
k
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
[
k
].
relativePath
)
{
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
[
k
].
nodes
.
push
(
objfs
);
break
;
}
}
break
;
}
}
break
;
}
}
break
;
case
5
:
var
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
];
for
(
var
i
=
0
;
i
<
tree
[
0
].
nodes
.
length
;
i
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
relativePath
)
{
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
]
+
"
/
"
+
splitPath
[
2
];
for
(
var
j
=
0
;
j
<
tree
[
0
].
nodes
[
i
].
nodes
.
length
;
j
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
relativePath
)
{
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
]
+
"
/
"
+
splitPath
[
2
]
+
"
/
"
+
splitPath
[
3
];
for
(
var
k
=
0
;
k
<
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
.
length
;
k
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
[
k
].
relativePath
)
{
partialParentPath
=
splitPath
[
0
]
+
"
/
"
+
splitPath
[
1
]
+
"
/
"
+
splitPath
[
2
]
+
"
/
"
+
splitPath
[
3
]
+
"
/
"
+
splitPath
[
4
];
for
(
var
l
=
0
;
l
<
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
[
k
].
nodes
.
length
;
l
++
)
{
if
(
partialParentPath
==
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
[
k
].
nodes
[
l
].
relativePath
)
{
tree
[
0
].
nodes
[
i
].
nodes
[
j
].
nodes
[
k
].
nodes
[
l
].
nodes
.
push
(
objfs
);
break
;
}
}
break
;
}
}
break
;
}
}
break
;
}
}
break
;
}
}
}
//funzione che dato l'url di un file, lo apre e lo legge passandone il contenuto
//alla funzione readData(). Questa funzione è invocata quando viene selezionato
//un file dall'albero
function
openFileFromServer
(
url
)
{
console
.
log
(
"
Try to open
"
+
url
.
slice
(
url
.
lastIndexOf
(
"
/
"
)
+
1
,
url
.
length
));
url
=
"
https://baltig.infn.it/api/v4/projects/819/repository/files/
"
+
encodeURIComponent
(
url
)
+
"
?ref=master
"
;
var
jsonContentFile
=
new
XMLHttpRequest
();
jsonContentFile
.
open
(
"
GET
"
,
url
,
false
);
jsonContentFile
.
onreadystatechange
=
function
()
{
if
(
jsonContentFile
.
readyState
===
4
)
{
if
(
jsonContentFile
.
status
===
200
)
{
var
jsonResponse
=
jsonContentFile
.
responseText
;
var
startPoint
=
jsonResponse
.
indexOf
(
"
content
"
)
+
10
;
var
endPoint
=
jsonResponse
.
indexOf
(
"
\"
, :ref
"
);
readData
(
atob
(
jsonResponse
.
slice
(
startPoint
,
endPoint
)));
}
}
};
jsonContentFile
.
send
(
null
);
}
This diff is collapsed.
Click to expand it.
start.js
deleted
100644 → 0
+
0
−
779
View file @
cef4de16
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment