提交 057b5806 编写于 作者: R rsercano

resolves #358

上级 e573e43a
......@@ -104,7 +104,7 @@
<h4 id="importExportMongoclientTitle" class="modal-title">Import Mongoclient Data</h4>
</div>
<div class="modal-body">
<form id="frmImportMongoclient" class="form-horizontal" style="display: none">
<form id="frmImportMongoclient" class="form-horizontal">
<div class="form-group">
<label class="col-lg-3 control-label">Backup File </label>
<div class="col-lg-9">
......@@ -114,17 +114,6 @@
</div>
</div>
</form>
<form id="frmExportMongoclient" class="form-horizontal" style="display: none">
<div class="form-group">
<label class="col-lg-3 control-label">Place to Export </label>
<div class="col-lg-9">
<input class="form-control" type="text" id="inputExportBackupDir"
data-buttonName="btn-primary">
<span class="help-block m-b-none">Example: <b>/home/user/mongoclient/</b></span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<div class="pull-left">
......
......@@ -79,11 +79,9 @@ Template.topNavbar.events({
'click #btnProceedImportExport'(e) {
e.preventDefault();
let laddaButton = Ladda.create(document.querySelector('#btnProceedImportExport'));
let isImport = $('#importExportMongoclientTitle').text() == 'Import Mongoclient Data';
let importInput = $('#inputImportBackupFile');
let exportInput = $('#inputExportBackupDir');
if (isImport && importInput.val()) {
if (importInput.val()) {
laddaButton.start();
loadFile(null, importInput, function (val) {
Meteor.call('importMongoclient', val, function (err) {
......@@ -98,20 +96,6 @@ Template.topNavbar.events({
});
}, true);
}
else if (!isImport && exportInput.val()) {
laddaButton.start();
Meteor.call('exportMongoclient', exportInput.val(), function (err, path) {
if (err) {
toastr.error("Couldn't export: " + err.message);
} else {
toastr.success("Successfully exported to " + path.result);
$('#importExportMongoclientModal').modal('hide');
}
Ladda.stopAll();
});
}
},
'change .filestyle'(e){
......@@ -132,14 +116,7 @@ Template.topNavbar.events({
'click #btnExportMongoclient' (e) {
e.preventDefault();
let icon = $('#importExportMongoclientIcon');
$('#importExportMongoclientTitle').text('Export Mongoclient Data');
icon.removeClass('fa-download');
icon.addClass('fa-upload');
$('#btnProceedImportExport').text('Export');
$('#frmImportMongoclient').hide();
$('#frmExportMongoclient').show();
$('#importExportMongoclientModal').modal('show');
window.open('exportMongoclient');
},
'click #btnImportMongoclient' (e) {
......
......@@ -27,7 +27,7 @@ const proceedFindQuery = function (selectedCollection, selector, cursorOptions,
};
if (exportFormat) {
window.open('export?format=' + exportFormat + '&selectedCollection=' + selectedCollection + "&selector=" + JSON.stringify(selector) + "&cursorOptions=" + JSON.stringify(cursorOptions));
window.open('export?format=' + exportFormat + '&selectedCollection=' + selectedCollection + "&selector=" + JSON.stringify(selector) + "&cursorOptions=" + JSON.stringify(cursorOptions) + "&sessionId=" + Meteor.default_connection._lastSessionId);
Ladda.stopAll();
} else {
Meteor.call("find", selectedCollection, selector, cursorOptions, executeExplain, Meteor.default_connection._lastSessionId, function (err, result) {
......
......@@ -215,26 +215,6 @@ Meteor.methods({
}
},
exportMongoclient(dir) {
let filePath = dir + "/backup_" + moment().format('DD_MM_YYYY_HH_mm_ss') + ".json";
let fileContent = {};
fileContent.settings = Settings.findOne();
fileContent.connections = Connections.find().fetch();
LOGGER.info('[exportMongoclient]', filePath);
return Async.runSync(function (done) {
try {
fs.writeFile(filePath, JSON.stringify(fileContent), function (err) {
done(err, filePath);
});
} catch (ex) {
LOGGER.error('[exportMongoclient]', ex);
done(new Meteor.Error(ex.message), null);
}
});
},
listCollectionNames(dbName, sessionId) {
LOGGER.info('[listCollectionNames]', dbName, sessionId);
......
......@@ -4,21 +4,40 @@
import {WebApp} from "meteor/webapp";
import {Meteor} from "meteor/meteor";
import {Papa} from "meteor/harrison:papa-parse";
import {Settings} from "/lib/imports/collections/settings";
import {Connections} from "/lib/imports/collections/connections";
import {databasesBySessionId} from "/server/imports/mongodb/methods_common";
import LOGGER from "/server/imports/internal/logger";
const mongodbApi = require('mongodb');
WebApp.connectHandlers.use('/exportMongoclient', function (req, res) {
let fileContent = {};
fileContent.settings = Settings.findOne();
fileContent.connections = Connections.find().fetch();
let fileName = "backup_" + moment().format('DD_MM_YYYY_HH_mm_ss') + ".json";
LOGGER.info('[exportMongoclient]', fileContent, fileName);
const headers = {
'Content-type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename=' + fileName
};
res.writeHead(200, headers);
res.end(JSON.stringify(fileContent));
});
WebApp.connectHandlers.use('/export', function (req, res) {
const urlParts = decodeURI(req.url).split('&');
const format = urlParts[0].substr(urlParts[0].indexOf('=') + 1);
const selectedCollection = urlParts[1].substr(urlParts[1].indexOf('=') + 1);
const selector = urlParts[2].substr(urlParts[2].indexOf('=') + 1);
const cursorOptions = urlParts[3].substr(urlParts[3].indexOf('=') + 1);
const sessionId = urlParts[4].substr(urlParts[4].indexOf('=') + 1);
LOGGER.info('[export]', format, selectedCollection, selector, cursorOptions);
LOGGER.info('[export]', format, selectedCollection, selector, cursorOptions, sessionId);
Meteor.call("find", selectedCollection, JSON.parse(selector), JSON.parse(cursorOptions), false, Meteor.default_connection._lastSessionId, function (err, result) {
Meteor.call("find", selectedCollection, JSON.parse(selector), JSON.parse(cursorOptions), false, sessionId, function (err, result) {
if (err || result.error) {
LOGGER.error('[export]', err, result.error);
res.writeHead(400);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册