批量导出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) {
callback({Ok: false, Msg: 'noteNotExists'});
} else {
if (!Api) {
Api = require('api');
}
Api.exportPdf(serverNoteId, callback);
}
})

View File

@@ -601,7 +601,7 @@ function log(o) {
<!-- loading -->
<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">
<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%;">
<span class="sr-only">60% Complete</span>
</div>
<div class="progress-rate"></div>
</div>
</div>

View File

@@ -2319,8 +2319,14 @@ Note.initContextmenu = function() {
var menuItem = new gui.MenuItem({
label: menu.label,
click: function(e) {
var note = Note.getNote($(self.target).attr('noteId'));
clickBac && clickBac(note);
if (Note.inBatch) {
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 = {
$loadingDialog: $('#loadingDialog'),
$progressBar: $('#loadingDialog .progress-bar'),
$progressRate: $('#loadingDialog .progress-rate'),
$msg: $('#loadingDialogBodyMsg'),
// option {hasProgress: true, onClose: function}
inited: false,
setMsg: function (msg) {
this.$msg.html(msg);
},
setProgressRate: function (msg) {
this.$progressRate.html(msg);
},
show: function(msg, option) {
option = option || {};
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});
if (option.hasProgress) {
this.$loadingDialog.addClass('has-progress');

View File

@@ -11,17 +11,23 @@ define(function() {
langs: {
'en-us': {
'export': 'Export HTML',
'Exporting': 'Exporting',
'Exporting: ': 'Exporting: ',
'exportSuccess': 'HTML saved successful!',
'exportFailure': 'HTML saved failure!',
'notExists': 'Please sync your note to ther server firslty.'
},
'zh-cn': {
'export': '导出HTML',
'Exporting': '正在导出',
'Exporting: ': '正在导出: ',
'exportSuccess': 'HTML导出成功!',
'exportFailure': 'HTML导出失败!'
},
'zh-hk': {
'export': '導出HTML',
'Exporting': '正在導出',
'Exporting: ': '正在導出: ',
'exportSuccess': 'HTML導出成功!',
'exportFailure': 'HTML導出失敗!'
}
@@ -125,7 +131,7 @@ define(function() {
},
// 得到存放images, js, css的路径
getFilesPath: function(basePath, nameNotExt, n, cb) {
getAssetsPath: function(basePath, nameNotExt, n, cb) {
var me = this;
var absPath = basePath + '/' + nameNotExt + '_files';
if (n > 1) {
@@ -136,7 +142,7 @@ define(function() {
cb(absPath);
}
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;
}
var absPath = pathInfo.getFullPath();
// 总是覆盖
return cb(absPath);
// 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;
if(!note) {
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';
name = me.fixFilename(name);
Api.gui.dialog.showSaveDialog(Api.gui.getCurrentWindow(), {title: name, defaultPath: name}, function(targetPath) {
if(targetPath) {
// 将路径和名字区分开
var pathInfo = Api.commonService.splitFile(targetPath);
pathInfo.nameNotExt = me.fixFilename(pathInfo.nameNotExt); // 重新修正一次
var nameNotExt = pathInfo.nameNotExt;
pathInfo.nameNotExtRaw = pathInfo.nameNotExt;
// 得到可用文件的绝对路径
me.getHtmlFilePath(pathInfo, 1, function(absHtmlFilePath) {
me.getFilesPath(pathInfo.path, pathInfo.nameNotExt, 1, function(absFilesPath) {
// alert(absHtmlFilePath + ' --- ' + absFilesPath);
var html = me.render(note);
// 写图片
me.writeFiles(absFilesPath, html, function(html) {
// 把文件写到
Api.commonService.writeFile(absHtmlFilePath, html);
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')});
});
});
var targetPath = path + '/' + name;
// 将路径和名字区分开
var pathInfo = Api.commonService.splitFile(targetPath);
pathInfo.nameNotExt = me.fixFilename(pathInfo.nameNotExt); // 重新修正一次
var nameNotExt = pathInfo.nameNotExt;
pathInfo.nameNotExtRaw = pathInfo.nameNotExt;
// 得到可用文件的绝对路径
me.getHtmlFilePath(pathInfo, 1, function(absHtmlFilePath) {
// 得到存放assets的目录
me.getAssetsPath(pathInfo.path, pathInfo.nameNotExt, 1, function(absFilesPath) {
// alert(absHtmlFilePath + ' --- ' + absFilesPath);
var html = me.render(note);
// 写图片
me.writeFiles(absFilesPath, html, function(html) {
// 把html文件写到
Api.commonService.writeFile(absHtmlFilePath, html);
callback();
});
}
});
});
},
@@ -207,8 +280,8 @@ define(function() {
return true;
},
click: (function() {
return function(note) {
me.exportHTML(note);
return function(noteIds) {
me.exportHTML(noteIds);
}
})()
};

View File

@@ -117,18 +117,26 @@ define(function() {
var menu = {
label: Api.getMsg('plugin.export_pdf.export'),
enabled: function(noteIds) {
if(UserInfo.IsLocal) {
return false;
}
if (noteIds && noteIds.length == 1) {
return true;
}
return false;
},
click: (function() {
return function(note) {
return function(noteIds) {
if (UserInfo.IsLocal) {
Notify.show({type: 'warning', title: 'Warning', body: getMsg('plugin.export_pdf.localUser')});
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%;
margin-left: -100px;
}
.modal-dialog.modal-large {
width: 300px !important;
}
.modal-body {
text-align: center;
border-radius: 5px;
}
#loadingDialogBodyMsg {
font-size: 16px;
font-size: 14px;
margin-top: 10px;
height: 20px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.progress {
margin: 0;
margin-top: 20px;
height: 1px;
display: none;
overflow: visible;
}
.progress-rate {
clear: both;
font-size: 12px;
}
&.has-progress {

View File

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