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
03fafd23
Commit
03fafd23
authored
Feb 27, 2018
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add browser file tree
parent
59b683aa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
0 deletions
+130
-0
browser-files-tree.js
src/app/files/browser-files-tree.js
+130
-0
No files found.
src/app/files/browser-files-tree.js
0 → 100644
View file @
03fafd23
'use strict'
var
EventManager
=
require
(
'remix-lib'
).
EventManager
function
FilesTree
(
name
,
storage
)
{
var
self
=
this
var
event
=
new
EventManager
()
this
.
event
=
event
this
.
type
=
name
this
.
structFile
=
'.'
+
name
+
'.tree'
this
.
tree
=
{}
this
.
exists
=
function
(
path
,
cb
)
{
cb
(
null
,
this
.
_exists
(
path
))
}
function
updateRefs
(
path
,
type
)
{
var
split
=
path
.
split
(
'/'
)
// this should be unprefixed path
var
crawlpath
=
self
.
tree
split
.
forEach
((
pathPart
,
index
)
=>
{
if
(
!
crawlpath
[
pathPart
])
crawlpath
[
pathPart
]
=
{}
if
(
index
<
split
.
length
-
1
)
{
crawlpath
=
crawlpath
[
pathPart
]
}
else
if
(
type
===
'add'
)
{
crawlpath
[
pathPart
]
=
path
}
else
if
(
type
===
'remove'
&&
crawlpath
[
pathPart
])
{
delete
crawlpath
[
pathPart
]
}
})
storage
.
set
(
self
.
structFile
,
JSON
.
stringify
(
self
.
tree
))
}
this
.
_exists
=
function
(
path
)
{
var
unprefixedpath
=
this
.
removePrefix
(
path
)
return
storage
.
exists
(
unprefixedpath
)
}
this
.
init
=
function
(
cb
)
{
var
tree
=
storage
.
get
(
this
.
structFile
)
this
.
tree
=
tree
?
JSON
.
parse
(
tree
)
:
{}
if
(
cb
)
cb
()
}
this
.
get
=
function
(
path
,
cb
)
{
var
unprefixedpath
=
this
.
removePrefix
(
path
)
var
content
=
storage
.
get
(
unprefixedpath
)
if
(
cb
)
{
cb
(
null
,
content
)
}
return
content
}
this
.
set
=
function
(
path
,
content
)
{
var
unprefixedpath
=
this
.
removePrefix
(
path
)
updateRefs
(
unprefixedpath
,
'add'
)
var
exists
=
storage
.
exists
(
unprefixedpath
)
if
(
!
storage
.
set
(
unprefixedpath
,
content
))
{
return
false
}
if
(
!
exists
)
{
event
.
trigger
(
'fileAdded'
,
[
this
.
type
+
'/'
+
unprefixedpath
,
false
])
}
else
{
event
.
trigger
(
'fileChanged'
,
[
this
.
type
+
'/'
+
unprefixedpath
])
}
return
true
}
this
.
addReadOnly
=
function
(
path
,
content
)
{
return
this
.
set
(
path
,
content
)
}
this
.
isReadOnly
=
function
(
path
)
{
return
false
}
this
.
remove
=
function
(
path
)
{
var
unprefixedpath
=
this
.
removePrefix
(
path
)
updateRefs
(
unprefixedpath
,
'remove'
)
if
(
!
this
.
_exists
(
unprefixedpath
))
{
return
false
}
if
(
!
storage
.
remove
(
unprefixedpath
))
{
return
false
}
event
.
trigger
(
'fileRemoved'
,
[
this
.
type
+
'/'
+
unprefixedpath
])
return
true
}
this
.
rename
=
function
(
oldPath
,
newPath
,
isFolder
)
{
var
unprefixedoldPath
=
this
.
removePrefix
(
oldPath
)
var
unprefixednewPath
=
this
.
removePrefix
(
newPath
)
updateRefs
(
unprefixedoldPath
,
'remove'
)
updateRefs
(
unprefixednewPath
,
'add'
)
if
(
storage
.
exists
(
unprefixedoldPath
))
{
if
(
!
storage
.
rename
(
unprefixedoldPath
,
unprefixednewPath
))
{
return
false
}
event
.
trigger
(
'fileRenamed'
,
[
this
.
type
+
'/'
+
unprefixedoldPath
,
this
.
type
+
'/'
+
unprefixednewPath
,
isFolder
])
return
true
}
return
false
}
this
.
resolveDirectory
=
function
(
path
,
callback
)
{
var
self
=
this
if
(
path
[
0
]
===
'/'
)
path
=
path
.
substring
(
1
)
if
(
!
path
)
return
callback
(
null
,
{
[
self
.
type
]:
{
}
})
var
tree
=
{}
path
=
self
.
removePrefix
(
path
)
var
split
=
path
.
split
(
'/'
)
// this should be unprefixed path
var
crawlpath
=
self
.
tree
split
.
forEach
((
pathPart
,
index
)
=>
{
if
(
crawlpath
[
pathPart
])
crawlpath
=
crawlpath
[
pathPart
]
})
for
(
var
item
in
crawlpath
)
{
tree
[
item
]
=
{
isDirectory
:
typeof
crawlpath
[
item
]
!==
'string'
}
}
callback
(
null
,
tree
)
}
this
.
removePrefix
=
function
(
path
)
{
path
=
path
.
indexOf
(
this
.
type
)
===
0
?
path
.
replace
(
this
.
type
,
''
)
:
path
if
(
path
[
0
]
===
'/'
)
return
path
.
substring
(
1
)
return
path
}
}
module
.
exports
=
FilesTree
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