2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00
Ghost/core/server/controllers/admin.js
Kevin Ansfield 7ac6ebb920 Refactor notifications service & components
issue #5409

- change persistent/passive notification status to alert/notification
- replace showSuccess/Info/Warn/Error with showNotification/showAlert
- fix and clean up notification/alert components
2015-07-28 12:26:11 +01:00

54 lines
1.9 KiB
JavaScript

var _ = require('lodash'),
api = require('../api'),
errors = require('../errors'),
updateCheck = require('../update-check'),
config = require('../config'),
adminControllers;
adminControllers = {
// Route: index
// Path: /ghost/
// Method: GET
index: function index(req, res) {
/*jslint unparam:true*/
function renderIndex() {
return api.configuration.browse().then(function then(data) {
var apiConfig = _.omit(data.configuration, function omit(value) {
return _.contains(['environment', 'database', 'mail', 'version'], value.key);
});
res.render('default', {
skip_google_fonts: config.isPrivacyDisabled('useGoogleFonts'),
configuration: apiConfig
});
});
}
updateCheck().then(function then() {
return updateCheck.showUpdateNotification();
}).then(function then(updateVersion) {
if (!updateVersion) {
return;
}
var notification = {
type: 'upgrade',
location: 'settings-about-upgrade',
dismissible: false,
status: 'alert',
message: 'Ghost ' + updateVersion + ' is available! Hot Damn. <a href="http://support.ghost.org/how-to-upgrade/" target="_blank">Click here</a> to upgrade.'
};
return api.notifications.browse({context: {internal: true}}).then(function then(results) {
if (!_.some(results.notifications, {message: notification.message})) {
return api.notifications.add({notifications: [notification]}, {context: {internal: true}});
}
});
}).finally(function noMatterWhat() {
renderIndex();
}).catch(errors.logError);
}
};
module.exports = adminControllers;