Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and drop of files #142

Merged
merged 4 commits into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }));
});

Expand Down
55 changes: 54 additions & 1 deletion src/components/file-browser/file-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/nav-bar/nav-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</li>

<li data-bind="css: { active: route().page === 'play-activity-page' }">
<a href="#playground">Playground</a>
<a href="#VM">VM</a>
</li>

<!-- TODO: Unhide navigation link once the page is ready -->
Expand Down