Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show connection state between UI and backend #48

Merged
merged 4 commits into from
May 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/app/scripts/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var Logo = require('./logo');
var SearchBar = require('./search-bar.js');
var AppStore = require('../stores/app-store');
var Groupings = require('./groupings.js');
var Status = require('./status.js');
var Topologies = require('./topologies.js');
var TopologyStore = require('../stores/topology-store');
var WebapiUtils = require('../utils/web-api-utils');
Expand All @@ -22,6 +23,7 @@ var ESC_KEY_CODE = 27;
function getStateFromStores() {
return {
activeTopology: AppStore.getCurrentTopology(),
connectionState: AppStore.getConnectionState(),
currentGrouping: AppStore.getCurrentGrouping(),
selectedNodeId: AppStore.getSelectedNodeId(),
nodeDetails: AppStore.getNodeDetails(),
Expand Down Expand Up @@ -70,6 +72,7 @@ var App = React.createClass({
<Logo />
<Topologies topologies={this.state.topologies} active={this.state.activeTopology} />
<Groupings active={this.state.currentGrouping} />
<Status connectionState={this.state.connectionState} />
</div>

<Nodes nodes={this.state.nodes} />
Expand Down
28 changes: 28 additions & 0 deletions client/app/scripts/components/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** @jsx React.DOM */

var React = require('react');

var Status = React.createClass({

renderConnectionState: function() {
return (
<div className="status-connection">
<span className="status-icon fa fa-exclamation-circle" />
<span className="status-label">Scope is disconnected</span>
</div>
);
},

render: function() {
var isDisconnected = this.props.connectionState === 'disconnected';

return (
<div className="status">
{isDisconnected && this.renderConnectionState()}
</div>
);
}

});

module.exports = Status;
11 changes: 11 additions & 0 deletions client/app/scripts/stores/app-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var TopologyStore = require('./topology-store');

// Initial values

var connectionState = 'disconnected';
var currentGrouping = 'none';
var currentTopology = 'applications';
var nodeDetails = null;
Expand All @@ -31,6 +32,10 @@ var AppStore = assign({}, EventEmitter.prototype, {
};
},

getConnectionState: function() {
return connectionState;
},

getCurrentTopology: function() {
return currentTopology;
},
Expand Down Expand Up @@ -109,6 +114,12 @@ AppStore.dispatchToken = AppDispatcher.register(function(payload) {
AppStore.emit(AppStore.CHANGE_EVENT);
break;

case ActionTypes.RECEIVE_NODES_DELTA:
connectionState = "connected";
AppDispatcher.waitFor([TopologyStore.dispatchToken]);
AppStore.emit(AppStore.CHANGE_EVENT);
break;

case ActionTypes.RECEIVE_TOPOLOGIES:
topologies = payload.topologies;
AppStore.emit(AppStore.CHANGE_EVENT);
Expand Down
12 changes: 7 additions & 5 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ function getTopologies() {
}

function getNodeDetails(topology, nodeId) {
var url = [AppStore.getUrlForTopology(topology), nodeId].join('/');
reqwest(url, function(res) {
AppActions.receiveNodeDetails(res.node);
});
if (nodeId) {
var url = [AppStore.getUrlForTopology(topology), nodeId].join('/');
reqwest(url, function(res) {
AppActions.receiveNodeDetails(res.node);
});
}
}

module.exports = {
Expand All @@ -61,7 +63,7 @@ module.exports = {
getTopologies: getTopologies,

getNodesDelta: function(topologyUrl) {
if (topologyUrl) {
if (topologyUrl && topologyUrl !== currentUrl) {
createWebsocket(topologyUrl);
}
}
Expand Down
19 changes: 19 additions & 0 deletions client/app/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ body {
}
}

.status {
float: right;
position: relative;
margin-top: 14px;
margin-right: 64px;

&-icon {
font-size: 16px;
position: relative;
top: 1px;
color: @text-secondary-color;
}

&-label {
margin-left: 0.5em;
}

}

#stats {

.stat-value {
Expand Down