| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
const { __ } = wp.i18n; |
| 5 |
|
| 6 |
const { Component } = wp.element; |
| 7 |
|
| 8 |
const { |
| 9 |
Button, |
| 10 |
Modal, |
| 11 |
PanelBody, |
| 12 |
SelectControl |
| 13 |
} = wp.components; |
| 14 |
|
| 15 |
/** |
| 16 |
* Internal dependencies |
| 17 |
*/ |
| 18 |
import SQLEditor from './SQLEditor.js'; |
| 19 |
|
| 20 |
class DataImport extends Component { |
| 21 |
constructor() { |
| 22 |
super( ...arguments ); |
| 23 |
this.save = this.save.bind( this ); |
| 24 |
|
| 25 |
this.state = { |
| 26 |
isOpen: false |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
save( query, name, series, data ) { |
| 31 |
this.props.databaseImportData( query, name, series, data ); |
| 32 |
this.setState({ isOpen: false }); |
| 33 |
} |
| 34 |
|
| 35 |
render() { |
| 36 |
if ( ( 'business' !== visualizerLocalize.isPro ) ) { |
| 37 |
return ( |
| 38 |
<PanelBody |
| 39 |
title={ __( 'Import data from database' ) } |
| 40 |
icon="lock" |
| 41 |
initialOpen={ false } |
| 42 |
> |
| 43 |
|
| 44 |
<p>{ __( 'Upgrade your license to at least the DEVELOPER version to activate this feature!' ) }</p> |
| 45 |
|
| 46 |
<Button |
| 47 |
isPrimary |
| 48 |
href={ visualizerLocalize.proTeaser } |
| 49 |
target="_blank" |
| 50 |
> |
| 51 |
{ __( 'Upgrade Now' ) } |
| 52 |
</Button> |
| 53 |
|
| 54 |
</PanelBody> |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
return ( |
| 59 |
<PanelBody |
| 60 |
title={ __( 'Import data from database' ) } |
| 61 |
initialOpen={ false } |
| 62 |
> |
| 63 |
|
| 64 |
<p>{ __( 'You can import data from the database here.' ) }</p> |
| 65 |
|
| 66 |
<p>{ __( 'How often do you want to refresh the data from the database.' ) }</p> |
| 67 |
|
| 68 |
<SelectControl |
| 69 |
label={ __( 'How often do you want to check the url?' ) } |
| 70 |
value={ this.props.chart['visualizer-db-schedule'] ? this.props.chart['visualizer-db-schedule'] : 0 } |
| 71 |
options={ [ |
| 72 |
{ label: __( 'Live' ), value: '0' }, |
| 73 |
{ label: __( 'Each hour' ), value: '1' }, |
| 74 |
{ label: __( 'Each 12 hours' ), value: '12' }, |
| 75 |
{ label: __( 'Each day' ), value: '24' }, |
| 76 |
{ label: __( 'Each 3 days' ), value: '72' } |
| 77 |
] } |
| 78 |
onChange={ this.props.editSchedule } |
| 79 |
/> |
| 80 |
|
| 81 |
<Button |
| 82 |
isPrimary |
| 83 |
isLarge |
| 84 |
onClick={ () => this.setState({ isOpen: true }) } |
| 85 |
> |
| 86 |
{ __( 'Create Query' ) } |
| 87 |
</Button> |
| 88 |
|
| 89 |
{ this.state.isOpen && ( |
| 90 |
<Modal |
| 91 |
title={ __( 'Import from database' ) } |
| 92 |
onRequestClose={ () => this.setState({ isOpen: false }) } |
| 93 |
className="visualizer-db-query-modal" |
| 94 |
shouldCloseOnClickOutside={ false } |
| 95 |
> |
| 96 |
<SQLEditor |
| 97 |
chart={ this.props.chart } |
| 98 |
changeQuery={ this.props.changeQuery } |
| 99 |
save={ this.save } |
| 100 |
/> |
| 101 |
</Modal> |
| 102 |
)} |
| 103 |
|
| 104 |
</PanelBody> |
| 105 |
); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
export default DataImport; |
| 110 |
|