0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Finish Debug screen for Ember admin

Closes #2847
This commit is contained in:
Jason Williams 2014-06-23 14:24:37 +00:00
parent ca19017509
commit 39c0f219e6
7 changed files with 91 additions and 47 deletions

View file

@ -1,17 +1,22 @@
var FileUpload = Ember.Component.extend({ var FileUpload = Ember.Component.extend({
_file: null, _file: null,
uploadButtonText: 'Text', uploadButtonText: 'Text',
uploadButtonDisabled: true, uploadButtonDisabled: true,
change: function (event) { change: function (event) {
this.set('uploadButtonDisabled', false); this.set('uploadButtonDisabled', false);
this.sendAction('onAdd'); this.sendAction('onAdd');
this._file = event.target.files[0]; this._file = event.target.files[0];
}, },
onUpload: 'onUpload',
actions: { actions: {
upload: function () { upload: function () {
var self = this; if (!this.uploadButtonDisabled && this._file) {
if (!this.uploadButtonDisabled && self._file) { this.sendAction('onUpload', this._file);
self.sendAction('onUpload', self._file);
} }
// Prevent double post by disabling the button. // Prevent double post by disabling the button.

View file

@ -1,37 +1,66 @@
/*global alert, console */ var DebugController = Ember.Controller.extend(Ember.Evented, {
var Debug = Ember.Controller.extend(Ember.Evented, {
uploadButtonText: 'Import', uploadButtonText: 'Import',
exportPath: function () {
return this.get('ghostPaths').apiUrl('db');
}.property(),
actions: { actions: {
importData: function (file) { onUpload: function (file) {
var self = this; var self = this,
formData = new FormData();
this.set('uploadButtonText', 'Importing'); this.set('uploadButtonText', 'Importing');
this.get('model').importFrom(file)
.then(function (response) { formData.append('importfile', file);
console.log(response);
alert('@TODO: success'); ic.ajax.request(this.get('ghostPaths').apiUrl('db'), {
}) type: 'POST',
.catch(function (response) { headers: {
console.log(response); 'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
alert('@TODO: error'); },
}) data: formData,
.finally(function () { dataType: 'json',
self.set('uploadButtonText', 'Import'); cache: false,
self.trigger('reset'); 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 () { sendTestEmail: function () {
this.get('model').sendTestEmail() var self = this;
.then(function (response) {
console.log(response); ic.ajax.request(this.get('ghostPaths').apiUrl('mail', 'test'), {
alert('@TODO: success'); type: 'POST',
}) headers: {
.catch(function (response) { 'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
console.log(response); }
alert('@TODO: error'); }).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;

View file

@ -1,15 +1,22 @@
/*global alert */
var DeleteAllController = Ember.Controller.extend({ var DeleteAllController = Ember.Controller.extend({
actions: { actions: {
confirmAccept: function () { 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 () { confirmReject: function () {
return true; return false;
} }
}, },

View file

@ -1,12 +1,15 @@
import styleBody from 'ghost/mixins/style-body'; import styleBody from 'ghost/mixins/style-body';
import AuthenticatedRoute from 'ghost/routes/authenticated'; import AuthenticatedRoute from 'ghost/routes/authenticated';
import SettingsModel from 'ghost/models/settings';
import loadingIndicator from 'ghost/mixins/loading-indicator'; import loadingIndicator from 'ghost/mixins/loading-indicator';
export default AuthenticatedRoute.extend(styleBody, loadingIndicator, { var DebugRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, {
classNames: ['settings'], classNames: ['settings'],
model: function () { model: function () {
return SettingsModel.create(); return this.store.find('setting', { type: 'blog,theme' }).then(function (records) {
return records.get('firstObject');
});
} }
}); });
export default DebugRoute;

View file

@ -1,4 +1,4 @@
<section class="js-drop-zone"> <input data-url="upload" class="button-add" type="file" name="importfile" {{bind-attr accept=options.acceptEncoding}}>
<img class="js-upload-target" {{bind-attr src=src}} alt="logo"> <button type="submit" class="button-save" id="startupload" {{bind-attr disabled=uploadButtonDisabled}} {{action "upload"}}>
<input data-url="upload" class="js-fileupload main" type="file" name="uploadimage" {{#if options.acceptEncoding}}accept="{{options.acceptEncoding}}"{{/if}}> {{uploadButtonText}}
</section> </button>

View file

@ -19,7 +19,7 @@
<fieldset> <fieldset>
<div class="form-group"> <div class="form-group">
<label>Export</label> <label>Export</label>
<a class="button-save" {{bind-attr href=model.exportPath}}>Export</a> <a class="button-save" {{bind-attr href=exportPath}}>Export</a>
<p>Export the blog settings and data.</p> <p>Export the blog settings and data.</p>
</div> </div>
</fieldset> </fieldset>
@ -28,7 +28,7 @@
<fieldset> <fieldset>
<div class="form-group"> <div class="form-group">
<label>Import</label> <label>Import</label>
{{gh-file-upload onUpload="importData" uploadButtonText=uploadButtonText}} {{gh-file-upload id="importfile" uploadButtonText=uploadButtonText}}
<p>Import from another Ghost installation. If you import a user, this will replace the current user & log you out.</p> <p>Import from another Ghost installation. If you import a user, this will replace the current user & log you out.</p>
</div> </div>
</fieldset> </fieldset>

View file

@ -119,7 +119,7 @@ db = {
}).then(function importSuccess() { }).then(function importSuccess() {
return api.settings.updateSettingsCache(); return api.settings.updateSettingsCache();
}).then(function () { }).then(function () {
return when.resolve({ db: [] }); return when.resolve({ message: 'Import successful', db: [] });
}).otherwise(function importFailure(error) { }).otherwise(function importFailure(error) {
return when.reject(new errors.InternalServerError(error.message || error)); return when.reject(new errors.InternalServerError(error.message || error));
}).finally(function () { }).finally(function () {
@ -127,7 +127,7 @@ db = {
return nodefn.call(fs.unlink, options.importfile.path); return nodefn.call(fs.unlink, options.importfile.path);
}); });
}, function () { }, 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)'));
}); });
}, },
/** /**