3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import TopologyL2Actions
from './topologyL2Actions.js';
19 import TopologyL2Source
from './topologyL2Source.js';
20 import Alt
from '../alt';
21 let rw
= require('utils/rw.js');
22 class TopologyL2Store
{
26 this.isLoading
= true;
32 this.errorMessage
= null;
34 this.detailView
= null;
36 this.bindActions(TopologyL2Actions
);
37 // bind source listeners
38 this.exportAsync(TopologyL2Source
);
39 this.exportPublicMethods({
40 closeSocket
: this.closeSocket
,
41 getTopologyData
: this.getTopologyData
43 this.ajax_mode
= rw
.getSearchParams(window
.location
).ajax_mode
|| false;
46 getTopologyData
= (id
) => {
48 this.getInstance().fetchTopology();
50 this.getInstance().openTopologyApiSocket(id
);
53 openTopologyApiSocketLoading() {}
54 openTopologyApiSocketSuccess
= (connection
) => {
57 let connectionManager
= (type
, connection
) => {
58 let ws
= window
.multiplexer
.channel(connection
);
60 console
.warn('There was an issue connecting to the ' + type
+ ' socket');
70 ws
.onmessage = function(data
) {
72 topologyData
: JSON
.parse(data
.data
),
78 connectionManager('foo-type', connection
);
81 openTopologyApiSocketError() {}
83 handleLogout
= () => {
89 window
.multiplexer
.channel(this.channelId
).close();
95 this.detailView
= null;
96 this.hasSelected
= false;
99 getTopologyApiSuccess
: TopologyL2Actions
.GET_TOPOLOGY_API_SUCCESS
,
100 getTopologyApiLoading
: TopologyL2Actions
.GET_TOPOLOGY_API_LOADING
,
101 getTopologyApiError
: TopologyL2Actions
.GET_TOPOLOGY_API_ERROR
103 // bind source listeners
104 this.exportAsync(TopologyL2Source
);
107 getTopologyApiSuccess
= (data
) => {
114 getTopologyApiLoading
= () => {}
116 getTopologyApiError
= (errorMessage
) => {
117 this.errorMessage
= errorMessage
;
120 getNodeData
= (node_id
) => {
121 // find node in thisa.topologyData.nodes
122 var node_data
= this.topologyData
.nodes
.find(
123 function(element
, index
, array
) {
124 return (element
.id
== node_id
);
129 nodeClicked
= (node_id
) => {
131 detailData
: this.getNodeData(node_id
)
135 export default Alt
.createStore(TopologyL2Store
);