diff --git a/src/ic/ic-action.js b/src/ic/ic-action.js
index 9eaabe0..93634e5 100644
--- a/src/ic/ic-action.js
+++ b/src/ic/ic-action.js
@@ -16,75 +16,93 @@
******************************************************************************/
import React from 'react';
-import { Button, ButtonToolbar, DropdownButton, Dropdown } from 'react-bootstrap';
-import TimePicker from 'react-bootstrap-time-picker'
+import { Button, ButtonToolbar, DropdownButton, Dropdown, InputGroup, FormControl } from 'react-bootstrap';
class ICAction extends React.Component {
- constructor(props) {
- super(props);
+ constructor(props) {
+ super(props);
- this.state = {
- selectedAction: null,
- selectedDelay: 0
- };
+ let t = new Date()
+
+ Number.prototype.pad = function(size) {
+ var s = String(this);
+ while (s.length < (size || 2)) {s = "0" + s;}
+ return s;
}
- static getDerivedStateFromProps(props, state){
- if (state.selectedAction == null) {
- if (props.actions != null && props.actions.length > 0) {
- return{
- selectedAction: props.actions[0]
- };
- }
- }
- return null
- }
+ let time = new Date();
+ time.setMinutes(5 * Math.round(time.getMinutes() / 5 + 1))
- setAction = id => {
- // search action
- for (let action of this.props.actions) {
- if (action.id === id) {
- this.setState({ selectedAction: action });
- }
- }
+ this.state = {
+ selectedAction: null,
+ time: time
};
+ }
- setDelayForAction = time => {
- // time in int format: (hours * 3600 + minutes * 60 + seconds)
- this.setState({selectedDelay: time})
+ static getDerivedStateFromProps(props, state) {
+ if (state.selectedAction == null) {
+ if (props.actions != null && props.actions.length > 0) {
+ return {
+ selectedAction: props.actions[0]
+ };
+ }
}
+ return null
+ }
- render() {
-
- let sendCommandDisabled = this.props.runDisabled || this.state.selectedAction == null || this.state.selectedAction.id === "-1"
-
- const actionList = this.props.actions.map(action => (
-
- {action.title}
-
- ));
-
- return
- {"Select delay for command execution (Format hh:mm, max 1h):"}
-
-
-
- {actionList}
-
-
-
-
-
-
;
+ setAction = id => {
+ // search action
+ for (let action of this.props.actions) {
+ if (action.id === id) {
+ this.setState({ selectedAction: action });
+ }
}
+ };
+
+ setTimeForAction = (time) => {
+ this.setState({ time: new Date(time) })
+ }
+
+ render() {
+
+ let sendCommandDisabled = this.props.runDisabled || this.state.selectedAction == null || this.state.selectedAction.id === "-1"
+
+ let time = this.state.time.getFullYear().pad(4) + '-' +
+ this.state.time.getMonth().pad(2) + '-' +
+ this.state.time.getDay().pad(2) + 'T' +
+ this.state.time.getHours().pad(2) + ':' +
+ this.state.time.getMinutes().pad(2);
+
+ const actionList = this.props.actions.map(action => (
+
+ {action.title}
+
+ ));
+
+ return
+
+
+
+ {actionList}
+
+
+
+
+
+ Select time for synced command execution
+
;
+ }
}
export default ICAction;
diff --git a/src/ic/ics-data-manager.js b/src/ic/ics-data-manager.js
index e4c9e44..02d480f 100644
--- a/src/ic/ics-data-manager.js
+++ b/src/ic/ics-data-manager.js
@@ -24,8 +24,14 @@ class IcsDataManager extends RestDataManager {
super('ic', '/ic');
}
- doActions(ic, action, token = null) {
- RestAPI.post(this.makeURL(this.url + '/' + ic.id + '/action'), action, token).then(response => {
+ doActions(ic, actions, token = null) {
+ for (let action of actions) {
+ if (action.when)
+ // Send timestamp as Unix Timestamp
+ action.when = Math.round(action.when.getTime() / 1000);
+ }
+
+ RestAPI.post(this.makeURL(this.url + '/' + ic.id + '/action'), actions, token).then(response => {
AppDispatcher.dispatch({
type: 'ics/action-started',
data: response
diff --git a/src/ic/ics.js b/src/ic/ics.js
index d995348..2347050 100644
--- a/src/ic/ics.js
+++ b/src/ic/ics.js
@@ -145,7 +145,6 @@ class InfrastructureComponents extends Component {
}
}
-
closeNewModal(data) {
this.setState({ newModal : false });
@@ -241,8 +240,10 @@ class InfrastructureComponents extends Component {
this.setState({ selectedICs: selectedICs });
}
- runAction(action) {
+ runAction(action, when) {
for (let index of this.state.selectedICs) {
+ action.when = when;
+
AppDispatcher.dispatch({
type: 'ics/start-action',
ic: this.state.ics[index],
@@ -262,7 +263,6 @@ class InfrastructureComponents extends Component {
}
stateLabelStyle(state, component){
-
var style = [ 'badge' ];
if (InfrastructureComponents.isICOutdated(component) && state !== 'shutdown') {
@@ -307,7 +307,6 @@ class InfrastructureComponents extends Component {
default:
style.push('badge-default');
-
/* Possible states of ICs
* 'error': ['resetting', 'error'],
'idle': ['resetting', 'error', 'idle', 'starting', 'shuttingdown'],
@@ -333,13 +332,11 @@ class InfrastructureComponents extends Component {
}
modifyManagedExternallyColumn(managedExternally, component){
-
if(managedExternally){
return
} else {
return ""
}
-
}
modifyUptimeColumn(uptime, component){
@@ -347,7 +344,7 @@ class InfrastructureComponents extends Component {
let momentDurationFormatSetup = require("moment-duration-format");
momentDurationFormatSetup(moment)
- let timeString = moment.duration(uptime, "seconds").format();
+ let timeString = moment.duration(uptime, "seconds").humanize();
return {timeString}
}
else{
@@ -366,7 +363,6 @@ class InfrastructureComponents extends Component {
}
sendControlCommand(command,ic){
-
if(command === "restart"){
AppDispatcher.dispatch({
type: 'ics/restart',
@@ -380,7 +376,6 @@ class InfrastructureComponents extends Component {
token: this.state.sessionToken,
});
}
-
}
isExternalIC(index){
@@ -497,9 +492,9 @@ class InfrastructureComponents extends Component {
this.runAction(action)}
+ runAction={(action, when) => this.runAction(action, when)}
actions={[
- {id: '-1', title: 'Select command', data: {action: 'none'}},
+ {id: '-1', title: 'Action', data: {action: 'none'}},
{id: '0', title: 'Reset', data: {action: 'reset'}},
{id: '1', title: 'Shutdown', data: {action: 'shutdown'}},
]}
@@ -524,7 +519,6 @@ class InfrastructureComponents extends Component {
sendControlCommand={(command, ic) => this.sendControlCommand(command, ic)}/>
-
);
}
}
diff --git a/src/scenario/scenario.js b/src/scenario/scenario.js
index 5397bb5..7bf2de9 100644
--- a/src/scenario/scenario.js
+++ b/src/scenario/scenario.js
@@ -390,9 +390,7 @@ class Scenario extends React.Component {
}
- runAction(action, delay) {
- // delay in seconds
-
+ runAction(action, when) {
if (action.data.action === 'none') {
console.warn("No command selected. Nothing was sent.");
return;
@@ -415,8 +413,7 @@ class Scenario extends React.Component {
action.data.parameters = this.state.configs[index].startParameters;
}
- // Unix time stamp + delay
- action.data.when = Math.round(Date.now() / 1000.0 + delay)
+ action.data.when = when;
console.log("Sending action: ", action.data)
@@ -798,8 +795,6 @@ class Scenario extends React.Component {
scenarioID={this.state.scenario.id}
/>
-
-
{/*Component Configurations table*/}
Component Configurations
this.runAction(action, delay)}
+ runAction={(action, when) => this.runAction(action, when)}
actions={[
- {id: '-1', title: 'Select command', data: {action: 'none'}},
+ {id: '-1', title: 'Action', data: {action: 'none'}},
{id: '0', title: 'Start', data: {action: 'start'}},
{id: '1', title: 'Stop', data: {action: 'stop'}},
{id: '2', title: 'Pause', data: {action: 'pause'}},