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({
_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.

View File

@ -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;

View File

@ -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;
}
},

View File

@ -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;

View File

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

View File

@ -19,7 +19,7 @@
<fieldset>
<div class="form-group">
<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>
</div>
</fieldset>
@ -28,7 +28,7 @@
<fieldset>
<div class="form-group">
<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>
</div>
</fieldset>

View File

@ -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)'));
});
},
/**