Changed Set & exists api to async

pull/262/head
ioedeveloper 4 years ago committed by yann300
parent ae7b140edd
commit 93500ced2e
  1. 13
      src/app/files/file-explorer.js
  2. 2
      src/app/files/fileProvider.js
  3. 33
      src/app/files/remixDProvider.js
  4. 1
      src/app/ui/TreeView.js

@ -102,9 +102,9 @@ function fileExplorer (localRegistry, files, menuItems) {
function fileAdded (filepath) {
self.ensureRoot(() => {
var folderpath = filepath.split('/').slice(0, -1).join('/')
var currentTree = self.treeView.nodeAt(folderpath)
const folderpath = filepath.split('/').slice(0, -1).join('/')
const currentTree = self.treeView.nodeAt(folderpath)
if (currentTree && self.treeView.isExpanded(folderpath)) {
self.files.resolveDirectory(folderpath, (error, fileTree) => {
if (error) console.error(error)
@ -130,8 +130,11 @@ function fileExplorer (localRegistry, files, menuItems) {
function folderAdded (folderpath) {
self.ensureRoot(() => {
console.log('called: ensureRoot')
folderpath = folderpath.split('/').slice(0, -1).join('/')
console.log('folderpath: ', folderpath)
self.files.resolveDirectory(folderpath, (error, fileTree) => {
console.log('fileTree: ', fileTree)
if (error) console.error(error)
if (!fileTree) return
fileTree = normalize(folderpath, fileTree)
@ -435,12 +438,12 @@ fileExplorer.prototype.uploadFile = function (event) {
let files = this.files
function loadFile () {
var fileReader = new FileReader()
fileReader.onload = function (event) {
fileReader.onload = async function (event) {
if (helper.checkSpecialChars(file.name)) {
modalDialogCustom.alert('Special characters are not allowed')
return
}
var success = files.set(name, event.target.result)
var success = await files.set(name, event.target.result)
if (!success) {
modalDialogCustom.alert('Failed to create file ' + name)
} else {

@ -221,6 +221,8 @@ class FileProvider {
window.remixFileSystem.readdir(path, (error, files) => {
var ret = {}
console.log('files: ', files)
if (files) {
files.forEach(element => {
const absPath = (path === '/' ? '' : path) + '/' + element

@ -77,9 +77,11 @@ module.exports = class RemixDProvider {
return this._appManager.call('remixd', 'exists', { path: unprefixedpath })
.then((result) => {
return cb(null, result)
if(cb) return cb(null, result)
return result
}).catch((error) => {
return cb(error)
if(cb) return cb(error)
throw new Error(error)
})
}
@ -106,15 +108,26 @@ module.exports = class RemixDProvider {
})
}
set (path, content, cb) {
async set (path, content, cb) {
const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'set', {path: unprefixedpath, content: content}).then((result) => {
if (cb) return cb(null, result)
const exists = await this.exists(path)
return this._appManager.call('remixd', 'set', { path: unprefixedpath, content: content }).then(async (result) => {
const path = this.type + '/' + unprefixedpath
this.event.trigger('fileChanged', [path])
if (!exists) {
const isDirectory = await this.isDirectory(path)
if (isDirectory) this.event.trigger('folderAdded', [path])
else this.event.trigger('fileAdded', [path])
} else {
this.event.trigger('fileChanged', [path])
}
if (cb) return cb(null, result)
}).catch((error) => {
if (cb) cb(error)
if (cb) return cb(error)
throw new Error(error)
})
}
@ -127,7 +140,6 @@ module.exports = class RemixDProvider {
const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'remove', { path: unprefixedpath })
.then(result => {
console.log('result: ', result)
const path = this.type + '/' + unprefixedpath
delete this.filesContent[path]
@ -179,7 +191,10 @@ module.exports = class RemixDProvider {
if (path[0] === '/') path = path.substring(1)
if (!path) return callback(null, { [self.type]: { } })
const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'resolveDirectory', {path: unprefixedpath}).then((result) => callback(null, result)).catch(callback)
this._appManager.call('remixd', 'resolveDirectory', { path: unprefixedpath }).then((result) => {
console.log('result: ', result)
callback(null, result)
}).catch(callback)
}
async isDirectory (path) {

@ -152,6 +152,7 @@ class TreeView {
}
nodeAt (path) {
console.log('nodeAt path: ', path)
return this.view.querySelector(`ul[key="${path}"]`)
}

Loading…
Cancel
Save