diff --git a/src/app/router.js b/src/app/router.js index 6ccdd322..321d4949 100644 --- a/src/app/router.js +++ b/src/app/router.js @@ -43,7 +43,7 @@ class Router { this.currentRoute(ko.utils.extend(requestParams, { page: 'activity-page' })); }); - crossroads.addRoute('playground', (requestParams) => { + crossroads.addRoute('VM', (requestParams) => { this.currentRoute(ko.utils.extend(requestParams, { page: 'play-activity-page' })); }); diff --git a/src/components/file-browser/file-browser.js b/src/components/file-browser/file-browser.js index 3509b376..5edbe43c 100644 --- a/src/components/file-browser/file-browser.js +++ b/src/components/file-browser/file-browser.js @@ -102,7 +102,6 @@ class Filebrowser { this.id = '#file-browser-body'; var fs = this.fs = SysFileSystem; - //TODO we are using the TokenHighligher to get a reference to the current Ace Editor... find a direct reference this.editor = SysGlobalObservables.Editor; this.depth = -1; @@ -253,6 +252,60 @@ class Filebrowser { return false; }); + $('#file-browser').on('dragover', (e) => { + e.preventDefault(); + e.stopPropagation(); + return false; + }); + $('#file-browser').on('dragenter', (e) => { + e.preventDefault(); + e.stopPropagation(); + return false; + }); + + $('#file-browser').on('drop', (e) => { + e.preventDefault(); + e.stopPropagation(); + var files = e.originalEvent.dataTransfer.files; + var droppedLocationItem = $(e.target); + var itemId = droppedLocationItem.data('id'); + var writeDroppedFile = function(i, done) { + (function (i) { + if (i === files.length) { + return done(); + } + + var file = files[i]; + var reader = new FileReader(); + reader.file = file; + reader.onload = function (e) { + if (itemId === undefined) { + fs.writeFile('/' +file.name, new Buffer(reader.result, 'binary')); + writeDroppedFile(i + 1, done); + } + else if (self.metaData[itemId].isDirectory) { + fs.writeFile(self.metaData[itemId].path + '/' +file.name, new Buffer(reader.result, 'binary')); + writeDroppedFile(i + 1, done); + } + else { + var newPath = self.metaData[itemId].parentPath + '/' + file.name; + if (self.metaData[itemId].parentPath == '/'){ + newPath = self.metaData[itemId].parentPath + file.name; + } + fs.writeFile(newPath, new Buffer(reader.result, 'binary')); + writeDroppedFile(i + 1, done); + } + }; + reader.readAsBinaryString(file); + })(i); + }; + + writeDroppedFile(0, () => {}); + + return false; + }); + + // toggle directory $(this.id).on('click', '.folder', (e) => { var $curr = $(e.currentTarget); diff --git a/src/components/nav-bar/nav-bar.html b/src/components/nav-bar/nav-bar.html index 411d3414..b1f5829d 100644 --- a/src/components/nav-bar/nav-bar.html +++ b/src/components/nav-bar/nav-bar.html @@ -27,7 +27,7 @@
  • - Playground + VM