2017-04-12 08:27:57 -04:00
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
2016-05-26 12:11:55 -07:00
// See License.txt for license information.
import React from 'react' ;
import * as Utils from 'utils/utils.jsx' ;
2016-06-28 14:53:36 -04:00
import { FormattedMessage , FormattedHTMLMessage } from 'react-intl' ;
2016-05-26 12:11:55 -07:00
2017-01-27 11:39:13 +01:00
import { reloadConfig } from 'actions/admin_actions.jsx' ;
2016-05-26 12:11:55 -07:00
export default class ReloadConfigButton extends React . Component {
constructor ( props ) {
super ( props ) ;
this . handleReloadConfig = this . handleReloadConfig . bind ( this ) ;
this . state = {
loading : false ,
fail : null
} ;
}
handleReloadConfig ( e ) {
e . preventDefault ( ) ;
this . setState ( {
loading : true ,
fail : null
} ) ;
2017-01-27 11:39:13 +01:00
reloadConfig (
2016-05-26 12:11:55 -07:00
( ) => {
this . setState ( {
loading : false
} ) ;
} ,
( err ) => {
this . setState ( {
loading : false ,
fail : err . message + ' - ' + err . detailed _error
} ) ;
}
) ;
}
render ( ) {
2016-06-04 11:22:42 -07:00
if ( global . window . mm _license . IsLicensed !== 'true' ) {
2016-09-23 12:29:54 -04:00
return < div / > ;
2016-06-04 11:22:42 -07:00
}
2016-05-26 12:11:55 -07:00
let testMessage = null ;
if ( this . state . fail ) {
testMessage = (
< div className = 'alert alert-warning' >
2016-09-23 12:29:54 -04:00
< i className = 'fa fa-warning' / >
2016-05-26 12:11:55 -07:00
< FormattedMessage
id = 'admin.reload.reloadFail'
defaultMessage = 'Reload unsuccessful: {error}'
values = { {
error : this . state . fail
} }
/ >
< / div >
) ;
}
2016-09-23 12:29:54 -04:00
const helpText = (
2016-06-28 14:53:36 -04:00
< FormattedHTMLMessage
id = 'admin.reload.reloadDescription'
defaultMessage = 'Deployments using multiple databases can switch from one master database to another without restarting the Mattermost server by updating "config.json" to the new desired configuration and using the <b>Reload Configuration from Disk</b> feature to load the new settings while the server is running. The administrator should then use the <a href="../advanced/database"><b>Database > Recycle Database Connections</b></a> feature to recycle the database connections based on the new settings.'
/ >
) ;
2016-05-26 12:11:55 -07:00
let contents = null ;
if ( this . state . loading ) {
contents = (
< span >
2016-07-06 00:46:36 +05:00
< span className = 'fa fa-refresh icon--rotate' / >
2016-05-26 12:11:55 -07:00
{ Utils . localizeMessage ( 'admin.reload.loading' , ' Loading...' ) }
< / span >
) ;
} else {
contents = (
< FormattedMessage
id = 'admin.reload.button'
defaultMessage = 'Reload Configuration From Disk'
/ >
) ;
}
return (
< div className = 'form-group reload-config' >
< div className = 'col-sm-offset-4 col-sm-8' >
< div >
< button
className = 'btn btn-default'
onClick = { this . handleReloadConfig }
>
{ contents }
< / button >
{ testMessage }
< / div >
2016-06-28 14:53:36 -04:00
< div className = 'help-text' >
{ helpText }
< / div >
2016-05-26 12:11:55 -07:00
< / div >
< / div >
) ;
}
2016-06-28 14:53:36 -04:00
}