Merge pull request #935 from ethereum/fileExplorers

[Gist File explorer] Fix file loading
pull/3094/head
yann300 7 years ago committed by GitHub
commit 9aa16f7e1c
  1. 10
      src/app.js
  2. 4
      src/app/contract/publishOnSwarm.js
  3. 19
      src/app/files/basicReadOnlyExplorer.js
  4. 1
      src/app/files/file-explorer.js
  5. 2
      src/app/panels/file-panel.js
  6. 1
      src/app/tabs/settings-tab.js

@ -409,14 +409,16 @@ function run () {
})
// Add files received from remote instance (i.e. another browser-solidity)
function loadFiles (filesSet) {
function loadFiles (filesSet, fileProvider) {
if (!fileProvider) fileProvider = 'browser'
for (var f in filesSet) {
var name = helper.createNonClashingName(f, filesProviders['browser'])
var name = helper.createNonClashingName(f, filesProviders[fileProvider])
if (helper.checkSpecialChars(name)) {
modalDialogCustom.alert('Special characters are not allowed')
return
}
filesProviders['browser'].set(name, filesSet[f].content)
filesProviders[fileProvider].set(name, filesSet[f].content)
}
fileManager.switchFile()
}
@ -444,7 +446,7 @@ function run () {
modalDialogCustom.alert('Gist load error: ' + response.data.message)
return
}
loadFiles(response.data.files)
loadFiles(response.data.files, 'gist')
}
}
})

@ -7,10 +7,6 @@ module.exports = (contract, appAPI, cb, swarmVerifiedPublishCallBack) => {
// gather list of files to publish
var sources = []
try {
contract.metadata = JSON.stringify(JSON.parse(contract.metadata), null, '\t')
} catch (e) {}
sources.push({
content: contract.metadata,
hash: contract.metadataHash

@ -1,11 +1,12 @@
'use strict'
var EventManager = require('remix-lib').EventManager
class SwarmExplorer {
class BasicReadOnlyExplorer {
constructor (type) {
this.event = new EventManager()
this.files = {}
this.type = type
this.readonly = true
}
close (cb) {
@ -31,12 +32,18 @@ class SwarmExplorer {
}
set (path, content, cb) {
this.addReadOnly(path, content)
if (cb) cb()
return true
}
addReadOnly (path, content) {
this.files[this.type + '/' + path] = content
this.event.trigger('fileAdded', [this.type + '/' + path, true])
var unprefixedPath = this.removePrefix(path)
try { // lazy try to format JSON
content = JSON.stringify(JSON.parse(content), null, '\t')
} catch (e) {}
this.files[this.type + '/' + unprefixedPath] = content
this.event.trigger('fileAdded', [this.type + '/' + unprefixedPath, true])
return true
}
@ -97,6 +104,10 @@ class SwarmExplorer {
})
return tree
}
removePrefix (path) {
return path.indexOf(this.type + '/') === 0 ? path.replace(this.type + '/', '') : path
}
}
module.exports = SwarmExplorer
module.exports = BasicReadOnlyExplorer

@ -216,6 +216,7 @@ function fileExplorer (appAPI, files) {
}
function editModeOn (event) {
if (self.files.readonly) return
var label = this
var li = getLiFrom(label)
var classes = li.className

@ -345,7 +345,7 @@ function filepanel (appAPI, filesProvider) {
}
function toGist () {
packageFiles(filesProvider['gist'], (error, packaged) => {
packageFiles(filesProvider['browser'], (error, packaged) => {
if (error) {
console.log(error)
} else {

@ -72,6 +72,7 @@ function SettingsTab (container, appAPI, appEvents, opts) {
optimize.setAttribute('checked', true)
appAPI.setOptimize(true, false)
} else {
queryParams.update({ optimize: false })
appAPI.setOptimize(false, false)
}

Loading…
Cancel
Save