diff --git a/src/ic/ic-data-data-manager.js b/src/ic/ic-data-data-manager.js
index 065d21c..ba2225e 100644
--- a/src/ic/ic-data-data-manager.js
+++ b/src/ic/ic-data-data-manager.js
@@ -44,67 +44,6 @@ class IcDataDataManager {
}
}
- getStatus(url,socketname,token,icid,ic){
- RestAPI.get(url, null).then(response => {
- AppDispatcher.dispatch({
- type: 'ic-status/status-received',
- data: response,
- token: token,
- socketname: socketname,
- icid: icid,
- ic: ic
- });
- if(!ic.managedexternally){
- let tempIC = ic;
- tempIC.state = response.state;
- AppDispatcher.dispatch({
- type: 'ics/start-edit',
- data: tempIC,
- token: token,
- });
- }
- }).catch(error => {
- AppDispatcher.dispatch({
- type: 'ic-status/status-error',
- error: error
- })
- })
- }
-
- restart(url,socketname,token){
- RestAPI.post(url, null).then(response => {
- AppDispatcher.dispatch({
- type: 'ic-status/restart-successful',
- data: response,
- token: token,
- socketname: socketname,
- });
- }).catch(error => {
- AppDispatcher.dispatch({
- type: 'ic-status/restart-error',
- error: error
- })
- })
- }
-
- shutdown(url,socketname,token){
- RestAPI.post(url, null).then(response => {
- AppDispatcher.dispatch({
- type: 'ic-status/shutdown-successful',
- data: response,
- token: token,
- socketname: socketname,
- });
- }).catch(error => {
- AppDispatcher.dispatch({
- type: 'ic-status/shutdown-error',
- error: error
- })
- })
- }
-
-
-
closeAll() {
// close every open socket
for (var identifier in this._sockets) {
diff --git a/src/ic/ic-dialog.js b/src/ic/ic-dialog.js
index bb4888f..02d469c 100644
--- a/src/ic/ic-dialog.js
+++ b/src/ic/ic-dialog.js
@@ -71,7 +71,7 @@ class ICDialog extends React.Component {
Status:
.
- ******************************************************************************/
-
-import ArrayStore from '../common/array-store';
-import ICDataDataManager from './ic-data-data-manager';
-
-class ICStatusStore extends ArrayStore {
- constructor() {
- super('ic-status', ICDataDataManager);
- }
-
-
- reduce(state, action) {
- switch(action.type) {
-
- case 'ic-status/get-status':
- ICDataDataManager.getStatus(action.url, action.socketname, action.token, action.icid, action.ic);
- return super.reduce(state, action);
-
- case 'ic-status/status-received':
- let tempData = action.data;
- tempData.icID = action.icid;
-
- return this.updateElements(state, [tempData]);
-
- case 'ic-status/status-error':
- console.log("status error");
- return state;
-
- case 'ic-status/restart':
- ICDataDataManager.restart(action.url, action.socketname, action.token);
- return state;
-
- case 'ic-status/restart-successful':
- return state;
-
- case 'ic-status/restart-error':
- console.log("restart error");
- return state;
-
- case 'ic-status/shutdown':
- ICDataDataManager.shutdown(action.url, action.socketname, action.token);
- return state;
-
- case 'ic-status/shutdown-successful':
- return state;
-
- case 'ic-status/shutdown-error':
- console.log("shutdown error");
- return state;
-
- default:
- return super.reduce(state, action);
- }
- }
-}
-
-export default new ICStatusStore();
diff --git a/src/ic/ic-store.js b/src/ic/ic-store.js
index 21d84ea..d9ae16e 100644
--- a/src/ic/ic-store.js
+++ b/src/ic/ic-store.js
@@ -76,6 +76,51 @@ class InfrastructureComponentStore extends ArrayStore {
console.log(action.error);
return state;
+ case 'ics/get-status':
+ ICsDataManager.getStatus(action.url, action.token, action.ic);
+ return super.reduce(state, action);
+
+ case 'ics/status-received':
+ let tempIC = action.ic;
+ if(!tempIC.managedexternally){
+ tempIC.state = action.data.state;
+ tempIC.statusupdateraw = action.data;
+ AppDispatcher.dispatch({
+ type: 'ics/start-edit',
+ data: tempIC,
+ token: action.token,
+ });
+ }
+ return super.reduce(state, action);
+
+ case 'ics/status-error':
+ console.log("status error:", action.error);
+ return super.reduce(state, action);
+
+ case 'ics/restart':
+ ICsDataManager.restart(action.url, action.token);
+ return super.reduce(state, action);
+
+ case 'ics/restart-successful':
+ console.log("restart response:", action.data);
+ return super.reduce(state, action);
+
+ case 'ics/restart-error':
+ console.log("restart error:", action.error);
+ return super.reduce(state, action);
+
+ case 'ics/shutdown':
+ ICsDataManager.shutdown(action.url, action.token);
+ return super.reduce(state, action);
+
+ case 'ics/shutdown-successful':
+ console.log("shutdown response:", action.data);
+ return super.reduce(state, action);
+
+ case 'ics/shutdown-error':
+ console.log("shutdown error:", action.error);
+ return super.reduce(state, action);
+
default:
return super.reduce(state, action);
}
diff --git a/src/ic/ics-data-manager.js b/src/ic/ics-data-manager.js
index 89455c3..e4c9e44 100644
--- a/src/ic/ics-data-manager.js
+++ b/src/ic/ics-data-manager.js
@@ -20,23 +20,69 @@ import RestAPI from '../common/api/rest-api';
import AppDispatcher from '../common/app-dispatcher';
class IcsDataManager extends RestDataManager {
- constructor() {
- super('ic', '/ic');
- }
+ constructor() {
+ super('ic', '/ic');
+ }
- doActions(ic, action, token = null) {
- RestAPI.post(this.makeURL(this.url + '/' + ic.id + '/action'), action, token).then(response => {
- AppDispatcher.dispatch({
- type: 'ics/action-started',
- data: response
- });
- }).catch(error => {
- AppDispatcher.dispatch({
- type: 'ics/action-error',
- error
- });
- });
- }
+ doActions(ic, action, token = null) {
+ RestAPI.post(this.makeURL(this.url + '/' + ic.id + '/action'), action, token).then(response => {
+ AppDispatcher.dispatch({
+ type: 'ics/action-started',
+ data: response
+ });
+ }).catch(error => {
+ AppDispatcher.dispatch({
+ type: 'ics/action-error',
+ error
+ });
+ });
+ }
+
+ getStatus(url,token,ic){
+ RestAPI.get(url, null).then(response => {
+ AppDispatcher.dispatch({
+ type: 'ics/status-received',
+ data: response,
+ token: token,
+ ic: ic
+ });
+ }).catch(error => {
+ AppDispatcher.dispatch({
+ type: 'ics/status-error',
+ error: error
+ })
+ })
+ }
+
+ restart(url,token){
+ RestAPI.post(url, null).then(response => {
+ AppDispatcher.dispatch({
+ type: 'ics/restart-successful',
+ data: response,
+ token: token,
+ });
+ }).catch(error => {
+ AppDispatcher.dispatch({
+ type: 'ics/restart-error',
+ error: error
+ })
+ })
+ }
+
+ shutdown(url,token){
+ RestAPI.post(url, null).then(response => {
+ AppDispatcher.dispatch({
+ type: 'ics/shutdown-successful',
+ data: response,
+ token: token,
+ });
+ }).catch(error => {
+ AppDispatcher.dispatch({
+ type: 'ics/shutdown-error',
+ error: error
+ })
+ })
+ }
}
export default new IcsDataManager();
diff --git a/src/ic/ics.js b/src/ic/ics.js
index 82aabdb..1982b51 100644
--- a/src/ic/ics.js
+++ b/src/ic/ics.js
@@ -24,7 +24,6 @@ import moment from 'moment'
import AppDispatcher from '../common/app-dispatcher';
import InfrastructureComponentStore from './ic-store';
-import ICStatusStore from './ic-status-store';
import Icon from '../common/icon';
import Table from '../common/table';
@@ -39,7 +38,7 @@ import DeleteDialog from '../common/dialogs/delete-dialog';
class InfrastructureComponents extends Component {
static getStores() {
- return [ InfrastructureComponentStore, ICStatusStore];
+ return [ InfrastructureComponentStore];
}
static statePrio(state) {
@@ -78,9 +77,7 @@ class InfrastructureComponents extends Component {
return {
sessionToken: localStorage.getItem("token"),
ics: ics,
- icStatus: ICStatusStore.getState(),
modalIC: {},
- modalICStatus: {},
deleteModal: false,
icModal: false,
selectedICs: [],
@@ -115,15 +112,12 @@ class InfrastructureComponents extends Component {
// get status of VILLASnode and VILLASrelay ICs
this.state.ics.forEach(ic => {
- if ((ic.type === "villas-node" || ic.type === "villas-relay" )
+ if ((ic.type === "villas-node" || ic.type === "villas-relay")
&& ic.apiurl !== '' && ic.apiurl !== undefined && ic.apiurl !== null && !ic.managedexternally) {
- let splitWebsocketURL = ic.websocketurl.split("/");
AppDispatcher.dispatch({
- type: 'ic-status/get-status',
+ type: 'ics/get-status',
url: ic.apiurl + "/status",
- socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
token: this.state.sessionToken,
- icid: ic.id,
ic: ic
});
}
@@ -349,26 +343,22 @@ class InfrastructureComponents extends Component {
openICStatus(ic){
let index = this.state.ics.indexOf(ic);
- let icStatus = this.state.icStatus.find(status => status.icID === ic.id);
- this.setState({ icModal: true, modalIC: ic, modalICStatus: icStatus, modalIndex: index })
+ this.setState({ icModal: true, modalIC: ic, modalIndex: index })
}
sendControlCommand(command,ic){
- let splitWebsocketURL = ic.websocketurl.split("/");
if(command === "restart"){
AppDispatcher.dispatch({
- type: 'ic-status/restart',
+ type: 'ics/restart',
url: ic.apiurl + "/restart",
- socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
token: this.state.sessionToken,
});
}else if(command === "shutdown"){
AppDispatcher.dispatch({
- type: 'ic-status/shutdown',
+ type: 'ics/shutdown',
url: ic.apiurl + "/shutdown",
- socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
token: this.state.sessionToken,
});
}
@@ -451,7 +441,6 @@ class InfrastructureComponents extends Component {
ic={this.state.modalIC}
token={this.state.sessionToken}
userRole={this.state.currentUser.role}
- icStatus={this.state.modalICStatus}
sendControlCommand={(command, ic) => this.sendControlCommand(command, ic)}/>
this.closeDeleteModal(e)} />