Skip to content

Commit

Permalink
Fixing notifications on ugly debug page
Browse files Browse the repository at this point in the history
- also fixes an issue where the debug tools didn't redirect properly when Ghost was operating in a subdirectory.
  • Loading branch information
ErisDS committed Dec 30, 2013
1 parent 91ef493 commit 158b92c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
41 changes: 22 additions & 19 deletions core/server/api/db.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
var dataExport = require('../data/export'),
dataImport = require('../data/import'),
dataProvider = require('../models'),
notifications = require('./notifications'),
settings = require('./settings'),
fs = require('fs-extra'),
path = require('path'),
when = require('when'),
nodefn = require('when/node/function'),
_ = require('underscore'),
schema = require('../data/schema'),
config = require('../config'),
debugPath = config.paths().subdir + '/ghost/debug/',
configPaths = require('../config/paths'),
api = {},

db;

api.notifications = require('./notifications');
api.settings = require('./settings');

db = {
'export': function (req, res) {
/*jslint unparam:true*/
return dataExport().then(function (exportedData) {
// Save the exported data to the file system for download
var fileName = path.resolve(__dirname + '/../../server/data/export/exported-' + (new Date().getTime()) + '.json');
var fileName = path.join(configPaths().exportPath, 'exported-' + (new Date().getTime()) + '.json');

return nodefn.call(fs.writeFile, fileName, JSON.stringify(exportedData)).then(function () {
return when(fileName);
Expand All @@ -29,16 +30,16 @@ db = {
res.download(exportedFilePath, 'GhostData.json');
}).otherwise(function (error) {
// Notify of an error if it occurs
return notifications.browse().then(function (notifications) {
return api.notifications.browse().then(function (notifications) {
var notification = {
type: 'error',
message: error.message || error,
status: 'persistent',
id: 'per-' + (notifications.length + 1)
};

return notifications.add(notification).then(function () {
res.redirect(debugPath);
return api.notifications.add(notification).then(function () {
res.redirect(configPaths().debugPath);
});
});
});
Expand All @@ -56,21 +57,23 @@ db = {
* - If there is no path
* - If the name doesn't have json in it
*/
return notifications.browse().then(function (notifications) {
return api.notifications.browse().then(function (notifications) {
notification = {
type: 'error',
message: "Must select a .json file to import",
status: 'persistent',
id: 'per-' + (notifications.length + 1)
};

return notifications.add(notification).then(function () {
res.redirect(debugPath);


return api.notifications.add(notification).then(function () {
res.redirect(configPaths().debugPath);
});
});
}

settings.read({ key: 'databaseVersion' }).then(function (setting) {
api.settings.read({ key: 'databaseVersion' }).then(function (setting) {
return when(setting.value);
}, function () {
return when('001');
Expand Down Expand Up @@ -127,9 +130,9 @@ db = {
return dataImport(databaseVersion, importData);

}).then(function importSuccess() {
return settings.updateSettingsCache();
return api.settings.updateSettingsCache();
}).then(function () {
return notifications.browse();
return api.notifications.browse();
}).then(function (notifications) {
notification = {
type: 'success',
Expand All @@ -138,11 +141,11 @@ db = {
id: 'per-' + (notifications.length + 1)
};

return notifications.add(notification).then(function () {
res.redirect(debugPath);
return api.notifications.add(notification).then(function () {
res.redirect(configPaths().debugPath);
});
}).otherwise(function importFailure(error) {
return notifications.browse().then(function (notifications) {
return api.notifications.browse().then(function (notifications) {
// Notify of an error if it occurs
notification = {
type: 'error',
Expand All @@ -151,8 +154,8 @@ db = {
id: 'per-' + (notifications.length + 1)
};

return notifications.add(notification).then(function () {
res.redirect(debugPath);
return api.notifications.add(notification).then(function () {
res.redirect(configPaths().debugPath);
});
});
});
Expand Down
6 changes: 5 additions & 1 deletion core/server/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ var path = require('path'),


function paths() {
var subdir = localPath === '/' ? '' : localPath;

return {
'appRoot': appRoot,
'subdir': localPath === '/' ? '' : localPath,
'subdir': subdir,
'config': path.join(appRoot, 'config.js'),
'configExample': path.join(appRoot, 'config.example.js'),
'contentPath': contentPath,
Expand All @@ -32,7 +34,9 @@ function paths() {
'imagesRelPath': 'content/images',
'adminViews': path.join(corePath, '/server/views/'),
'helperTemplates': path.join(corePath, '/server/helpers/tpl/'),
'exportPath': path.join(corePath, '/server/data/export/'),
'lang': path.join(corePath, '/shared/lang/'),
'debugPath': subdir + '/ghost/debug/',
'availableThemes': availableThemes,
'availablePlugins': availablePlugins
};
Expand Down
2 changes: 2 additions & 0 deletions core/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ describe('Config', function () {
'imagesRelPath',
'adminViews',
'helperTemplates',
'exportPath',
'lang',
'debugPath',
'availableThemes',
'availablePlugins'
);
Expand Down

0 comments on commit 158b92c

Please sign in to comment.