Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
68d4a563
Commit
68d4a563
authored
Dec 14, 2017
by
serapath
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapt files listAsTree(path, level)
parent
0954680d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
28 deletions
+96
-28
browser-files.js
src/app/files/browser-files.js
+67
-26
shared-folder.js
src/app/files/shared-folder.js
+29
-2
No files found.
src/app/files/browser-files.js
View file @
68d4a563
...
...
@@ -7,6 +7,7 @@ function Files (storage) {
this
.
event
=
event
var
readonly
=
{}
this
.
type
=
'browser'
this
.
filesTree
=
null
this
.
exists
=
function
(
path
)
{
var
unprefixedpath
=
this
.
removePrefix
(
path
)
...
...
@@ -19,7 +20,10 @@ function Files (storage) {
}
this
.
init
=
function
(
cb
)
{
cb
()
listAsTree
(
this
,
this
.
list
(),
(
error
,
tree
)
=>
{
this
.
filesTree
=
tree
if
(
cb
)
cb
(
error
)
})
}
this
.
get
=
function
(
path
,
cb
)
{
...
...
@@ -49,6 +53,7 @@ function Files (storage) {
return
false
}
if
(
!
exists
)
{
this
.
init
()
event
.
trigger
(
'fileAdded'
,
[
this
.
type
+
'/'
+
unprefixedpath
,
false
])
}
else
{
event
.
trigger
(
'fileChanged'
,
[
this
.
type
+
'/'
+
unprefixedpath
])
...
...
@@ -63,6 +68,7 @@ function Files (storage) {
var
unprefixedpath
=
this
.
removePrefix
(
path
)
if
(
!
storage
.
exists
(
unprefixedpath
))
{
readonly
[
unprefixedpath
]
=
content
this
.
init
()
event
.
trigger
(
'fileAdded'
,
[
this
.
type
+
'/'
+
unprefixedpath
,
true
])
return
true
}
...
...
@@ -88,6 +94,7 @@ function Files (storage) {
return
false
}
}
this
.
init
()
event
.
trigger
(
'fileRemoved'
,
[
this
.
type
+
'/'
+
unprefixedpath
])
return
true
}
...
...
@@ -99,6 +106,7 @@ function Files (storage) {
if
(
!
storage
.
rename
(
unprefixedoldPath
,
unprefixednewPath
))
{
return
false
}
this
.
init
()
event
.
trigger
(
'fileRenamed'
,
[
this
.
type
+
'/'
+
unprefixedoldPath
,
this
.
type
+
'/'
+
unprefixednewPath
,
isFolder
])
return
true
}
...
...
@@ -140,33 +148,22 @@ function Files (storage) {
// }
// }
//
this
.
listAsTree
=
function
()
{
function
hashmapize
(
obj
,
path
,
val
)
{
var
nodes
=
path
.
split
(
'/'
)
var
i
=
0
for
(;
i
<
nodes
.
length
-
1
;
i
++
)
{
var
node
=
nodes
[
i
]
if
(
obj
[
node
]
===
undefined
)
{
obj
[
node
]
=
{}
}
obj
=
obj
[
node
]
this
.
listAsTree
=
function
(
path
,
level
)
{
var
nodes
=
path
?
path
.
split
(
'/'
)
:
[]
var
tree
=
this
.
filesTree
try
{
while
(
nodes
.
length
)
{
var
key
=
nodes
.
shift
()
if
(
key
)
tree
=
tree
[
key
]
}
obj
[
nodes
[
i
]]
=
val
}
catch
(
e
)
{
tree
=
{}
}
if
(
level
)
{
var
leveltree
=
{}
build
(
tree
,
level
,
leveltree
)
tree
=
leveltree
}
var
tree
=
{}
var
self
=
this
// This does not include '.remix.config', because it is filtered
// inside list().
Object
.
keys
(
this
.
list
()).
forEach
(
function
(
path
)
{
hashmapize
(
tree
,
path
,
{
'/readonly'
:
self
.
isReadOnly
(
path
),
'/content'
:
self
.
get
(
path
)
})
})
return
tree
}
...
...
@@ -174,6 +171,50 @@ function Files (storage) {
if
(
this
.
exists
(
'.browser-solidity.json'
))
{
this
.
rename
(
'.browser-solidity.json'
,
'.remix.config'
)
}
this
.
init
()
}
module
.
exports
=
Files
function
build
(
tree
,
level
,
leveltree
)
{
if
(
!
level
)
return
Object
.
keys
(
tree
).
forEach
(
key
=>
{
var
value
=
tree
[
key
]
var
more
=
value
===
Object
(
value
)
if
(
more
)
{
leveltree
[
key
]
=
{}
build
(
value
,
level
-
1
,
leveltree
[
key
])
}
else
leveltree
[
key
]
=
value
})
}
function
listAsTree
(
self
,
filesList
,
callback
)
{
function
hashmapize
(
obj
,
path
,
val
)
{
var
nodes
=
path
.
split
(
'/'
)
var
i
=
0
for
(;
i
<
nodes
.
length
-
1
;
i
++
)
{
var
node
=
nodes
[
i
]
if
(
obj
[
node
]
===
undefined
)
{
obj
[
node
]
=
{}
}
obj
=
obj
[
node
]
}
obj
[
nodes
[
i
]]
=
val
}
var
tree
=
{}
// This does not include '.remix.config', because it is filtered
// inside list().
Object
.
keys
(
filesList
).
forEach
(
function
(
path
)
{
hashmapize
(
tree
,
path
,
{
'/readonly'
:
self
.
isReadOnly
(
path
),
'/content'
:
self
.
get
(
path
)
})
})
callback
(
null
,
tree
)
}
src/app/files/shared-folder.js
View file @
68d4a563
...
...
@@ -138,8 +138,23 @@ class SharedFolder {
return
this
.
files
}
listAsTree
()
{
return
this
.
filesTree
listAsTree
(
path
,
level
)
{
var
nodes
=
path
?
path
.
split
(
'/'
)
:
[]
var
tree
=
this
.
filesTree
try
{
while
(
nodes
.
length
)
{
var
key
=
nodes
.
shift
()
if
(
key
)
tree
=
tree
[
key
]
}
}
catch
(
e
)
{
tree
=
{}
}
if
(
level
)
{
var
leveltree
=
{}
build
(
tree
,
level
,
leveltree
)
tree
=
leveltree
}
return
tree
}
removePrefix
(
path
)
{
...
...
@@ -159,6 +174,18 @@ class SharedFolder {
// }
// }
//
function
build
(
tree
,
level
,
leveltree
)
{
if
(
!
level
)
return
Object
.
keys
(
tree
).
forEach
(
key
=>
{
var
value
=
tree
[
key
]
var
more
=
value
===
Object
(
value
)
if
(
more
)
{
leveltree
[
key
]
=
{}
build
(
value
,
level
-
1
,
leveltree
[
key
])
}
else
leveltree
[
key
]
=
value
})
}
function
listAsTree
(
self
,
filesList
,
callback
)
{
function
hashmapize
(
obj
,
path
,
val
)
{
var
nodes
=
path
.
split
(
'/'
)
...
...
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