From e9e9ff36e28f613b4f1304c29b2cf333933598b9 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 25 Jun 2020 17:23:22 +0200 Subject: [PATCH] generate the list of paths --- src/app/files/fileManager.js | 33 +++++++++++++++++++++++++++++++++ src/app/files/fileProvider.js | 2 +- src/app/tabs/test-tab.js | 14 ++++++++------ src/app/tabs/testTab/testTab.js | 5 +++++ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 6699179c06..3d36b1b7be 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -493,6 +493,39 @@ class FileManager extends Plugin { return this._deps.filesProviders['browser'] } + allPaths () { + const dirPaths = [] + + const findPaths = (path) => { + return new Promise((resolve, reject) => { + 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}` + if (ls[item].isDirectory) { + return findPaths(curPath) + } else { + return new Promise((resolve, reject) => { resolve() }) + } + }) + Promise.all(promises).then(() => { resolve(dirPaths) }) + }) + } else { + resolve(dirPaths) + } + }) + } + + const br = findPaths('browser') + const lh = findPaths('localhost') + return Promise.all([br, lh]) + } + saveCurrentFile () { var currentFile = this._deps.config.get('currentFile') if (currentFile && this.editor.current()) { diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index 4aaae8b637..ac6d1887b4 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -226,7 +226,7 @@ class FileProvider { if (files) { files.forEach(element => { const absPath = (path === '/' ? '' : path) + '/' + element - ret[absPath.indexOf('/') === 0 ? absPath.replace('/', '') : absPath] = { isDirectory: window.remixFileSystem.statSync(absPath).isDirectory() } + ret[absPath.indexOf('/') === 0 ? absPath.substr(1, absPath.length) : absPath] = { isDirectory: window.remixFileSystem.statSync(absPath).isDirectory() } // ^ ret does not accept path starting with '/' }) } diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index 0bec6aaa8f..d25ddf47ff 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -486,8 +486,7 @@ module.exports = class TestTab extends ViewPlugin { } allPaths () { - const paths = ['browser', 'browser/test'] - return paths + return this.testTabLogic.allPaths() } render () { @@ -510,9 +509,12 @@ module.exports = class TestTab extends ViewPlugin { ${this.uiPathList} ` - let options = ['browser', 'browser/test'] // this.allPaths() - options.forEach((path) => { - this.uiPathList.appendChild(yo``) + this.allPaths().then((options) => { + console.log('options ', options, ' length is ', options.length) + options.forEach((path) => { + console.log('option ', path) + this.uiPathList.appendChild(yo``) + }) }) this.testsExecutionStopped.hidden = true @@ -523,7 +525,7 @@ module.exports = class TestTab extends ViewPlugin {

Test your smart contract in Solidity.

-

Click on "Generate" to generate a sample test file in.

+

Click on "Generate" to generate a sample test file in a:

${availablePaths}
diff --git a/src/app/tabs/testTab/testTab.js b/src/app/tabs/testTab/testTab.js index 3181794ba3..2a91552d7f 100644 --- a/src/app/tabs/testTab/testTab.js +++ b/src/app/tabs/testTab/testTab.js @@ -1,6 +1,7 @@ const helper = require('../../../lib/helper.js') const modalDialogCustom = require('../../ui/modal-dialog-custom') const remixPath = require('path') + class TestTabLogic { constructor (fileManager) { @@ -31,6 +32,10 @@ class TestTabLogic { }) } + allPaths () { + return this.fileManager.allPaths() + } + async getTests (cb) { if (!this.currentPath) return cb(null, []) const provider = this.fileManager.fileProviderOf(this.currentPath)