Skip to content

Commit

Permalink
add file upload by dragging it into the editor
Browse files Browse the repository at this point in the history
fixes #45
  • Loading branch information
lucas-clemente committed Jun 3, 2015
1 parent 10d7119 commit 94a4b0d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Features:

- File upload via drag and drop into the folder view
- Commits that are less than a minute ago are automatically ammended
- File upload via drag and drop into the folder view or drag and drop into the editor. The latter will insert a reference to the file into the text.
- Commits that are less than a minute ago are automatically amended.
- Autosave in the web editor

Fixed:
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/drop-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default Ember.Component.extend({
return;
}
var files = e.dataTransfer.files;
this.sendAction('action', files);
this.sendAction('action', files, e.target);
});
},
});
6 changes: 4 additions & 2 deletions web/app/controllers/folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export default Ember.Controller.extend({
id: id,
folder: folder,
});
page.save();
page.sendData(file);
/* jshint -W083 */
page.save().then(function () {
page.sendData(file);
});
}
},
},
Expand Down
27 changes: 27 additions & 0 deletions web/app/controllers/page/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,32 @@ export default Ember.Controller.extend({
this.get('model').save();
this.transitionToRoute('page.show', this.get('model'));
},

uploadAndLinkFile: function (fileList, textArea) {
var textToInsert = '';

var folder = this.get('page.folder');
for (var i = 0; i < fileList.length; i++) {
var file = fileList.item(i);
var id = folder.get('id') + '|' + file.name;
id = id.replace('||', '|');
var page = this.store.createRecord('page', {
id: id,
folder: folder,
});
/* jshint -W083 */
page.save().then(function () {
page.sendData(file);
});

textToInsert += '[[' + file.name + ']]';
}

var pos = textArea.selectionStart || 0;
var text = this.get('page.markdownSource');
this.set('page.markdownSource', text.substring(0, pos) + textToInsert + text.substring(pos));
textArea.selectionStart = pos + textToInsert.length;
textArea.selectionEnd = pos + textToInsert.length;
},
},
});
8 changes: 4 additions & 4 deletions web/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ a:not([href]) {
cursor: pointer;
}

.dragging {
box-shadow: 0px 0px 10px green;
}

// Folder list

.nav-list {
Expand All @@ -51,10 +55,6 @@ a:not([href]) {
border-color: lighten(#428bca, 20%);
color: #fff;
}

&.dragging {
box-shadow: 0px 0px 10px green;
}
}

.btn-new-file {
Expand Down
4 changes: 3 additions & 1 deletion web/app/templates/page/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
</div>

{{#if page.isMarkdown}}
{{textarea-autosize value=page.markdownSource class="markdown-edit" placeholder='Type markdown here'}}
{{#drop-area action='uploadAndLinkFile'}}
{{textarea-autosize value=page.markdownSource class="markdown-edit" placeholder='Type markdown here'}}
{{/drop-area}}
{{/if}}

0 comments on commit 94a4b0d

Please sign in to comment.