From 20bad62a63e8dd76376c7f46a3719e3187f05d88 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Mon, 29 Jun 2020 18:50:47 +0200 Subject: [PATCH] read dear on '/' down --- src/app.js | 2 +- src/app/files/fileManager.js | 44 ++++++++++++++++++++++++++++----- src/app/tabs/test-tab.js | 19 +++++++------- src/app/tabs/testTab/testTab.js | 8 ++++-- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/app.js b/src/app.js index dd3e1b4d40..b530d31c15 100644 --- a/src/app.js +++ b/src/app.js @@ -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) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 3d36b1b7be..6d370c930e 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -38,7 +38,7 @@ const createError = (err) => { } class FileManager extends Plugin { - constructor (editor) { + constructor (editor, appManager) { super(profile) this.openedFiles = {} // list all opened files this.events = new EventEmitter() @@ -46,6 +46,7 @@ class FileManager extends Plugin { this._components = {} this._components.compilerImport = new CompilerImport() this._components.registry = globalRegistry + this.appManager = appManager this.init() } @@ -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 = [] @@ -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 { @@ -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 () { diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index d25ddf47ff..efade9dc01 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -485,8 +485,12 @@ module.exports = class TestTab extends ViewPlugin { return yo`Progress: ${ready} finished (of ${this.runningTestsNumber})` } - 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``)) + }) + } } render () { @@ -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} ` - this.allPaths().then((options) => { - console.log('options ', options, ' length is ', options.length) - options.forEach((path) => { - console.log('option ', path) - this.uiPathList.appendChild(yo``) - }) - }) - + this.uiPathList.appendChild(yo``) + if (this.testTabLogic.isRemixDActive()) this.uiPathList.appendChild(yo``) this.testsExecutionStopped.hidden = true this.testsExecutionStoppedError.hidden = true this.resultStatistics = this.createResultLabel() diff --git a/src/app/tabs/testTab/testTab.js b/src/app/tabs/testTab/testTab.js index 2a91552d7f..964b431337 100644 --- a/src/app/tabs/testTab/testTab.js +++ b/src/app/tabs/testTab/testTab.js @@ -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) {