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
159aefff
Commit
159aefff
authored
Jan 24, 2017
by
chriseth
Committed by
GitHub
Jan 24, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #400 from ethereum/files-api
Implement the files API
parents
a7d01060
20ce7788
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
2 deletions
+122
-2
files.js
src/app/files.js
+111
-0
storage.js
src/app/storage.js
+11
-2
No files found.
src/app/files.js
0 → 100644
View file @
159aefff
'use strict'
var
EventManager
=
require
(
'../lib/eventManager'
)
function
Files
(
storage
)
{
var
event
=
new
EventManager
()
this
.
event
=
event
var
readonly
=
{}
this
.
exists
=
function
(
path
)
{
// NOTE: ignore the config file
if
(
path
===
'.browser-solidity.json'
)
{
return
false
}
return
this
.
isReadOnly
(
path
)
||
storage
.
exists
(
path
)
}
this
.
get
=
function
(
path
)
{
// NOTE: ignore the config file
if
(
path
===
'.browser-solidity.json'
)
{
return
null
}
return
readonly
[
path
]
||
storage
.
get
(
path
)
}
this
.
set
=
function
(
path
,
content
)
{
// NOTE: ignore the config file
if
(
path
===
'.browser-solidity.json'
)
{
return
false
}
if
(
!
this
.
isReadOnly
(
path
))
{
var
exists
=
storage
.
exists
(
path
)
if
(
!
storage
.
set
(
path
,
content
))
{
return
false
}
if
(
!
exists
)
{
event
.
trigger
(
'fileAdded'
,
[
path
,
false
])
}
else
{
event
.
trigger
(
'fileChanged'
,
[
path
])
}
return
true
}
return
false
}
this
.
addReadOnly
=
function
(
path
,
content
)
{
if
(
!
storage
.
exists
(
path
))
{
readonly
[
path
]
=
content
event
.
trigger
(
'fileAdded'
,
[
path
,
true
])
return
true
}
return
false
}
this
.
isReadOnly
=
function
(
path
)
{
return
!!
readonly
[
path
]
}
this
.
remove
=
function
(
path
)
{
if
(
!
this
.
exists
(
path
))
{
return
false
}
if
(
this
.
isReadOnly
(
path
))
{
readonly
[
path
]
=
undefined
}
else
{
if
(
!
storage
.
remove
(
path
))
{
return
false
}
}
event
.
trigger
(
'fileRemoved'
,
[
path
])
return
true
}
this
.
rename
=
function
(
oldPath
,
newPath
)
{
if
(
!
this
.
isReadOnly
(
oldPath
)
&&
storage
.
exists
(
oldPath
))
{
if
(
!
storage
.
rename
(
oldPath
,
newPath
))
{
return
false
}
event
.
trigger
(
'fileRenamed'
,
[
oldPath
,
newPath
])
return
true
}
return
false
}
this
.
list
=
function
()
{
var
files
=
{}
// add r/w files to the list
storage
.
keys
().
forEach
(
function
(
path
)
{
// NOTE: as a temporary measure do not show the config file
if
(
path
!==
'.browser-solidity.json'
)
{
files
[
path
]
=
false
}
})
// add r/o files to the list
Object
.
keys
(
readonly
).
forEach
(
function
(
path
)
{
files
[
path
]
=
true
})
return
files
}
}
module
.
exports
=
Files
src/app/storage.js
View file @
159aefff
...
...
@@ -10,7 +10,12 @@ function Storage () {
}
this
.
set
=
function
(
name
,
content
)
{
window
.
localStorage
.
setItem
(
'sol:'
+
name
,
content
)
try
{
window
.
localStorage
.
setItem
(
'sol:'
+
name
,
content
)
}
catch
(
exception
)
{
return
false
}
return
true
}
function
safeKeys
()
{
...
...
@@ -28,12 +33,16 @@ function Storage () {
this
.
remove
=
function
(
name
)
{
window
.
localStorage
.
removeItem
(
'sol:'
+
name
)
return
true
}
this
.
rename
=
function
(
originalName
,
newName
)
{
var
content
=
this
.
get
(
originalName
)
this
.
set
(
newName
,
content
)
if
(
!
this
.
set
(
newName
,
content
))
{
return
false
}
this
.
remove
(
originalName
)
return
true
}
this
.
loadFile
=
function
(
filename
,
content
)
{
...
...
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