2014-07-21 20:00:54 +02:00
var _ = require ( 'lodash' ) ,
2014-07-09 04:17:30 +00:00
api = require ( '../api' ) ,
2014-05-09 12:11:29 +02:00
errors = require ( '../errors' ) ,
2014-01-03 15:50:03 +00:00
updateCheck = require ( '../update-check' ) ,
2014-09-03 00:27:37 -04:00
config = require ( '../config' ) ,
2014-07-01 00:26:08 +01:00
adminControllers ;
2013-05-29 01:10:39 +01:00
2013-06-25 12:43:15 +01:00
adminControllers = {
2014-07-01 00:26:08 +01:00
// Route: index
// Path: /ghost/
// Method: GET
2015-05-30 21:18:26 +01:00
index : function index ( req , res ) {
2014-02-26 23:15:31 +00:00
/*jslint unparam:true*/
2014-05-09 00:00:10 -05:00
2014-02-25 10:51:12 +00:00
function renderIndex ( ) {
2015-05-30 21:18:26 +01:00
return api . configuration . browse ( ) . then ( function then ( data ) {
var apiConfig = _ . omit ( data . configuration , function omit ( value ) {
2014-11-27 21:50:15 +01:00
return _ . contains ( [ 'environment' , 'database' , 'mail' , 'version' ] , value . key ) ;
} ) ;
res . render ( 'default' , {
skip _google _fonts : config . isPrivacyDisabled ( 'useGoogleFonts' ) ,
configuration : apiConfig
} ) ;
2014-09-03 00:27:37 -04:00
} ) ;
2014-02-25 10:51:12 +00:00
}
2015-05-30 21:18:26 +01:00
updateCheck ( ) . then ( function then ( ) {
2014-07-09 04:17:30 +00:00
return updateCheck . showUpdateNotification ( ) ;
2015-05-30 21:18:26 +01:00
} ) . then ( function then ( updateVersion ) {
2014-08-06 00:48:44 +01:00
if ( ! updateVersion ) {
2014-08-17 06:17:23 +00:00
return ;
2014-07-09 04:17:30 +00:00
}
var notification = {
2015-04-29 21:54:53 +01:00
type : 'upgrade' ,
location : 'settings-about-upgrade' ,
2014-07-09 04:17:30 +00:00
dismissible : false ,
status : 'persistent' ,
2015-04-29 21:54:53 +01:00
message : 'Ghost ' + updateVersion + ' is available! Hot Damn. <a href="http://support.ghost.org/how-to-upgrade/" target="_blank">Click here</a> to upgrade.'
2014-07-09 04:17:30 +00:00
} ;
2015-05-30 21:18:26 +01:00
return api . notifications . browse ( { context : { internal : true } } ) . then ( function then ( results ) {
2014-09-10 00:06:24 -04:00
if ( ! _ . some ( results . notifications , { message : notification . message } ) ) {
return api . notifications . add ( { notifications : [ notification ] } , { context : { internal : true } } ) ;
2014-07-09 04:17:30 +00:00
}
} ) ;
2015-05-30 21:18:26 +01:00
} ) . finally ( function noMatterWhat ( ) {
2014-07-09 04:17:30 +00:00
renderIndex ( ) ;
} ) . catch ( errors . logError ) ;
2013-06-25 12:43:15 +01:00
}
} ;
2013-05-11 17:44:25 +01:00
2013-08-09 02:22:49 +01:00
module . exports = adminControllers ;