diff --git a/core/client/components/gh-file-upload.js b/core/client/components/gh-file-upload.js index 98d3e8c5a6..5f0cc27074 100644 --- a/core/client/components/gh-file-upload.js +++ b/core/client/components/gh-file-upload.js @@ -1,17 +1,22 @@ var FileUpload = Ember.Component.extend({ _file: null, + uploadButtonText: 'Text', + uploadButtonDisabled: true, + change: function (event) { this.set('uploadButtonDisabled', false); this.sendAction('onAdd'); this._file = event.target.files[0]; }, + + onUpload: 'onUpload', + actions: { upload: function () { - var self = this; - if (!this.uploadButtonDisabled && self._file) { - self.sendAction('onUpload', self._file); + if (!this.uploadButtonDisabled && this._file) { + this.sendAction('onUpload', this._file); } // Prevent double post by disabling the button. diff --git a/core/client/controllers/debug.js b/core/client/controllers/debug.js index 875e44d1e4..4055ed3cb3 100644 --- a/core/client/controllers/debug.js +++ b/core/client/controllers/debug.js @@ -1,37 +1,66 @@ -/*global alert, console */ - -var Debug = Ember.Controller.extend(Ember.Evented, { +var DebugController = Ember.Controller.extend(Ember.Evented, { uploadButtonText: 'Import', + + exportPath: function () { + return this.get('ghostPaths').apiUrl('db'); + }.property(), + actions: { - importData: function (file) { - var self = this; + onUpload: function (file) { + var self = this, + formData = new FormData(); + this.set('uploadButtonText', 'Importing'); - this.get('model').importFrom(file) - .then(function (response) { - console.log(response); - alert('@TODO: success'); - }) - .catch(function (response) { - console.log(response); - alert('@TODO: error'); - }) - .finally(function () { - self.set('uploadButtonText', 'Import'); - self.trigger('reset'); - }); + + formData.append('importfile', file); + + ic.ajax.request(this.get('ghostPaths').apiUrl('db'), { + type: 'POST', + headers: { + 'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content') + }, + data: formData, + dataType: 'json', + cache: false, + contentType: false, + processData: false + }).then(function () { + self.notifications.showSuccess('Import successful.'); + }).catch(function (response) { + self.notifications.showErrors(response); + }).finally(function () { + self.set('uploadButtonText', 'Import'); + self.trigger('reset'); + }); }, + + exportData: function () { + var self = this; + + ic.ajax.request(this.get('ghostPaths').apiUrl('db'), { + type: 'GET' + }).then(function () { + self.notifications.showSuccess('Data exported successfully.'); + }).catch(function (response) { + self.notifications.showErrors(response); + }); + }, + sendTestEmail: function () { - this.get('model').sendTestEmail() - .then(function (response) { - console.log(response); - alert('@TODO: success'); - }) - .catch(function (response) { - console.log(response); - alert('@TODO: error'); - }); + var self = this; + + ic.ajax.request(this.get('ghostPaths').apiUrl('mail', 'test'), { + type: 'POST', + headers: { + 'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content') + } + }).then(function () { + self.notifications.showSuccess('Check your email for the test message:'); + }).catch(function (response) { + self.notifications.showErrors(response); + }); } } }); -export default Debug; +export default DebugController; diff --git a/core/client/controllers/modals/delete-all.js b/core/client/controllers/modals/delete-all.js index b63571f54a..6662381a09 100644 --- a/core/client/controllers/modals/delete-all.js +++ b/core/client/controllers/modals/delete-all.js @@ -1,15 +1,22 @@ -/*global alert */ - var DeleteAllController = Ember.Controller.extend({ actions: { confirmAccept: function () { - alert('Deleting everything!'); + var self = this; - this.notifications.showSuccess('Everything has been deleted.'); + ic.ajax.request(this.get('ghostPaths').apiUrl('db'), { + type: 'DELETE', + headers: { + 'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content') + } + }).then(function () { + self.notifications.showSuccess('All content deleted from database.'); + }).catch(function (response) { + self.notifications.showErrors(response); + }); }, confirmReject: function () { - return true; + return false; } }, diff --git a/core/client/routes/debug.js b/core/client/routes/debug.js index b63eba2f6d..9cd9fc976a 100644 --- a/core/client/routes/debug.js +++ b/core/client/routes/debug.js @@ -1,12 +1,15 @@ import styleBody from 'ghost/mixins/style-body'; import AuthenticatedRoute from 'ghost/routes/authenticated'; -import SettingsModel from 'ghost/models/settings'; import loadingIndicator from 'ghost/mixins/loading-indicator'; -export default AuthenticatedRoute.extend(styleBody, loadingIndicator, { +var DebugRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, { classNames: ['settings'], model: function () { - return SettingsModel.create(); + return this.store.find('setting', { type: 'blog,theme' }).then(function (records) { + return records.get('firstObject'); + }); } }); + +export default DebugRoute; diff --git a/core/client/templates/components/gh-file-upload.hbs b/core/client/templates/components/gh-file-upload.hbs index 9aa605e4ca..f36930b6eb 100644 --- a/core/client/templates/components/gh-file-upload.hbs +++ b/core/client/templates/components/gh-file-upload.hbs @@ -1,4 +1,4 @@ -
- logo - -
+ + diff --git a/core/client/templates/debug.hbs b/core/client/templates/debug.hbs index e2178eb714..6288a15166 100644 --- a/core/client/templates/debug.hbs +++ b/core/client/templates/debug.hbs @@ -19,7 +19,7 @@
- Export + Export

Export the blog settings and data.

@@ -28,7 +28,7 @@
- {{gh-file-upload onUpload="importData" uploadButtonText=uploadButtonText}} + {{gh-file-upload id="importfile" uploadButtonText=uploadButtonText}}

Import from another Ghost installation. If you import a user, this will replace the current user & log you out.

diff --git a/core/server/api/db.js b/core/server/api/db.js index bd614f4666..5f993130f4 100644 --- a/core/server/api/db.js +++ b/core/server/api/db.js @@ -119,7 +119,7 @@ db = { }).then(function importSuccess() { return api.settings.updateSettingsCache(); }).then(function () { - return when.resolve({ db: [] }); + return when.resolve({ message: 'Import successful', db: [] }); }).otherwise(function importFailure(error) { return when.reject(new errors.InternalServerError(error.message || error)); }).finally(function () { @@ -127,7 +127,7 @@ db = { return nodefn.call(fs.unlink, options.importfile.path); }); }, function () { - return when.reject(new errors.NoPermissionError('You do not have permission to export data. (no rights)')); + return when.reject(new errors.NoPermissionError('You do not have permission to import data. (no rights)')); }); }, /**