Newer
Older
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
import NrpCoreDashboard from '../nrp-core-dashboard/nrp-core-dashboard';
let _instance = null;
const SINGLETON_ENFORCER = Symbol();
/**
* Service handling server resources for simulating experiments.
*/
class SimulationToolsService {
constructor(enforcer) {
if (enforcer !== SINGLETON_ENFORCER) {
throw new Error('Use ' + this.constructor.name + '.instance');
}
this.tools = new Map();
for (const toolEntry in SimulationToolsService.TOOLS) {
this.registerToolConfig(SimulationToolsService.TOOLS[toolEntry]);
}
this.registerToolConfig(NrpCoreDashboard.CONSTANTS.TOOL_CONFIG);
}
static get instance() {
if (_instance == null) {
_instance = new SimulationToolsService(SINGLETON_ENFORCER);
}
return _instance;
}
registerToolConfig(toolConfig) {
console.info('registerToolConfig');
console.info(toolConfig);
let id = toolConfig.flexlayoutNode.component;
if (this.tools.has(id)) {
console.warn('SimulationToolsService.registerToolConfig() - tool with ID ' + id + ' already exists');
return;
}
this.tools.set(id, toolConfig);
}
flexlayoutNodeFactory(node) {
var component = node.getComponent();
let toolConfig = this.tools.get(component);
if (toolConfig && toolConfig.flexlayoutFactoryCb) {
return toolConfig.flexlayoutFactoryCb();
}
if (component === 'button') {
return <button>{node.getName()}</button>;
}
else if (component === 'nest_wiki') {
return <iframe src='https://en.wikipedia.org/wiki/NEST_(software)' title='nest_wiki'
className='flexlayout-iframe'></iframe>;
}
}
startToolDrag(flexlayoutNode, layoutReference) {
layoutReference.current.addTabWithDragAndDrop(flexlayoutNode.name, flexlayoutNode);
}
}
SimulationToolsService.TOOLS = Object.freeze({
NEST_DESKTOP: {
singleton: true,
flexlayoutNode: {
'type': 'tab',
'name': 'NEST Desktop',
'component': 'nest-desktop'
},
flexlayoutFactoryCb: () => {
return <iframe src='http://localhost:8000' title='NEST Desktop' />;
},
getIcon: () => {
return <div>
<img src={'https://www.nest-simulator.org/wp-content/uploads/2015/03/nest_logo.png'}
alt="NEST Desktop"
style={{width: 40+ 'px', height: 20 + 'px'}} />
<span>Desktop</span>
</div>;
}
},
TEST_NRP_CORE_DOCU: {
singleton: true,
flexlayoutNode: {
'type': 'tab',
'name': 'NRP-Core Docs',
'component': 'nrp-core-docu'
},
flexlayoutFactoryCb: () => {
return <iframe src='https://hbpneurorobotics.bitbucket.io/index.html'
title='NRP-Core Documentation' />;
},
getIcon: () => {
return <span>NRP-Core Docs</span>;
}
}
});
SimulationToolsService.CONSTANTS = Object.freeze({
CATEGORY: {
EXTERNAL_IFRAME: 'EXTERNAL_IFRAME',
REACT_COMPONENT: 'REACT_COMPONENT'
}
});
export default SimulationToolsService;