Add template thumbnail generation and display

This commit is contained in:
Tautvidas Sipavičius
2015-11-24 16:50:57 +02:00
parent ebca4257a6
commit 52a0aae10f
6 changed files with 50 additions and 14 deletions

View File

@ -18,6 +18,17 @@
height: 150px height: 150px
margin-right: 15px margin-right: 15px
float: left float: left
overflow: hidden
img
min-width: 150px
min-height: 150px
height: 100%
width: auto
position: relative
top: 50%
left: 50%
transform: translate(-50%, -50%)
.mailpoet_boxes .mailpoet_description .mailpoet_boxes .mailpoet_description
float:left float:left

View File

@ -6,8 +6,9 @@ define([
'backbone.marionette', 'backbone.marionette',
'jquery', 'jquery',
'blob', 'blob',
'filesaver' 'filesaver',
], function(App, MailPoet, Notice, Backbone, Marionette, jQuery, Blob, FileSaver) { 'html2canvas'
], function(App, MailPoet, Notice, Backbone, Marionette, jQuery, Blob, FileSaver, html2canvas) {
"use strict"; "use strict";
@ -56,8 +57,17 @@ define([
}); });
}; };
Module.getThumbnail = function(element, options) {
return html2canvas(element, options || {});
};
Module.exportTemplate = function(options) { Module.exportTemplate = function(options) {
var that = this;
return Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function(thumbnail) {
var data = _.extend(options || {}, { var data = _.extend(options || {}, {
thumbnail: thumbnail.toDataURL(),
body: App.getBody(), body: App.getBody(),
}); });
var blob = new Blob( var blob = new Blob(
@ -66,6 +76,7 @@ define([
); );
FileSaver.saveAs(blob, 'template.json'); FileSaver.saveAs(blob, 'template.json');
});
}; };
Module.SaveView = Marionette.LayoutView.extend({ Module.SaveView = Marionette.LayoutView.extend({

View File

@ -56,7 +56,7 @@ define([
}; };
Module.getTransformedPosts = function(options) { Module.getTransformedPosts = function(options) {
return Module._query({ return Module._cachedQuery({
action: 'getTransformedPosts', action: 'getTransformedPosts',
options: options, options: options,
}); });

View File

@ -164,11 +164,19 @@ define(
Delete Delete
</a> </a>
</div> </div>
), thumbnail = '';
if (typeof template.thumbnail === 'string'
&& template.thumbnail.length > 0) {
thumbnail = (
<img src={ template.thumbnail } />
); );
}
return ( return (
<li key={ 'template-'+index }> <li key={ 'template-'+index }>
<div className="mailpoet_thumbnail"> <div className="mailpoet_thumbnail">
{ thumbnail }
</div> </div>
<div className="mailpoet_description"> <div className="mailpoet_description">

View File

@ -97,6 +97,7 @@ class Migrator {
'name varchar(250) NOT NULL,', 'name varchar(250) NOT NULL,',
'description varchar(250) NOT NULL,', 'description varchar(250) NOT NULL,',
'body longtext,', 'body longtext,',
'thumbnail longtext,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,', 'created_at TIMESTAMP NOT NULL DEFAULT 0,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', 'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id)' 'PRIMARY KEY (id)'

View File

@ -29,7 +29,8 @@ baseConfig = {
'blob$': 'blob/Blob.js', 'blob$': 'blob/Blob.js',
'filesaver$': 'filesaver/FileSaver.js', 'filesaver$': 'filesaver/FileSaver.js',
'papaparse': 'papaparse/papaparse.min.js', 'papaparse': 'papaparse/papaparse.min.js',
'helpscout': 'helpscout.js' 'helpscout': 'helpscout.js',
'html2canvas': 'html2canvas/dist/html2canvas.js'
}, },
}, },
node: { node: {
@ -73,6 +74,10 @@ baseConfig = {
include: /helpscout.js$/, include: /helpscout.js$/,
loader: 'exports-loader?window.HS', loader: 'exports-loader?window.HS',
}, },
{
include: /html2canvas.js$/,
loader: 'expose-loader?html2canvas',
},
] ]
} }
}; };