mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
IC actions start, stop, pause, resume working with correct params
- start parameters of component config added to start action #285 - auto-creation of result and url for start action working #286 - model defaults to first file of component config for now #286
This commit is contained in:
parent
04916aa9d6
commit
035e1defc7
4 changed files with 29 additions and 32 deletions
|
@ -54,13 +54,6 @@ class ICAction extends React.Component {
|
|||
|
||||
runAction(action, when) {
|
||||
|
||||
console.log("configs", this.props.configs)
|
||||
console.log("selectedConfigs", this.props.selectedConfigs)
|
||||
console.log("ics", this.props.ics)
|
||||
console.log("selectedICs", this.props.selectedICs)
|
||||
console.log("action", action)
|
||||
console.log("when", when)
|
||||
|
||||
if (action.data.action === 'none') {
|
||||
console.warn("No command selected. Nothing was sent.");
|
||||
return;
|
||||
|
@ -169,9 +162,10 @@ class ICAction extends React.Component {
|
|||
|
||||
if (newAction.action === 'start') {
|
||||
newAction["parameters"] = config.startParameters;
|
||||
newAction["model"] = {}
|
||||
|
||||
|
||||
if (config.fileIDs.length > 0){
|
||||
newAction["model"] = {}
|
||||
newAction.model["type"] = "url"
|
||||
newAction.model["token"] = this.props.token
|
||||
// TODO do not default to the first file of the config
|
||||
|
@ -187,7 +181,6 @@ class ICAction extends React.Component {
|
|||
|
||||
// add the new action
|
||||
newActions.push(newAction);
|
||||
console.log("New actions in loop", newAction, newActions)
|
||||
|
||||
} // end for loop over selected configs
|
||||
|
||||
|
@ -204,7 +197,7 @@ class ICAction extends React.Component {
|
|||
}
|
||||
|
||||
// create new result for new run
|
||||
newResult.result["description"] = "Placeholder for description"
|
||||
newResult.result["description"] = "Start at " + when;
|
||||
newResult.result["scenarioID"] = this.props.selectedConfigs[0].scenarioID
|
||||
newResult.result["configSnapshots"] = configSnapshots
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ class InfrastructureComponentStore extends ArrayStore {
|
|||
case 'ics/action-result-added':
|
||||
|
||||
for (let a of action.actions){
|
||||
let icid = Object.assign({}, a.icid)
|
||||
|
||||
if (a.results !== undefined && a.results != null){
|
||||
// adapt URL for newly created result ID
|
||||
|
@ -87,13 +86,12 @@ class InfrastructureComponentStore extends ArrayStore {
|
|||
a.results.url = ICsDataManager.makeURL(a.results.url);
|
||||
a.results.url = window.location.host + a.results.url;
|
||||
}
|
||||
if (a.model !== undefined && a.model != null) {
|
||||
if (a.model !== undefined && a.model != null && JSON.stringify(a.model) !== JSON.stringify({})) {
|
||||
// adapt URL for model file
|
||||
a.model.url = ICsDataManager.makeURL(a.model.url);
|
||||
a.model.url = window.location.host + a.model.url;
|
||||
}
|
||||
delete a.icid
|
||||
ICsDataManager.doActions(icid, [a], action.token)
|
||||
ICsDataManager.doActions(a.icid, [a], action.token)
|
||||
}
|
||||
return state;
|
||||
|
||||
|
|
|
@ -25,15 +25,16 @@ class IcsDataManager extends RestDataManager {
|
|||
}
|
||||
|
||||
doActions(icid, actions, token = null, result=null) {
|
||||
for (let action of actions) {
|
||||
if (action.when)
|
||||
// Send timestamp as Unix Timestamp
|
||||
action.when = Math.round(action.when.getTime() / 1000);
|
||||
}
|
||||
|
||||
if (icid !== undefined && icid != null) {
|
||||
|
||||
console.log("doActions, icid:", icid)
|
||||
if (icid !== undefined && icid != null && JSON.stringify(icid) !== JSON.stringify({})) {
|
||||
|
||||
for (let action of actions) {
|
||||
if (action.when) {
|
||||
// Send timestamp as Unix Timestamp
|
||||
action.when = Math.round(action.when.getTime() / 1000);
|
||||
}
|
||||
}
|
||||
// sending action to a specific IC via IC list
|
||||
|
||||
RestAPI.post(this.makeURL(this.url + '/' + icid + '/action'), actions, token).then(response => {
|
||||
|
@ -54,13 +55,14 @@ class IcsDataManager extends RestDataManager {
|
|||
|
||||
if (actions[0].action !== "start"){
|
||||
for (let a of actions){
|
||||
console.log("doActions, a.icid:", a.icid)
|
||||
icid = JSON.parse(JSON.stringify(a.icid))
|
||||
delete a.icid
|
||||
console.log("doActions, icid:", icid)
|
||||
// sending action to a specific IC via IC list
|
||||
|
||||
RestAPI.post(this.makeURL(this.url + '/' + icid + '/action'), [a], token).then(response => {
|
||||
// sending action to a specific IC via IC list
|
||||
if (a.when) {
|
||||
// Send timestamp as Unix Timestamp
|
||||
a.when = Math.round(a.when.getTime() / 1000);
|
||||
}
|
||||
|
||||
RestAPI.post(this.makeURL(this.url + '/' + a.icid + '/action'), [a], token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/action-started',
|
||||
data: response
|
||||
|
@ -84,6 +86,11 @@ class IcsDataManager extends RestDataManager {
|
|||
actions: actions,
|
||||
token: token,
|
||||
});
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: "results/added",
|
||||
data: response.result,
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/action-result-add-error',
|
||||
|
|
|
@ -302,7 +302,6 @@ class Scenario extends React.Component {
|
|||
}
|
||||
|
||||
copyConfig(index) {
|
||||
console.log("index", index, "copyConfig: ", this.state.configs[index])
|
||||
let config = JSON.parse(JSON.stringify(this.state.configs[index]));
|
||||
|
||||
let signals = JSON.parse(JSON.stringify(SignalStore.getState().filter(s => s.configID === parseInt(config.id, 10))));
|
||||
|
@ -665,7 +664,7 @@ class Scenario extends React.Component {
|
|||
});
|
||||
} else {
|
||||
this.setState({
|
||||
modalResultConfigs: JSON.parse(result.configSnapshots),
|
||||
modalResultConfigs: result.configSnapshots,
|
||||
modalResultConfigsIndex: result.id,
|
||||
resultConfigsModal: true
|
||||
});
|
||||
|
@ -873,7 +872,7 @@ class Scenario extends React.Component {
|
|||
/>
|
||||
</Table>
|
||||
|
||||
{/*{this.state.ExternalICInUse ? (*/}
|
||||
{this.state.ExternalICInUse ? (
|
||||
<div style={{ float: 'left' }}>
|
||||
<ICAction
|
||||
hasConfigs={true}
|
||||
|
@ -890,8 +889,8 @@ class Scenario extends React.Component {
|
|||
{ id: '3', title: 'Resume', data: { action: 'resume' } }
|
||||
]} />
|
||||
</div>
|
||||
{/*) : (<div />)*/}
|
||||
{/*}*/}
|
||||
) : (<div />)
|
||||
}
|
||||
|
||||
< div style={{ clear: 'both' }} />
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue