@ -1,18 +1,19 @@
/* global FileReader */
/* global FileReader */
var async = require ( 'async' )
const async = require ( 'async' )
var Gists = require ( 'gists' )
const Gists = require ( 'gists' )
var modalDialogCustom = require ( '../ui/modal-dialog-custom' )
const modalDialogCustom = require ( '../ui/modal-dialog-custom' )
var tooltip = require ( '../ui/tooltip' )
const tooltip = require ( '../ui/tooltip' )
var QueryParams = require ( '../../lib/query-params' )
const QueryParams = require ( '../../lib/query-params' )
var helper = require ( '../../lib/helper' )
const helper = require ( '../../lib/helper' )
var yo = require ( 'yo-yo' )
const yo = require ( 'yo-yo' )
var Treeview = require ( '../ui/TreeView' )
const Treeview = require ( '../ui/TreeView' )
var modalDialog = require ( '../ui/modaldialog' )
const modalDialog = require ( '../ui/modaldialog' )
var EventManager = require ( '../../lib/events' )
const EventManager = require ( '../../lib/events' )
var contextMenu = require ( '../ui/contextMenu' )
const contextMenu = require ( '../ui/contextMenu' )
var css = require ( './styles/file-explorer-styles' )
const css = require ( './styles/file-explorer-styles' )
var globalRegistry = require ( '../../global/registry' )
const globalRegistry = require ( '../../global/registry' )
var queryParams = new QueryParams ( )
const queryParams = new QueryParams ( )
//
let MENU _HANDLE
let MENU _HANDLE
function fileExplorer ( localRegistry , files , menuItems ) {
function fileExplorer ( localRegistry , files , menuItems ) {
@ -441,35 +442,43 @@ fileExplorer.prototype.toGist = function (id) {
}
}
}
}
async function getOriginalFiles ( id ) {
if ( ! id ) {
return [ ]
}
const url = ` https://api.github.com/gists/ ${ id } `
const res = await fetch ( url )
const data = await res . json ( )
return data . files || [ ]
}
this . packageFiles ( this . files , 'browser/gists/' + id , ( error , packaged ) => {
this . packageFiles ( this . files , 'browser/gists/' + id , ( error , packaged ) => {
if ( error ) {
if ( error ) {
console . log ( error )
console . log ( error )
modalDialogCustom . alert ( 'Failed to create gist: ' + error )
modalDialogCustom . alert ( 'Failed to create gist: ' + error )
} else {
} else {
// check for token
var tokenAccess = this . _deps . config . get ( 'settings/gist-access-token' )
var tokenAccess = this . _deps . config . get ( 'settings/gist-access-token' )
if ( ! tokenAccess ) {
if ( ! tokenAccess ) {
modalDialogCustom . alert (
modalDialogCustom . alert (
'Remix requires an access token (which includes gists creation permission). Please go to the settings tab to create one.'
'Remix requires an access token (which includes gists creation permission). Please go to the settings tab to create one.'
)
)
} else {
} else {
var description = 'Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=' +
// get existing gist files
queryParams . get ( ) . version +
const description = 'Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=' +
'&optimize=' +
queryParams . get ( ) . version + '&optimize=' + queryParams . get ( ) . optimize + '&gist='
queryParams . get ( ) . optimize +
const gists = new Gists ( { token : tokenAccess } )
'&gist='
var gists = new Gists ( {
token : tokenAccess
} )
if ( id ) {
if ( id ) {
const fileList = Object . keys ( this . files . origGistFiles )
let originalFileList = getOriginalFiles ( id )
const updatedFileList = Object . keys ( packaged )
// Telling the GIST API to remove files
// Telling the GIST API to remove files
const allItems = fileList
const updatedFileList = Object . keys ( packaged )
const allItems = Object . keys ( originalFileList )
. filter ( fileName => updatedFileList . indexOf ( fileName ) === - 1 )
. filter ( fileName => updatedFileList . indexOf ( fileName ) === - 1 )
. reduce ( ( acc , deleteFileName ) => ( {
. reduce ( ( acc , deleteFileName ) => ( {
... acc ,
... acc ,
[ deleteFileName ] : null
[ deleteFileName ] : null
} ) , this . files . origGistFiles )
} ) , originalFileList )
// adding new files
// adding new files
updatedFileList . forEach ( ( file ) => {
updatedFileList . forEach ( ( file ) => {
const _items = file . split ( '/' )
const _items = file . split ( '/' )
@ -489,10 +498,10 @@ fileExplorer.prototype.toGist = function (id) {
for ( const key in allItems ) {
for ( const key in allItems ) {
if ( allItems [ key ] === null ) delete allItems [ key ]
if ( allItems [ key ] === null ) delete allItems [ key ]
}
}
this . files . origGistFiles = allItems
}
}
} )
} )
} else {
} else {
// id is not existing, need to create a new gist
tooltip ( 'Creating a new gist ...' )
tooltip ( 'Creating a new gist ...' )
gists . create ( {
gists . create ( {
description : description ,
description : description ,