Adding base version for Operations Module

This commit is contained in:
mati108@gmail.com committed 2018-12-26 19:41:13 -03:00
1 parent ae08794750
commit d397c87d68
64 files changed
+3524 -1

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import gql from 'graphql-tag';
import { clone } from '../Fragments';
const OPERATIONS_ADD_CLONE = gql`
mutation Operations_AddClone($clone: operations_CloneInput!) {
operations_AddClone(clone: $clone) {
...clone
}
}
${clone}
`;
const OPERATIONS_LIST_CLONES = gql`
query Operations_Clones{
operations_Clones {
...clone
}
}
${clone}
`;
const OPERATIONS_REMOVE_CLONE = gql`
mutation Operations_RemoveClone($id: ID!){
operations_RemoveClone( id: $id)
}
`;
export default {
OPERATIONS_LIST_CLONES,
OPERATIONS_ADD_CLONE,
OPERATIONS_REMOVE_CLONE
};
+7
View File
@@ -0,0 +1,7 @@
import clones from './clones';
import teams from './teams';
export {
clones,
teams
};
+38
View File
@@ -0,0 +1,38 @@
import gql from 'graphql-tag';
export const GET_ALL_TEAMS_QUERY = gql`
query Teams_FbByTeamMember {
teams_FbByTeamMember {
id
name
slug
fb {
id
name
slug
}
}
}
`
export const GET_ALL_TEAM_BOTS_QUERY = gql`
query teamBotsQuery($teamId: String!) {
teams_TeamById(teamId: $teamId) {
fb {
id
name
slug
team{
id
name
slug
}
}
}
}
`
export default {
GET_ALL_TEAMS_QUERY,
GET_ALL_TEAM_BOTS_QUERY
};
+20
View File
@@ -0,0 +1,20 @@
import gql from 'graphql-tag';
export const clone = gql`
fragment clone on operations_Clone {
id
authId
teamId
botId
mode
resumeExecution
beginDatetime
endDatetime
waitTime
state
stateDatetime
createDatetime
lastLogs
runAsTeam
}
`;
+5
View File
@@ -0,0 +1,5 @@
import { clone } from './clone';
export {
clone
};
+56
View File
@@ -0,0 +1,56 @@
import gql from 'graphql-tag'
const getSecret = gql`
query($id: ID!){
keyVault_Secret(id: $id)
}
`
const editCloneMutation = gql`
mutation($id: ID!, $type: String!, $description: String!, $validFrom: Int!,
$validTo: Int!, $active: Boolean!, $botId: ID!){
operations_EditClone(
id: $id,
type: $type,
description: $description,
validFrom: $validFrom,
validTo: $validTo,
active: $active,
botId: $botId
){
id
key
}
}
`
const getCloneQuery = gql`
query($id: ID!){
opeations_Clone(id: $id) {
id
authId
key
type
description
exchange
validFrom
validTo
active
botId
}
}
`
const getAuditLog = gql`
query($key: String!){
keyVault_AuditLogs(key: $key){
id,
date,
action,
details
}
}
`
export { getSecret, editCloneMutation,
getCloneQuery, getAuditLog }
+10
View File
@@ -0,0 +1,10 @@
const types = [ 'Live', 'Competition', 'Backtest' ]
const exchanges = [
{
id: '1',
name: 'Poloniex'
}
]
export { types, exchanges }
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+21
View File
@@ -0,0 +1,21 @@
import React, { Component } from 'react'
import { Route, Switch } from 'react-router-dom'
import { MuiPickersUtilsProvider } from 'material-ui-pickers'
import LuxonUtils from 'material-ui-pickers/utils/luxon-utils'
import BrowseClones from './views/Clone/List'
import AddClone from './views/Clone/Add'
import Home from './views/Home'
const App = () => (
<MuiPickersUtilsProvider utils={LuxonUtils}>
<Switch>
<Route exact path='/operations/' component={Home} />
<Route path='/operations/browse' component={BrowseClones} />
<Route path='/operations/add' component={AddClone} />
</Switch>
</MuiPickersUtilsProvider>
)
export default App
+71
View File
@@ -0,0 +1,71 @@
import { createMuiTheme } from '@material-ui/core/styles'
export const theme = createMuiTheme({
palette: {
primary: { main: '#303036' }, // DARK.
secondary: { main: '#CC5835' } // RUSTED_RED.
},
typography: {
fontFamily: '"Saira","Saira Condenses", sans-serif',
useNextVariants: true
},
overrides: {
Paper: {
root: {
backgroundColor: '#ffffff'
},
elevation: 0,
square: true
}
}
})
export const globalStyles = theme => ({
'@global': {
body: {
backgroundColor: theme.palette.common.white
}
},
appBar: {
position: 'relative'
},
toolbarTitle: {
flex: 1
},
layout: {
width: 'auto',
marginLeft: theme.spacing.unit * 3,
marginRight: theme.spacing.unit * 3,
[theme.breakpoints.up(900 + theme.spacing.unit * 3 * 2)]: {
width: 900,
marginLeft: 'auto',
marginRight: 'auto'
}
},
heroContent: {
maxWidth: 600,
margin: '0 auto',
padding: `${theme.spacing.unit * 8}px 0 ${theme.spacing.unit * 6}px`
},
cardHeader: {
backgroundColor: theme.palette.grey[200]
},
cardPricing: {
display: 'flex',
justifyContent: 'center',
alignItems: 'baseline',
marginBottom: theme.spacing.unit * 2
},
cardActions: {
[theme.breakpoints.up('sm')]: {
paddingBottom: theme.spacing.unit * 2
}
},
footer: {
marginTop: theme.spacing.unit * 8,
borderTop: `1px solid ${theme.palette.divider}`,
padding: `${theme.spacing.unit * 6}px 0`
}
})
export default theme
+74
View File
@@ -0,0 +1,74 @@
export function toLocalTime (epoch) {
const localDate = new Date(0)
localDate.setUTCSeconds(epoch)
const options = { year: 'numeric', month: 'long', day: '2-digit' }
return (
`${localDate.toLocaleDateString(options)
} at ${
localDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' })}`
)
}
export function toUTCTimestamp (localDate) {
if(isDefined(localDate)){
const date = new Date(localDate.valueOf())
const utcDate = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(),
date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(),
date.getUTCSeconds())
return utcDate.valueOf() / 1000|0
}
}
export function isDefined (d) {
return d !== null && typeof d !== 'undefined'
}
export const isArray = Array.isArray
export function isObject (d) {
return isDefined(d) && typeof d === 'object' && !Array.isArray(d)
}
export function isEmpty (obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) return false
}
return true
}
export function validObject (object, ...keys) {
return keys.reduce((a, b) => (a || { })[b], object) !== undefined
}
export function mergeDeep (target, ...sources) {
if (!sources.length) return target
const source = sources.shift()
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} })
mergeDeep(target[key], source[key])
} else {
Object.assign(target, { [key]: source[key] })
}
}
}
return mergeDeep(target, ...sources)
}
export function slugify (string) {
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w-]+/g, '') // Remove all non-word characters
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
}
+18
View File
@@ -0,0 +1,18 @@
import React from 'react'
import Typography from '@material-ui/core/Typography'
const TopBar = ({
size,
backgroundUrl,
title,
text
}) => (
<div className={`bannerTopBar ${size}`} style={backgroundUrl ? { backgroundImage: `url(${backgroundUrl})` } : {}}>
<div className='caption'>
<Typography className='title' variant='h1' align='center'>{title}</Typography>
<Typography className='text' variant='h2' align='center'>{text}</Typography>
</div>
</div>
)
export default TopBar
+367
View File
@@ -0,0 +1,367 @@
import React, { Component } from 'react'
import { graphql, compose, Query } from 'react-apollo'
import { clones, teams } from '../../../GraphQL/Calls'
import { DateTime } from 'luxon';
import TopBar from '../../BannerTopBar'
import { withStyles } from '@material-ui/core/styles'
import classNames from 'classnames'
import styles from './styles'
import { types} from '../../../GraphQL/models'
import { isDefined } from '../../../utils'
import {
MenuItem, Button, TextField, FormControl, InputLabel, Input, Typography,
Paper, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions,
Select, FormControlLabel, Checkbox
} from '@material-ui/core'
import { DateTimePicker } from 'material-ui-pickers';
import {
ChevronLeft,
ChevronRight,
} from '@material-ui/icons';
class AddClone extends Component {
constructor(props){
super(props)
let user = localStorage.getItem('user')
this.state = {
user: JSON.parse(user),
teamId:'',
botId:'',
mode:'',
resumeExecution: false,
beginDatetime: DateTime.local().minus({ days: 8 }).startOf('day'),
endDatetime: DateTime.local(),
waitTime: 1,
state : '',
stateDatetime: 0,
createDatetime: 0,
runAsTeam: false,
//Error handlers
nameError: false,
teamError: false,
botError: false,
modeError: false,
isNewCloneConfirmationOpen: false,
serverResponse:'',
serverError: false
}
}
render() {
const { classes } = this.props
if( !isDefined(this.state.user) ) {
return (
<TopBar
size='big'
title='Create a bot clone'
text="Please login to create a bot clone."
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
} else return (
<React.Fragment>
<TopBar
size='medium'
title='Create a bot clone'
text='Create a bot clone here.'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
<div className='container'>
<Paper className={classNames('container', classes.root)}>
<form noValidate autoComplete="off" onSubmit={this.submitForm.bind(this)}>
<Typography className={classes.typography} variant='h5' gutterBottom>
Create a Bot Clone
</Typography>
<Typography className={classes.typography} variant='subtitle1' align='justify'>
A bot clone it's a copy of your bot running on a virtual machine.
At the moment Live clones trade by default 0.001 BTC on Poloniex.
Please select the team and bot you want to clone!
</Typography>
<FormControl className={classNames(classes.form, classes.textField)} fullWidth>
<InputLabel shrink htmlFor='select'>
Select Team and Bot
</InputLabel>
<Query query={teams.GET_ALL_TEAMS_QUERY} >
{({ loading, error, data }) => {
if (loading) {
return (
<Select
value='loading'
input={<Input />}
displayEmpty
className={classes.selectEmpty}
disabled
>
<MenuItem key='1' value='loading'>Loading...</MenuItem>
</Select>
)
} else if(!isDefined(data.teams_FbByTeamMember)){
return (
<Select
value='noteams'
input={<Input />}
displayEmpty
className={classes.selectEmpty}
disabled
>
<MenuItem key='1' value='noteams'>You don't have any teams yet.</MenuItem>
</Select>
)
} else if (error) return `Error! There has been an error loading teams.`
return (
<Select
value={this.state.teamId}
input={<Input />}
className={classes.selectEmpty}
onBlur={(e)=>this.setState({teamError:false})}
error={this.state.teamError}
onChange={e => this.setState({teamId:e.target.value})}
>
<MenuItem key={data.teams_FbByTeamMember.id}
value={data.teams_FbByTeamMember.id}>
{data.teams_FbByTeamMember.name + '/' + data.teams_FbByTeamMember.fb[0].name}
</MenuItem>
</Select>
)
}}
</Query>
</FormControl>
<TextField
select
label="Running Mode"
className={classNames(classes.margin, classes.textField, classes.form)}
value={this.state.mode}
onChange={(e)=> this.setState({mode:e.target.value})}
onBlur={(e)=>this.setState({modeError:false})}
error={this.state.modeError}
fullWidth
>
{types.map(option => (
<MenuItem key={option} value={option}>
{option}
</MenuItem>
))}
</TextField>
{ this.state.mode == "Backtest" &&
<React.Fragment>
<DateTimePicker
autoOk
disableFuture
format="DD' at 'HH:mm"
ampm={false}
showTabs={false}
leftArrowIcon={<ChevronLeft />}
rightArrowIcon={<ChevronRight />}
value={this.state.beginDatetime}
label='Backtest Start Date'
onChange={newVal => this.setState({ beginDatetime: newVal })}
className={classNames(classes.form, classes.textField)}
fullWidth
/>
<DateTimePicker
autoOk
disableFuture
format="DD' at 'HH:mm"
ampm={false}
showTabs={false}
leftArrowIcon={<ChevronLeft />}
rightArrowIcon={<ChevronRight />}
value={this.state.endDatetime}
label='Backtest End Date'
onChange={newVal => this.setState({ endDatetime: newVal })}
className={classNames(classes.form, classes.textField)}
fullWidth
/>
<TextField
id="waitTime"
label="Wait Time"
className={classNames(classes.form, classes.textField)}
value={this.state.waitTime}
onChange={(e)=>this.setState({waitTime:e.target.value})}
fullWidth
/>
</React.Fragment>
}
<Typography className={classes.typography} variant='subtitle1' align='justify'>
If Run as Team is selected, the clone will be taken from the
team respository instead of your own team member folder.
Competitions runs from the team respository.
</Typography>
<FormControlLabel
control={
<Checkbox
checked={this.state.runAsTeam}
onChange={(e)=>this.setState({runAsTeam:e.target.checked })}
value="runAsTeam"
color="primary"
/>
}
label="Run as Team"
className={classNames(classes.form, classes.textField)}
/>
<Typography className={classes.typography} variant='subtitle1' align='justify'>
The Resume Execution option let's you pick up the context of
the last execution and continue from there.
</Typography>
<FormControlLabel
control={
<Checkbox
checked={this.state.resumeExecution}
onChange={(e)=>this.setState({resumeExecution:e.target.checked })}
value="resumeExecution"
color="primary"
/>
}
label="Resume Execution"
className={classNames(classes.form, classes.textField)}
/>
<div className={classes.actionButton} >
<Button
type="submit"
variant='contained' color='secondary'>
Clone Bot!
</Button>
</div>
</form>
<Dialog
open={this.state.isNewCloneConfirmationOpen}
onClose={this.handleNewCloneConfirmationClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">Creating bot clone</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{this.state.serverResponse}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={this.handleNewCloneConfirmationClose} color="primary" autoFocus>
Ok
</Button>
</DialogActions>
</Dialog>
</Paper>
</div>
</React.Fragment>
);
}
async submitForm(e){
e.preventDefault()
let error = this.validate()
if (!error){
let serverResponse = await this.createCloneOnServer()
error = serverResponse.errors || !isDefined(serverResponse.data.operations_AddClone)
if(error){
this.state.serverResponse = serverResponse.errors[0].message
this.state.serverError = true
}else{
this.state.serverResponse = "The new clone was sucessfully created."
this.state.serverError = false
}
this.handleNewCloneConfirmationOpen()
}
}
async createCloneOnServer(){
let variables = {
clone:{
teamId: this.state.teamId,
botId: this.state.botId,
mode: this.state.mode,
resumeExecution: this.state.resumeExecution,
runAsTeam: this.state.runAsTeam
}
}
if(this.state.mode == "Backtest"){
variables.clone.beginDatetime = this.state.beginDatetime.valueOf() / 1000|0
variables.clone.endDatetime = this.state.endDatetime.valueOf() / 1000|0
variables.clone.waitTime = this.state.waitTime
}
return this.props.addCloneMutation({
variables: variables
//refetchQueries: [{query: getClonesQuery}],
})
}
handleNewCloneConfirmationOpen = () => {
this.setState({ isNewCloneConfirmationOpen: true })
};
handleNewCloneConfirmationClose = () => {
this.setState({
isNewCloneConfirmationOpen: false
})
if(!this.state.serverError)
this.setState({
teamId:'',
botId:'',
mode:'',
resumeExecution: false,
beginDatetime: DateTime.local().minus({ days: 8 }).startOf('day'),
endDatetime: DateTime.local(),
waitTime: 1,
state : '',
stateDatetime: 0,
createDatetime: 0,
runAsTeam: false,
//Error handlers
nameError: false,
teamError: false,
botError: false,
modeError: false,
isNewCloneConfirmationOpen: false,
serverResponse: '',
serverError: false
})
};
validate(){
let isError = false
if(this.state.teamId.length < 1) {
isError = true
this.setState(state => ({ teamError: true }));
}
if(this.state.mode.length < 1) {
isError = true
this.setState(state => ({ modeError: true }));
}
return isError;
}
}
export default compose(
graphql(clones.OPERATIONS_ADD_CLONE, { name:'addCloneMutation' }),
withStyles(styles)
)(AddClone)
+37
View File
@@ -0,0 +1,37 @@
const styles = theme => ({
root: {
width: '100%',
flexGrow: 1,
padding: 10,
marginTop: '5%',
marginBottom: '10%'
},
container: {
display: 'flex',
flexWrap: 'wrap',
padding: 20,
height: '100%'
},
textField: {
width: '80%',
marginLeft:'10%',
marginBottom: 10
},
actionButton: {
textAlign: 'center',
marginTop: 10
},
typography: {
width: '80%',
marginLeft: '10%',
marginTop: 40
},
form: {
marginTop: 20
},
selectEmpty: {
marginTop: theme.spacing.unit * 2,
},
});
export default styles;
@@ -0,0 +1,59 @@
import React, { Component } from 'react'
import AddClone from './AddClone'
import AddIcon from '@material-ui/icons/Add'
import { withStyles } from '@material-ui/core/styles'
import styles from './styles'
import {
Button, Dialog, DialogContent, DialogContentText, DialogTitle, Paper, Typography
} from '@material-ui/core'
class CloneDialog extends Component {
constructor (props) {
super(props)
this.state = {
selected:'',
isNewCloneDialogOpen: false,
}
}
handleNewCloneDialogOpen = () => {
this.setState({ isNewCloneDialogOpen: true })
};
handleNewCloneDialogClose = () => {
this.setState({ isNewCloneDialogOpen: false })
};
render () {
const { classes } = this.props
return (
<div className={classes.root}>
<Button variant="contained" color="secondary"
aria-label="addNewClone" className={classes.button}
onClick={this.handleNewCloneDialogOpen} >
Add a new Clone
</Button>
<Dialog
open={this.state.isNewCloneDialogOpen}
onClose={this.handleNewCloneDialogClose}
aria-labelledby="addClone-dialog-title"
>
<DialogTitle id="addClone-dialog-title">
Add a new Clone
</DialogTitle>
<DialogContent>
<DialogContentText>
Description...
</DialogContentText>
<AddClone handleNewCloneDialogClose={this.handleNewCloneDialogClose}/>
</DialogContent>
</Dialog>
</div>
)
}
}
export default withStyles(styles)(CloneDialog)
+228
View File
@@ -0,0 +1,228 @@
import React, { Component } from 'react'
import { graphql, compose } from 'react-apollo'
import { clones } from '../../../GraphQL/Calls'
import Poloniex from '../../../img/poloniex.png'
import Binance from '../../../img/binance.png'
import {
Grid, Paper, Typography, Button, TextField, Dialog, DialogContent,
DialogContentText, DialogTitle, DialogActions,
ExpansionPanel, ExpansionPanelDetails, ExpansionPanelSummary,
ExpansionPanelActions, Chip, Divider
} from '@material-ui/core'
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import { isDefined, toLocalTime } from '../../../utils'
import classNames from 'classnames'
import { withStyles } from '@material-ui/core/styles'
import styles from './styles'
class ListClones extends Component {
constructor (props) {
super(props)
this.state = {
isRemoveDialogOpen: false,
isLogsDialogOpen: false,
}
}
render () {
const { classes } = this.props
const clone = this.props.currentClone
return (
<React.Fragment>
<ExpansionPanel className={classes.root}>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<div className={classes.heading}>
<Typography className={classes.heading}>{clone.teamId}</Typography>
</div>
<div className={classes.heading}>
<Typography className={classes.heading}>{clone.botId}</Typography>
</div>
<div className={classes.heading}>
<Typography className={classes.heading}>{clone.mode}</Typography>
</div>
</ExpansionPanelSummary>
<Divider />
<ExpansionPanelDetails className={classes.details}>
<div className={classes.column}>
<Typography className={classes.cloneInfo1}>Created:</Typography>
{ isDefined(clone.beginDatetime) &&
<Typography className={classes.cloneInfo1}>Begin:</Typography>
}
{ isDefined(clone.endDatetime) &&
<Typography className={classes.cloneInfo1}>End:</Typography>
}
{ isDefined(clone.waitTime) &&
<Typography className={classes.cloneInfo1}>Wait Time:</Typography>
}
<Typography className={classes.cloneInfo1}>Resume Execution:</Typography>
<Typography className={classes.cloneInfo1}>Run As Team:</Typography>
</div>
<div className={classes.column2}>
<Typography className={classes.cloneInfo2}>{toLocalTime(clone.createDatetime)}</Typography>
{ isDefined(clone.beginDatetime) &&
<Typography className={classes.cloneInfo2}>{toLocalTime(clone.beginDatetime)}</Typography>
}
{ isDefined(clone.endDatetime) &&
<Typography className={classes.cloneInfo2}>{toLocalTime(clone.endDatetime)}</Typography>
}
{ isDefined(clone.waitTime) &&
<Typography className={classes.cloneInfo2}>{clone.waitTime}</Typography>
}
<Typography className={classes.cloneInfo2}>{clone.resumeExecution ? 'Yes':'No'}</Typography>
<Typography className={classes.cloneInfo2}>{clone.runAsTeam ? 'Yes':'No'}</Typography>
</div>
<div className={classNames(classes.column3, classes.helper)}>
<Typography className={classes.cloneInfo1}>Virtual Machine Status</Typography>
<TextField
id="outlined-state"
defaultValue={clone.state}
margin="normal"
InputProps={{
readOnly: true,
}}
fullWidth
multiline
/>
</div>
</ExpansionPanelDetails>
<Divider />
<ExpansionPanelActions>
<Button
className={classes.buttonList}
variant='contained' color='secondary' size='small'
onClick={() => this.setState({ isLogsDialogOpen: true })}>
View Logs
</Button>
<Button
className={classes.buttonList}
variant='contained' color='secondary' size='small'
onClick={this.handleRemoveDialogOpen}>
Delete
</Button>
</ExpansionPanelActions>
</ExpansionPanel>
<Dialog
open={this.state.isRemoveDialogOpen}
onClose={this.handleRemoveDialogClose}
aria-labelledby="removeClone-dialog-title"
>
<DialogTitle id="removeClone-dialog-title">
Delete Clone
</DialogTitle>
<DialogContent>
<DialogContentText>
Are you sure you want to delete this clone?
Deleting this clone will prevent any running bots associated to this clone to access your account at the exchange.
</DialogContentText>
<DialogActions>
<Button onClick={this.handleRemoveDialogOK} className={classes.buttonList}
variant='contained' color='secondary' size='small'
>
Proceed
</Button>
<Button onClick={this.handleRemoveDialogCancel}
className={classes.buttonList}
variant='contained' color='secondary' size='small'
>
Cancel
</Button>
</DialogActions>
</DialogContent>
</Dialog>
<Dialog
open={this.state.isLogsDialogOpen}
onClose={this.handleLogsDialogClose}
aria-labelledby="logs-dialog-title"
>
<DialogTitle id="logs-dialog-title">
Last clone logs
</DialogTitle>
<DialogContent className={classes.logsDialog}>
<TextField
id="outlined-logs"
label="Last Logs"
defaultValue={this.props.currentClone.lastLogs}
className={classes.textArea}
margin="normal"
InputProps={{
readOnly: true,
}}
variant="outlined"
fullWidth
multiline
/>
</DialogContent>
<DialogActions>
<Button onClick={this.handleLogsDialogClose} className={classes.buttonList}
variant='contained' color='secondary' size='small' autoFocus
>
Close
</Button>
</DialogActions>
</Dialog>
</React.Fragment>
)
}
canStopClone(){
const state = JSON.parse(this.props.currentClone.state)
if(isDefined(state) && state.hasOwnProperty("running")){
return true
} else {
return false
}
}
canRestartClone(){
const state = JSON.parse(this.props.currentClone.state)
if(isDefined(state) && state.hasOwnProperty("terminated")){
return true
} else {
return false
}
}
removeClone (clone) {
this.props.mutate({
variables:{
id: clone.id
},
refetchQueries: [{query: clones.OPERATIONS_LIST_CLONES}]
})
}
showLogs () {
this.setState({ isLogsDialogOpen: true })
}
handleLogsDialogClose = () => {
this.setState({ isLogsDialogOpen: false })
}
handleRemoveDialogOpen = () => {
this.setState({ isRemoveDialogOpen: true })
}
handleRemoveDialogOK = () => {
this.removeClone(this.props.currentClone)
this.setState({ isRemoveDialogOpen: false })
}
handleRemoveDialogCancel = () => {
this.setState({ isRemoveDialogOpen: false })
}
}
export default compose(
graphql(clones.OPERATIONS_REMOVE_CLONE),
withStyles(styles)
)(ListClones)
+130
View File
@@ -0,0 +1,130 @@
import React, { Component } from 'react'
import { graphql } from 'react-apollo'
import { clones } from '../../../GraphQL/Calls'
import TopBar from '../../BannerTopBar'
//import CloneDialog from './CloneDialog'
import ListClones from './ListClones'
// Material-ui
import { Typography, Paper } from '@material-ui/core'
class BrowseClones extends Component {
constructor (props) {
super(props)
let user = localStorage.getItem('user')
this.state = {
user: JSON.parse(user)
}
}
render () {
let data = this.props.data
if (data.loading) {
return (
<TopBar
size='big'
title='Your Bot Clones'
text='Loading your Bot Clones...'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
} else if (data.operations_Clones && data.operations_Clones.length > 0) {
return (
<React.Fragment>
<TopBar
size='medium'
title='Your Bot Clones'
text='All your Bot Clones are here.'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
<div className='container'>
{
data.operations_Clones.map((clone, i) => {
return (
<ListClones key={clone.id} currentClone={clone} />
)
})
}
</div>
</React.Fragment>
)
} else if (data.error) {
return (
<TopBar
size='big'
title='Your Bot Clones'
text='Please login to gain access to your Bot Clones.'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
} else {
return (
<TopBar
size='big'
title='Your Bot Clones'
text="You don't have any Bot Clone yet. Once you create one you will find it here."
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
}
}
getBodyContent (data) {
if (data.loading) {
return (
<TopBar
size='big'
title='Manage your Bot Clones'
text='Loading Bot Clones...'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
} else if (data.operations_Clones && data.operations_Clones.length > 0) {
return (
<React.Fragment>
<TopBar
size='big'
title='Manage your Bot Clones'
text='Loading Bot Clones...'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
<div className='container'>
{
data.operations_Clones.map((clone, i) => {
return (
<ListClones key={clone.id} currentClone={clone} />
)
})
}
</div>
</React.Fragment>
)
} else if (data.error) {
return (
<TopBar
size='big'
title='No Bot Clones to display'
text='Please Login to access your Bot Clones.'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
} else {
return (
<TopBar
size='big'
title='No Bot Clones to display'
text="You don't have any Bot Clone yet. After you create a new Clone, it will be listed here."
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
)
}
}
}
export default graphql(clones.OPERATIONS_LIST_CLONES)(BrowseClones)
+82
View File
@@ -0,0 +1,82 @@
const styles = theme => ({
root: {
flexGrow: 1,
padding: 10,
margin: 10
},
image: {
width: 128,
height: '100%',
cursor: 'default'
},
img: {
margin: 'auto',
display: 'block',
maxWidth: '100%',
maxHeight: '100%'
},
buttonList: {
margin: theme.spacing.unit,
float: 'right',
},
buttonGrid: {
marginTop: -20,
},
button: {
display: 'block',
marginLeft: 'auto',
marginRight: 'auto',
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
},
textArea: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
whiteSpace: 'pre',
overflowY:'auto',
overflowX:'hidden'
},
heading: {
fontSize: theme.typography.pxToRem(18),
flexBasis: '33.33%',
fontWeight: '600'
},
helper: {
borderLeft: `2px solid ${theme.palette.divider}`,
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`,
},
logsDialog:{
width:'1750px',
overflowY:'auto',
overflowX:'hidden'
},
details:{
display:'flex'
},
column: {
flexBasis: '15%',
maxWidth: '15%'
},
column2: {
flexBasis: '42.5%',
maxWidth: '42.5%'
},
column3: {
flexBasis: '42.5%',
maxWidth: '42.5%'
},
cloneInfo1:{
fontWeight: '600',
paddingLeft: '16px',
paddingTop: '16px'
},
cloneInfo2:{
paddingLeft: '16px',
paddingTop: '16px'
},
})
export default styles
+87
View File
@@ -0,0 +1,87 @@
import React, { Component } from 'react'
import {graphql, compose} from 'react-apollo'
import { getAuditLog } from '../../../queries'
import { Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@material-ui/core';
import { withStyles } from '@material-ui/core/styles'
import { toLocalTime } from '../../../utils'
const styles = theme => ({
root: {
flexGrow: 1,
padding: 20,
margin: 10
}
});
class AuditLogList extends Component {
constructor(props){
super(props)
const key = this.props.currentKey
this.state = {
id: key.id,
key: key.key,
date:'',
action: ''
}
}
render() {
const { classes } = this.props
var data = this.props.data
if(data.loading){
return <Typography className={classes.root} variant='subtitle1'>Loading...</Typography>
}else{
if(!data.keyVault_AuditLogs){
return <Typography className={classes.root} variant='subtitle1'>There has been an erorr.</Typography>
}
if(data.keyVault_AuditLogs.length === 0){
return <Typography className={classes.root} variant='subtitle1'>There is no audit history for this key.</Typography>
}
return (
<Table className={classes.table}>
<TableHead>
<TableRow>
<TableCell>Date</TableCell>
<TableCell>Action</TableCell>
<TableCell>Details</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.keyVault_AuditLogs.map(row => {
return (
<TableRow key={row.id}>
<TableCell component="th" scope="row">
{toLocalTime(row.date)}
</TableCell>
<TableCell>{row.action}</TableCell>
<TableCell>{row.details}</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
)
}
}
}
export default compose(
graphql(getAuditLog, { // What follows is the way to pass a parameter to a query.
options: (props) => {
return {
variables: {
key: props.currentKey.id
}
}
}
}),
withStyles(styles)
)(AuditLogList)
+43
View File
@@ -0,0 +1,43 @@
import React, { Component } from 'react'
import { Typography } from '@material-ui/core'
import { withStyles } from '@material-ui/core/styles'
import TopBar from './BannerTopBar'
class Home extends Component {
render () {
return (
<React.Fragment>
<TopBar
size='big'
title='Operations Module'
text='Responsible for manage bot clones.'
backgroundUrl='https://advancedalgos.net/img/photos/ecosystem.jpg'
/>
<div className='homePage container'>
<Typography variant='h1' align='center' className='title'>
Welcome to the Operations Module!
</Typography>
<Typography variant='h2' align='center' className='subtitle'>
Responsible for manage bot clones.
</Typography>
<div className='column'>
<Typography align='justify'>
The Operations module allows you to create copies of your bot
that will be executed on a virtual machine.
</Typography>
</div>
<div className='column'>
<Typography align='justify'>
</Typography>
</div>
</div>
</React.Fragment>
)
}
}
export default Home