Skip to content
Snippets Groups Projects
Commit a52e9c79 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Merge branch 'summernote' of github.com:noesya/osuny into summernote

parents 728ea648 0a310d23
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,8 @@ gem 'jbuilder' ...@@ -46,7 +46,8 @@ gem 'jbuilder'
gem 'kamifusen'#, path: '../kamifusen' gem 'kamifusen'#, path: '../kamifusen'
gem 'bootstrap' gem 'bootstrap'
gem 'sanitize' gem 'sanitize'
gem 'summernote-rails', git: 'https://github.com/noesya/summernote-rails.git' gem 'summernote-rails', git: 'https://github.com/noesya/summernote-rails.git', branch: 'activestorage'
# gem 'summernote-rails', path: '../summernote-rails'
group :development, :test do group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
......
GIT GIT
remote: https://github.com/noesya/summernote-rails.git remote: https://github.com/noesya/summernote-rails.git
revision: 6dcff6c2a0e56492dbbcaf0a91ccc5898e6be922 revision: 3581d868bbe303377f37f6e26858176debae51a4
branch: activestorage
specs: specs:
summernote-rails (0.8.20.1) summernote-rails (0.8.20.1)
railties (>= 3.1) railties (>= 3.1)
......
const uploadFile = (file) => {
// TODO should be data-direct-upload-url
const url = '/rails/active_storage/direct_uploads'
const upload = new ActiveStorage.DirectUpload(file, url)
upload.create((error, blob) => {
if (error) {
alert(error)
} else {
console.log(blob)
return blob
}
})
}
/* eslint no-alert: 'off' */ /* eslint no-alert: 'off' */
/*global $, FormData */ /*global $, SummernoteAttachmentUpload */
// window.osuny.summernote.sendFile = function (file, toSummernote) { // window.osuny.summernote.sendFile = function (file, toSummernote) {
// 'use strict'; // 'use strict';
// var data = new FormData(); // var data = new FormData();
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
// }; // };
// //
//
$(function () { $(function () {
'use strict'; 'use strict';
...@@ -58,10 +54,8 @@ $(function () { ...@@ -58,10 +54,8 @@ $(function () {
], ],
callbacks: { callbacks: {
onImageUpload: function (files) { onImageUpload: function (files) {
var blob = uploadFile(files[0]); var attachmentUpload = new SummernoteAttachmentUpload(this, files[0]);
console.log(blob); attachmentUpload.start();
// 'use strict';
// window.osuny.summernote.sendFile(files[0], $(this));
} }
} }
}); });
......
/*global ActiveStorage */
var SummernoteAttachmentUpload = function (element, file) {
'use strict';
this.element = element;
this.file = file;
this.directUpload = new ActiveStorage.DirectUpload(file, this.getDirectUploadUrl(), this);
};
SummernoteAttachmentUpload.prototype.start = function () {
'use strict';
this.directUpload.create(this.directUploadDidComplete.bind(this));
};
SummernoteAttachmentUpload.prototype.directUploadDidComplete = function (error, attributes) {
'use strict';
if (error) {
throw new Error('Direct upload failed: ' + error);
}
// Insert Blob in Summernote
console.log(attributes);
console.log({
sgid: attributes.attachable_sgid,
url: this.createBlobUrl(attributes.signed_id, attributes.filename)
});
};
SummernoteAttachmentUpload.prototype.createBlobUrl = function (signedId, filename) {
'use strict';
return this.getBlobUrlTemplate()
.replace(':signed_id', signedId)
.replace(':filename', encodeURIComponent(filename));
};
SummernoteAttachmentUpload.prototype.getDirectUploadUrl = function () {
'use strict';
return this.element.dataset.directUploadUrl;
};
SummernoteAttachmentUpload.prototype.getBlobUrlTemplate = function () {
'use strict';
return this.element.dataset.blobUrlTemplate;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment