|
@@ -3,7 +3,13 @@ import { connect } from 'react-redux'
|
|
|
import { withStyles } from 'material-ui/styles'
|
|
|
import Button from 'material-ui/Button'
|
|
|
import Base from '../common/Base'
|
|
|
-import DataTable from '../common/DataTable'
|
|
|
+import Paper from 'material-ui/Paper'
|
|
|
+import Table, { TableHead, TableBody, TableRow, TableCell } from 'material-ui/Table'
|
|
|
+import Dialog, { DialogActions, DialogContent, DialogContentText, DialogTitle } from 'material-ui/Dialog'
|
|
|
+import TextField from 'material-ui/TextField'
|
|
|
+import { isEqual, isEmpty } from 'lodash'
|
|
|
+import { ODOO } from '../../constants/ResourceNames'
|
|
|
+import { post } from '../../actions'
|
|
|
|
|
|
const styles = theme => ({
|
|
|
gap: {
|
|
@@ -12,64 +18,157 @@ const styles = theme => ({
|
|
|
})
|
|
|
|
|
|
class TasksList extends Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props)
|
|
|
+
|
|
|
+ this.state = {
|
|
|
+ isDialogOpened: false,
|
|
|
+ isDialogValid: true,
|
|
|
+ name: '',
|
|
|
+ nameConfirmation: ''
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ handleOpenDialog = e => {
|
|
|
+ this.setState({
|
|
|
+ isDialogOpened: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ handleCloseDialog = e => {
|
|
|
+ this.setState({
|
|
|
+ isDialogOpened: false,
|
|
|
+ isDialogValid: true,
|
|
|
+ name: '',
|
|
|
+ nameConfirmation: ''
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ handleChangeName = e => {
|
|
|
+ if (isEqual(e.target.id, 'name')) {
|
|
|
+ this.setState({
|
|
|
+ name: e.target.value
|
|
|
+ }, this.handleStateChange)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEqual(e.target.id, 'nameConfirmation')) {
|
|
|
+ this.setState({
|
|
|
+ nameConfirmation: e.target.value
|
|
|
+ }, this.handleStateChange)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
- * @param {*} e
|
|
|
*/
|
|
|
- onAction(e) {
|
|
|
- console.log(e)
|
|
|
+ handleStateChange = () => {
|
|
|
+ if (isEqual(this.state.name, this.state.nameConfirmation)) {
|
|
|
+ this.setState({
|
|
|
+ isDialogValid: true
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.setState({
|
|
|
+ isDialogValid: false
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
- * @param {*} e
|
|
|
- * @param {*} ids
|
|
|
*/
|
|
|
- onSelect(e, ids) {
|
|
|
+ handleAcceptDialog = e => {
|
|
|
+ const { name, nameConfirmation } = this.state
|
|
|
+
|
|
|
+ if (isEmpty(name) || isEmpty(nameConfirmation)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEqual(name, nameConfirmation)) {
|
|
|
+ this.props.createOdoo(name)
|
|
|
|
|
|
+ this.setState({
|
|
|
+ isDialogOpened: false,
|
|
|
+ name: '',
|
|
|
+ nameConfirmation: ''
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
render() {
|
|
|
- const columns = [
|
|
|
- {
|
|
|
- title: 'Nombre',
|
|
|
- key: 'title'
|
|
|
- },
|
|
|
- {
|
|
|
- title: 'Última Ejecución',
|
|
|
- key: 'last_execution'
|
|
|
- }
|
|
|
- ]
|
|
|
-
|
|
|
- const { tasks } = this.props
|
|
|
+ const { isDialogOpened, isDialogValid } = this.state
|
|
|
|
|
|
return (
|
|
|
<Base title={this.props.title}>
|
|
|
- <Button variant='raised' color='primary' onClick={e => this.onAction(e)}>Ejecutar</Button>
|
|
|
- <DataTable
|
|
|
- columns={columns}
|
|
|
- rows={tasks}
|
|
|
- onSelect={(e, ids) => this.onSelect(e, ids)}
|
|
|
- />
|
|
|
+ <Paper>
|
|
|
+ <Table>
|
|
|
+ <TableHead>
|
|
|
+ <TableRow>
|
|
|
+ <TableCell>Nombre</TableCell>
|
|
|
+ <TableCell>Última ejecución</TableCell>
|
|
|
+ <TableCell>Usuario</TableCell>
|
|
|
+ <TableCell />
|
|
|
+ </TableRow>
|
|
|
+ </TableHead>
|
|
|
+ <TableBody>
|
|
|
+ <TableRow>
|
|
|
+ <TableCell>Crear contenedor Odoo</TableCell>
|
|
|
+ <TableCell>Nunca</TableCell>
|
|
|
+ <TableCell>Anónimo</TableCell>
|
|
|
+ <TableCell>
|
|
|
+ <Button variant='raised' color='primary' data-action='create' onClick={this.handleOpenDialog}>Ejecutar</Button>
|
|
|
+ </TableCell>
|
|
|
+ </TableRow>
|
|
|
+ </TableBody>
|
|
|
+ </Table>
|
|
|
+ </Paper>
|
|
|
+ <Dialog open={isDialogOpened} onClose={this.handleCloseDialog}>
|
|
|
+ <DialogTitle>Confirmar</DialogTitle>
|
|
|
+ <DialogContent>
|
|
|
+ <DialogContentText>Estas solicitando crear un contenedor Odoo. Tenga en cuenta que ésta tarea puede tardar unos instantes dependiendo del tráfico de red y el uso de los recursos del servidor</DialogContentText>
|
|
|
+ <TextField
|
|
|
+ id='name'
|
|
|
+ margin='dense'
|
|
|
+ label='Nombre del sistema'
|
|
|
+ type='text'
|
|
|
+ autoComplete='off'
|
|
|
+ autoFocus
|
|
|
+ fullWidth
|
|
|
+ onKeyUp={this.handleChangeName}
|
|
|
+ />
|
|
|
+ <TextField
|
|
|
+ id='nameConfirmation'
|
|
|
+ margin='dense'
|
|
|
+ label='Nombre del sistema'
|
|
|
+ type='text'
|
|
|
+ autoComplete='off'
|
|
|
+ fullWidth
|
|
|
+ error={!isDialogValid}
|
|
|
+ onKeyUp={this.handleChangeName}
|
|
|
+ />
|
|
|
+ </DialogContent>
|
|
|
+ <DialogActions>
|
|
|
+ <Button color='primary' onClick={this.handleCloseDialog}>Cancelar</Button>
|
|
|
+ <Button color='primary' onClick={this.handleAcceptDialog}>Aceptar</Button>
|
|
|
+ </DialogActions>
|
|
|
+ </Dialog>
|
|
|
</Base>
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- *
|
|
|
- * @param {*} state
|
|
|
- * @param {*} props
|
|
|
- */
|
|
|
-const mapStateToProps = (state, props) => {
|
|
|
- return {
|
|
|
- tasks: []
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
*
|
|
|
* @param {*} dispatch
|
|
@@ -79,11 +178,13 @@ const mapDispatchToProps = (dispatch, props) => ({
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- loadData() {
|
|
|
-
|
|
|
+ createOdoo(name) {
|
|
|
+ dispatch(post(`${ODOO}create/`, {
|
|
|
+ name
|
|
|
+ }))
|
|
|
}
|
|
|
})
|
|
|
|
|
|
TasksList = withStyles(styles)(TasksList)
|
|
|
|
|
|
-export default connect(mapStateToProps, mapDispatchToProps)(TasksList)
|
|
|
+export default connect(null, mapDispatchToProps)(TasksList)
|