-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathic-store.js
More file actions
151 lines (125 loc) · 5.43 KB
/
ic-store.js
File metadata and controls
151 lines (125 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* This file is part of VILLASweb.
*
* VILLASweb is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VILLASweb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VILLASweb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import ArrayStore from '../common/array-store';
import ICsDataManager from './ics-data-manager';
import ICDataDataManager from './ic-data-data-manager';
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
import NotificationsFactory from "../common/data-managers/notifications-factory";
import AppDispatcher from '../common/app-dispatcher';
class InfrastructureComponentStore extends ArrayStore {
constructor() {
super('ics', ICsDataManager);
}
reduce(state, action) {
switch(action.type) {
case 'ics/loaded':
return super.reduce(state, action);
case 'ics/edited':
// connect to each infrastructure component
const ic = action.data;
if (ic.websocketurl != null && ic.websocketurl !== '') {
ICDataDataManager.update(ic.websocketurl, ic.id);
}
return super.reduce(state, action);
case 'ics/open-sockets':
// open websocket for each IC contained in array action.data
// action.data contains only those IC used by the scenario
for (let ic of action.data) {
if (ic.websocketurl != null && ic.websocketurl !== '') {
ICDataDataManager.open(ic.websocketurl, ic.id);
} else if (ic.statusupdateraw != null && ic.statusupdateraw.properties != null) {
let rawProps = ic.statusupdateraw.properties
if (rawProps != null && typeof rawProps.server !== 'undefined') {
let url = rawProps.server + '/' + rawProps.session
ICDataDataManager.openWebRTC(url, ic.id);
}
} else {
NotificationsDataManager.addNotification(NotificationsFactory.WEBSOCKET_URL_WARN(ic.name, ic.uuid));
}
}
return super.reduce(state, action);
case 'ics/close-sockets':
// close all websockets
ICDataDataManager.closeAll();
return super.reduce(state, action);
case 'ics/fetched':
return this.updateElements(state, [action.data]);
case 'ics/fetch-error':
return state;
case 'ics/start-action':
if (!Array.isArray(action.action))
action.action = [ action.action ]
if (action.icid !== undefined && action.icid != null && JSON.stringify(action.icid) !== JSON.stringify({})) {
ICsDataManager.doActionsForIC(action.icid, action.action, action.token)
} else {
ICsDataManager.doActionForMultipleICs(action.action, action.result, action.token);
}
return state;
case 'ics/action-started':
NotificationsDataManager.addNotification(NotificationsFactory.ACTION_INFO());
return state;
case 'ics/action-error':
console.log(action.error);
return state;
case 'ics/action-result-added':
for (let a of action.actions){
if (a.results !== undefined && a.results != null){
// adapt URL for newly created result ID
a.results.url = a.results.url.replace("RESULTID", action.data.result.id);
a.results.url = ICsDataManager.makeURL(a.results.url);
a.results.url = 'https://' + window.location.host + a.results.url;
}
if (a.model !== undefined && a.model != null && JSON.stringify(a.model) !== JSON.stringify({})) {
// adapt URL(s) for model file
let modelURLs = []
for (let url of a.model.url){
let modifiedURL = ICsDataManager.makeURL(url);
modifiedURL = 'https://' + window.location.host + modifiedURL;
modelURLs.push(modifiedURL)
}
a.model.url = modelURLs
}
ICsDataManager.doActionsForIC(a.icid, [a], action.token)
}
return state;
case 'ics/action-result-add-error':
console.log(action.error);
return state
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);
}
}
}
export default new InfrastructureComponentStore();