批量导出html完成, 支持导出笔记本下所有笔记

This commit is contained in:
life
2015-10-24 18:54:38 +08:00
parent 5f2ad33ffa
commit 29eaea0f7e
3 changed files with 154 additions and 38 deletions

View File

@@ -138,6 +138,17 @@ var Api = {
return me._exportMenus; return me._exportMenus;
}, },
// 导出, 笔记本下
_exportMenusForNotebook: [],
addExportMenuForNotebook: function(menu) {
var me = this;
me._exportMenusForNotebook.push(menu);
},
getExportMenusForNotebook: function() {
var me = this;
return me._exportMenusForNotebook;
},
// 更多菜单 // 更多菜单
_moreMenus: [], _moreMenus: [],
getMoreMenus: function() { getMoreMenus: function() {

View File

@@ -1149,7 +1149,7 @@ Notebook.init = function() {
this.menu.append(this.rename); this.menu.append(this.rename);
this.menu.append(this.del); this.menu.append(this.del);
// 导入菜单 // 导入菜单
var importMenus = Api.getImportMenus(); var importMenus = Api.getImportMenus();
if(importMenus && importMenus.length) { if(importMenus && importMenus.length) {
var importSubmenus = new gui.Menu(); var importSubmenus = new gui.Menu();
@@ -1168,9 +1168,43 @@ Notebook.init = function() {
submenu: importSubmenus, submenu: importSubmenus,
label: getMsg('Import notes') label: getMsg('Import notes')
}); });
this.menu.append(gui.getSeparatorMenu());
this.menu.append(this.imports); this.menu.append(this.imports);
} }
// 导出
var exportsSubMenus = new gui.Menu();
var exportMenus = Api.getExportMenusForNotebook() || [];
for(var i = 0; i < exportMenus.length; ++i) {
(function(j) {
var menu = exportMenus[j];
var clickBac = menu.click;
var menuItem = new gui.MenuItem({
label: menu.label,
click: function(e) {
var notebookId = $(me.target).attr('notebookId');
clickBac && clickBac(notebookId);
}
});
exportMenus[i].menu = menuItem;
exportsSubMenus.append(menuItem);
})(i);
}
if(exportMenus.length > 0) {
this.exports = new gui.MenuItem({
label: getMsg('Export notes'),
submenu: exportsSubMenus,
click: function(e) {
}
});
this.menu.append(this.exports);
}
this.enable = function(name, ok) { this.enable = function(name, ok) {
this[name].enabled = ok; this[name].enabled = ok;
} }

View File

@@ -167,13 +167,7 @@ define(function() {
}); });
}, },
loadingIsClosed: false, getTargetPath: function(callback) {
exportHTML: function (noteIds) {
var me = this;
if (!noteIds || noteIds.length == 0) {
return;
}
// showSaveDialog 不支持property选择文件夹 // showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(), Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{ {
@@ -181,48 +175,113 @@ define(function() {
properties: ['openDirectory'] properties: ['openDirectory']
}, },
function(targetPath) { function(targetPath) {
if(!targetPath) { callback(targetPath);
}
);
},
loadingIsClosed: false,
exportHTMLForNotebook: function (notebookId) {
var me = this;
if (!notebookId) {
return;
}
me.getTargetPath(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() {
me.hideLoading();
});
}});
Api.loading.setProgress(1);
Api.noteService.getNotes(notebookId, function(notes) {
if (!notes) {
me.hideLoading();
return; return;
} }
me.loadingIsClosed = false; var total = notes.length;
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 i = 0;
var total = noteIds.length; async.eachSeries(notes, function(note, cb) {
async.eachSeries(noteIds, function(noteId, cb) {
if (me.loadingIsClosed) { if (me.loadingIsClosed) {
cb(); cb();
me.hideLoading();
return; return;
} }
// setTimeout(function () {
i++; i++;
Api.loading.setProgress(100 * i / total); Api.loading.setProgress(100 * i / total);
Api.noteService.getNote(noteId, function(note) { me._exportHTML(note, targetPath, function() {
me._exportHTML(note, targetPath, function() { cb();
cb(); }, i, total);
}, i, total); }, function() {
}); me.hideLoading();
// }, i * 1000);
}, function () {
Api.loading.hide();
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')}); Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')});
}); });
});
});
},
hideLoading: function () {
setTimeout(function () {
Api.loading.hide();
}, 1000);
},
exportHTML: function (noteIds) {
var me = this;
if (!noteIds || noteIds.length == 0) {
return;
}
me.getTargetPath(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() {
me.hideLoading();
});
}});
Api.loading.setProgress(1);
var i = 0;
var total = noteIds.length;
async.eachSeries(noteIds, function(noteId, cb) {
if (me.loadingIsClosed) {
cb();
return;
}
i++;
Api.loading.setProgress(100 * i / total);
Api.noteService.getNote(noteId, function(note) {
me._exportHTML(note, targetPath, function() {
cb();
}, i, total);
});
}, function () {
me.hideLoading();
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')});
});
}); });
}, },
@@ -286,6 +345,18 @@ define(function() {
})() })()
}; };
Api.addExportMenu(menu); Api.addExportMenu(menu);
Api.addExportMenuForNotebook({
label: Api.getMsg('plugin.export_html.export'),
enabled: function(notebookId) {
return true;
},
click: (function() {
return function(notebookId) {
me.exportHTMLForNotebook(notebookId);
}
})()
});
}, },
// 打开后 // 打开后
onOpenAfter: function() { onOpenAfter: function() {