Skip to content

Commit

Permalink
read dear on '/' down
Browse files Browse the repository at this point in the history
  • Loading branch information
LianaHus authored and yann300 committed Jul 1, 2020
1 parent e9e9ff3 commit 20bad62
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
editor.event.register('requiringToSaveCurrentfile', () => fileManager.saveCurrentFile())

// ----------------- fileManager servive ----------------------------
const fileManager = new FileManager(editor)
const fileManager = new FileManager(editor, appManager)
registry.put({api: fileManager, name: 'filemanager'})

const blockchain = new Blockchain(registry.get('config').api)
Expand Down
44 changes: 38 additions & 6 deletions src/app/files/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ const createError = (err) => {
}

class FileManager extends Plugin {
constructor (editor) {
constructor (editor, appManager) {
super(profile)
this.openedFiles = {} // list all opened files
this.events = new EventEmitter()
this.editor = editor
this._components = {}
this._components.compilerImport = new CompilerImport()
this._components.registry = globalRegistry
this.appManager = appManager
this.init()
}

Expand Down Expand Up @@ -493,6 +494,36 @@ class FileManager extends Plugin {
return this._deps.filesProviders['browser']
}

// returns the list of directories inside path
dirList (path) {
const dirPaths = []
const collectList = (path) => {
return new Promise((resolve, reject) => {
if (this.isDirectory(path)) {
this.readdir(path).then((ls) => {
const promises = Object.keys(ls).map((item, index) => {
const root = (path.indexOf('/') === -1) ? path : path.substr(0, path.indexOf('/'))
const curPath = `${root}/${item}` // adding 'browser' or 'localhost'
if (ls[item].isDirectory && !dirPaths.includes(curPath)) {
dirPaths.push(curPath)
resolve(dirPaths)
}
return new Promise((resolve, reject) => { resolve() })
})
Promise.all(promises).then(() => { resolve(dirPaths) })
})
} else {
resolve(dirPaths)
}
})
}
return collectList(path)
}

isRemixDActive () {
return this.appManager.isActive('remixd')
}

allPaths () {
const dirPaths = []

Expand All @@ -501,12 +532,12 @@ class FileManager extends Plugin {
if (this.isDirectory(path)) {
if (!dirPaths.includes(path)) {
dirPaths.push(path)
console.log('adding .. ', path)
}

this.readdir(path).then((ls) => {
const promises = Object.keys(ls).map((item, index) => {
const curPath = `browser/${item}`
const root = (path.indexOf('/') === -1) ? path : path.substr(0, path.indexOf('/'))
const curPath = `${root}/${item}` // adding 'browser' or 'localhost'
if (ls[item].isDirectory) {
return findPaths(curPath)
} else {
Expand All @@ -521,9 +552,10 @@ class FileManager extends Plugin {
})
}

const br = findPaths('browser')
const lh = findPaths('localhost')
return Promise.all([br, lh])
const roots = []
roots.push(findPaths('browser'))
if (this.appManager.isActive('remixd')) roots.push(findPaths('localhost'))
return Promise.all(roots)
}

saveCurrentFile () {
Expand Down
19 changes: 9 additions & 10 deletions src/app/tabs/test-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,12 @@ module.exports = class TestTab extends ViewPlugin {
return yo`<span class='text-info h6'>Progress: ${ready} finished (of ${this.runningTestsNumber})</span>`
}

allPaths () {
return this.testTabLogic.allPaths()
updateDirList (e) {
if (e.keyCode === 191) {
this.testTabLogic.dirList(this._view.el.getElementsByClassName('custom-select')[0].value).then((options) => {
options.forEach((path) => this.uiPathList.appendChild(yo`<option>${path}</option>`))
})
}
}

render () {
Expand All @@ -505,18 +509,13 @@ module.exports = class TestTab extends ViewPlugin {
data-id="uiPathInput"
name="utPath"
style="background-image: var(--primary);"
onkeydown=${(e) => this.updateDirList(e)}
onchange=${(e) => this.updateCurrentPath(e)}/>
${this.uiPathList}
</div>
`
this.allPaths().then((options) => {
console.log('options ', options, ' length is ', options.length)
options.forEach((path) => {
console.log('option ', path)
this.uiPathList.appendChild(yo`<option>${path}</option>`)
})
})

this.uiPathList.appendChild(yo`<option>browser</option>`)
if (this.testTabLogic.isRemixDActive()) this.uiPathList.appendChild(yo`<option>localhost</option>`)
this.testsExecutionStopped.hidden = true
this.testsExecutionStoppedError.hidden = true
this.resultStatistics = this.createResultLabel()
Expand Down
8 changes: 6 additions & 2 deletions src/app/tabs/testTab/testTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class TestTabLogic {
})
}

allPaths () {
return this.fileManager.allPaths()
dirList (path) {
return this.fileManager.dirList(path)
}

isRemixDActive () {
return this.fileManager.isRemixDActive()
}

async getTests (cb) {
Expand Down

0 comments on commit 20bad62

Please sign in to comment.