批量导出html成功, 待添加到notebook上

This commit is contained in:
life
2015-10-24 15:30:46 +08:00
parent 51174399d2
commit 5f2ad33ffa
8 changed files with 167 additions and 36 deletions

3
node_modules/note.js generated vendored
View File

@@ -1682,6 +1682,9 @@ var Note = {
if(!serverNoteId) { if(!serverNoteId) {
callback({Ok: false, Msg: 'noteNotExists'}); callback({Ok: false, Msg: 'noteNotExists'});
} else { } else {
if (!Api) {
Api = require('api');
}
Api.exportPdf(serverNoteId, callback); Api.exportPdf(serverNoteId, callback);
} }
}) })

View File

@@ -601,7 +601,7 @@ function log(o) {
<!-- loading --> <!-- loading -->
<div class="modal fade bs-modal-sm" id="loadingDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel"> <div class="modal fade bs-modal-sm" id="loadingDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm modal-large">
<div class="modal-content"> <div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
@@ -614,6 +614,7 @@ function log(o) {
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;"> <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;">
<span class="sr-only">60% Complete</span> <span class="sr-only">60% Complete</span>
</div> </div>
<div class="progress-rate"></div>
</div> </div>
</div> </div>

View File

@@ -2319,8 +2319,14 @@ Note.initContextmenu = function() {
var menuItem = new gui.MenuItem({ var menuItem = new gui.MenuItem({
label: menu.label, label: menu.label,
click: function(e) { click: function(e) {
var note = Note.getNote($(self.target).attr('noteId')); if (Note.inBatch) {
clickBac && clickBac(note); var noteIds = Note.getBatchNoteIds();
}
else {
var noteIds = [$(self.target).attr('noteId')];
}
// var note = Note.getNote();
clickBac && clickBac(noteIds);
} }
}); });

View File

@@ -1568,12 +1568,26 @@ var trimTitle = function(title) {
var Loading = { var Loading = {
$loadingDialog: $('#loadingDialog'), $loadingDialog: $('#loadingDialog'),
$progressBar: $('#loadingDialog .progress-bar'), $progressBar: $('#loadingDialog .progress-bar'),
$progressRate: $('#loadingDialog .progress-rate'),
$msg: $('#loadingDialogBodyMsg'),
// option {hasProgress: true, onClose: function} // option {hasProgress: true, onClose: function}
inited: false, inited: false,
setMsg: function (msg) {
this.$msg.html(msg);
},
setProgressRate: function (msg) {
this.$progressRate.html(msg);
},
show: function(msg, option) { show: function(msg, option) {
option = option || {}; option = option || {};
msg || (msg = getMsg("loading...")); msg || (msg = getMsg("loading..."));
$('#loadingDialogBodyMsg').html(msg); this.$msg.html(msg);
if (option.isLarge) {
this.$loadingDialog.find('.modal-dialog').addClass('modal-large');
}
else {
this.$loadingDialog.find('.modal-dialog').addClass('modal-large');
}
this.$loadingDialog.modal({backdrop: 'static', keyboard: true}); this.$loadingDialog.modal({backdrop: 'static', keyboard: true});
if (option.hasProgress) { if (option.hasProgress) {
this.$loadingDialog.addClass('has-progress'); this.$loadingDialog.addClass('has-progress');

View File

@@ -11,17 +11,23 @@ define(function() {
langs: { langs: {
'en-us': { 'en-us': {
'export': 'Export HTML', 'export': 'Export HTML',
'Exporting': 'Exporting',
'Exporting: ': 'Exporting: ',
'exportSuccess': 'HTML saved successful!', 'exportSuccess': 'HTML saved successful!',
'exportFailure': 'HTML saved failure!', 'exportFailure': 'HTML saved failure!',
'notExists': 'Please sync your note to ther server firslty.' 'notExists': 'Please sync your note to ther server firslty.'
}, },
'zh-cn': { 'zh-cn': {
'export': '导出HTML', 'export': '导出HTML',
'Exporting': '正在导出',
'Exporting: ': '正在导出: ',
'exportSuccess': 'HTML导出成功!', 'exportSuccess': 'HTML导出成功!',
'exportFailure': 'HTML导出失败!' 'exportFailure': 'HTML导出失败!'
}, },
'zh-hk': { 'zh-hk': {
'export': '導出HTML', 'export': '導出HTML',
'Exporting': '正在導出',
'Exporting: ': '正在導出: ',
'exportSuccess': 'HTML導出成功!', 'exportSuccess': 'HTML導出成功!',
'exportFailure': 'HTML導出失敗!' 'exportFailure': 'HTML導出失敗!'
} }
@@ -125,7 +131,7 @@ define(function() {
}, },
// 得到存放images, js, css的路径 // 得到存放images, js, css的路径
getFilesPath: function(basePath, nameNotExt, n, cb) { getAssetsPath: function(basePath, nameNotExt, n, cb) {
var me = this; var me = this;
var absPath = basePath + '/' + nameNotExt + '_files'; var absPath = basePath + '/' + nameNotExt + '_files';
if (n > 1) { if (n > 1) {
@@ -136,7 +142,7 @@ define(function() {
cb(absPath); cb(absPath);
} }
else { else {
me.getFilesPath(basePath, nameNotExt, n+1, cb); me.getAssetsPath(basePath, nameNotExt, n+1, cb);
} }
}); });
}, },
@@ -148,8 +154,6 @@ define(function() {
pathInfo.nameNotExt = pathInfo.nameNotExtRaw + '-' + n; pathInfo.nameNotExt = pathInfo.nameNotExtRaw + '-' + n;
} }
var absPath = pathInfo.getFullPath(); var absPath = pathInfo.getFullPath();
// 总是覆盖
return cb(absPath);
// Api.nodeFs.existsSync(absPath) 总是返回false, 不知道什么原因 // Api.nodeFs.existsSync(absPath) 总是返回false, 不知道什么原因
// 在控制台上是可以的 // 在控制台上是可以的
@@ -163,36 +167,105 @@ define(function() {
}); });
}, },
exportHTML: function(note) { loadingIsClosed: false,
exportHTML: function (noteIds) {
var me = this;
if (!noteIds || noteIds.length == 0) {
return;
}
// showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{
defaultPath: Api.gui.app.getPath('userDesktop') + '/',
properties: ['openDirectory']
},
function(targetPath) {
if(!targetPath) {
return;
}
me.loadingIsClosed = false;
Api.loading.show(Api.getMsg('plugin.export_html.Exporting'),
{
hasProgress: true,
isLarge: true,
onClose: function () {
me.loadingIsClosed = true;
setTimeout(function() {
Api.loading.hide();
});
}});
Api.loading.setProgress(1);
var i = 0;
var total = noteIds.length;
async.eachSeries(noteIds, function(noteId, cb) {
if (me.loadingIsClosed) {
cb();
return;
}
// setTimeout(function () {
i++;
Api.loading.setProgress(100 * i / total);
Api.noteService.getNote(noteId, function(note) {
me._exportHTML(note, targetPath, function() {
cb();
}, i, total);
});
// }, i * 1000);
}, function () {
Api.loading.hide();
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')});
});
});
},
_exportHTML: function(note, path, callback, i, total) {
var me = this; var me = this;
if(!note) { if(!note) {
return; return;
} }
if (me.loadingIsClosed) {
callback();
return;
}
setTimeout(function () {
Api.loading.setMsg(Api.getMsg('plugin.export_html.Exporting: ') + (note.Title || getMsg('Untitled')));
Api.loading.setProgressRate(i + '/' + total);
}, 100);
var name = note.Title ? note.Title + '.html' : getMsg('Untitled') + '.html'; var name = note.Title ? note.Title + '.html' : getMsg('Untitled') + '.html';
name = me.fixFilename(name); name = me.fixFilename(name);
Api.gui.dialog.showSaveDialog(Api.gui.getCurrentWindow(), {title: name, defaultPath: name}, function(targetPath) { var targetPath = path + '/' + name;
if(targetPath) {
// 将路径和名字区分开 // 将路径和名字区分开
var pathInfo = Api.commonService.splitFile(targetPath); var pathInfo = Api.commonService.splitFile(targetPath);
pathInfo.nameNotExt = me.fixFilename(pathInfo.nameNotExt); // 重新修正一次 pathInfo.nameNotExt = me.fixFilename(pathInfo.nameNotExt); // 重新修正一次
var nameNotExt = pathInfo.nameNotExt; var nameNotExt = pathInfo.nameNotExt;
pathInfo.nameNotExtRaw = pathInfo.nameNotExt; pathInfo.nameNotExtRaw = pathInfo.nameNotExt;
// 得到可用文件的绝对路径
me.getHtmlFilePath(pathInfo, 1, function(absHtmlFilePath) { // 得到可用文件的绝对路径
me.getFilesPath(pathInfo.path, pathInfo.nameNotExt, 1, function(absFilesPath) { me.getHtmlFilePath(pathInfo, 1, function(absHtmlFilePath) {
// alert(absHtmlFilePath + ' --- ' + absFilesPath); // 得到存放assets的目录
var html = me.render(note); me.getAssetsPath(pathInfo.path, pathInfo.nameNotExt, 1, function(absFilesPath) {
// 写图片 // alert(absHtmlFilePath + ' --- ' + absFilesPath);
me.writeFiles(absFilesPath, html, function(html) { var html = me.render(note);
// 把文件写到 // 写图片
Api.commonService.writeFile(absHtmlFilePath, html); me.writeFiles(absFilesPath, html, function(html) {
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')}); // 把html文件写到
}); Api.commonService.writeFile(absHtmlFilePath, html);
}); callback();
}); });
} });
}); });
}, },
@@ -207,8 +280,8 @@ define(function() {
return true; return true;
}, },
click: (function() { click: (function() {
return function(note) { return function(noteIds) {
me.exportHTML(note); me.exportHTML(noteIds);
} }
})() })()
}; };

View File

@@ -117,18 +117,26 @@ define(function() {
var menu = { var menu = {
label: Api.getMsg('plugin.export_pdf.export'), label: Api.getMsg('plugin.export_pdf.export'),
enabled: function(noteIds) { enabled: function(noteIds) {
if(UserInfo.IsLocal) {
return false;
}
if (noteIds && noteIds.length == 1) { if (noteIds && noteIds.length == 1) {
return true; return true;
} }
return false; return false;
}, },
click: (function() { click: (function() {
return function(note) { return function(noteIds) {
if (UserInfo.IsLocal) { if (UserInfo.IsLocal) {
Notify.show({type: 'warning', title: 'Warning', body: getMsg('plugin.export_pdf.localUser')}); Notify.show({type: 'warning', title: 'Warning', body: getMsg('plugin.export_pdf.localUser')});
return; return;
} }
me.exportPDF(note); if (!noteIds || noteIds.length > 1) {
return;
}
Api.noteService.getNote(noteIds[0], function(note) {
me.exportPDF(note);
});
} }
})() })()
}; };

View File

@@ -1861,19 +1861,32 @@ img::selection {
left: 50%; left: 50%;
margin-left: -100px; margin-left: -100px;
} }
.modal-dialog.modal-large {
width: 300px !important;
}
.modal-body { .modal-body {
text-align: center; text-align: center;
border-radius: 5px; border-radius: 5px;
} }
#loadingDialogBodyMsg { #loadingDialogBodyMsg {
font-size: 16px; font-size: 14px;
margin-top: 10px;
height: 20px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
} }
.progress { .progress {
margin: 0; margin: 0;
margin-top: 20px; margin-top: 20px;
height: 1px; height: 1px;
display: none; display: none;
overflow: visible;
}
.progress-rate {
clear: both;
font-size: 12px;
} }
&.has-progress { &.has-progress {

View File

@@ -1638,18 +1638,31 @@ img::selection {
left: 50%; left: 50%;
margin-left: -100px; margin-left: -100px;
} }
#loadingDialog .modal-dialog.modal-large {
width: 300px !important;
}
#loadingDialog .modal-body { #loadingDialog .modal-body {
text-align: center; text-align: center;
border-radius: 5px; border-radius: 5px;
} }
#loadingDialog #loadingDialogBodyMsg { #loadingDialog #loadingDialogBodyMsg {
font-size: 16px; font-size: 14px;
margin-top: 10px;
height: 20px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
} }
#loadingDialog .progress { #loadingDialog .progress {
margin: 0; margin: 0;
margin-top: 20px; margin-top: 20px;
height: 1px; height: 1px;
display: none; display: none;
overflow: visible;
}
#loadingDialog .progress-rate {
clear: both;
font-size: 12px;
} }
#loadingDialog.has-progress .progress { #loadingDialog.has-progress .progress {
display: block; display: block;