Skip to content

Commit

Permalink
Merge pull request #78 from Capgemini/starting-tasks-support
Browse files Browse the repository at this point in the history
Starting tasks support
  • Loading branch information
enxebre committed Mar 9, 2016
2 parents f79cf3a + 16e75af commit 6870c1b
Show file tree
Hide file tree
Showing 15 changed files with 2,697 additions and 231 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"indent": [2, 2, {SwitchCase: 1}],
"jsx-quotes": 1,
"quotes": [2, "single"],
"camelcase": 2,
"camelcase": 0,
"no-undefined": 2,
"no-unused-vars": 0,
"curly": 2,
Expand Down
10 changes: 9 additions & 1 deletion src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class App extends React.Component {
stats: ClusterStore.getStats(),
logs: ClusterStore.getLogs(),
frameworks: ClusterStore.getFrameworks(),
tasks: ClusterStore.getTasks(),
nodes: ClusterStore.getNodes(),
leader: ClusterStore.getLeader(),
pid: ClusterStore.getPid(),
Expand All @@ -60,6 +61,8 @@ class App extends React.Component {
window.addEventListener('resize', this.handleResize);
this.handleResize();

//TODO: we are rerendering components too many times
// everytime we make a mesos request with current approach.
ClusterStore.addChangeListener(this.refreshStats.bind(this));
ClusterStore.addChangeListener(this.refreshLogs.bind(this));
ClusterStore.addChangeListener(this.refreshState.bind(this));
Expand All @@ -69,6 +72,7 @@ class App extends React.Component {
if (this.mounted) {
this.setState( {
frameworks: ClusterStore.getFrameworks(),
tasks: ClusterStore.getTasks(),
nodes: ClusterStore.getNodes(),
leader: ClusterStore.getLeader(),
pid: ClusterStore.getPid(),
Expand Down Expand Up @@ -117,18 +121,21 @@ class App extends React.Component {
};
let dashboardIcon = React.createElement(FontIcon, {style: iconStyle, className: 'material-icons'}, 'settings_input_svideo' );
let nodesIcon = React.createElement(FontIcon, {style: iconStyle, className: 'material-icons'}, 'dns' );
let frameworksIcon = React.createElement(FontIcon, {style: iconStyle, className: 'material-icons'}, 'build' );
let TasksIcon = React.createElement(FontIcon, {style: iconStyle, className: 'material-icons'}, 'track_changes' );
let frameworksIcon = React.createElement(FontIcon, {style: iconStyle, className: 'material-icons'}, 'schedule' );
let logsIcon = React.createElement(FontIcon, {style: iconStyle, className: 'material-icons'}, 'assignment ' );

let logsText = this.state.leftNavExpanded ? 'Logs' : '';
let dashboardText = this.state.leftNavExpanded ? 'Dashboard' : '';
let frameworksText = this.state.leftNavExpanded ? 'Frameworks' : '';
let nodesText = this.state.leftNavExpanded ? 'Nodes' : '';
let tasksText = this.state.leftNavExpanded ? 'Tasks' : '';

return [
{ route: '/', text: dashboardText, icon: dashboardIcon },
{ route: 'frameworks', text: frameworksText, icon: frameworksIcon },
{ route: 'nodes', text: nodesText, icon: nodesIcon },
{ route: 'tasks', text: tasksText, icon: TasksIcon },
{ route: 'logs', text: logsText, icon: logsIcon }
];
}
Expand Down Expand Up @@ -229,6 +236,7 @@ class App extends React.Component {
{...this.props}
nodes={this.state.nodes}
frameworks={this.state.frameworks}
tasks = {this.state.tasks}
stats={this.state.stats}
logs={this.state.logs}
/>
Expand Down
30 changes: 30 additions & 0 deletions src/components/Circle/Circle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { PropTypes } from 'react';

class Circle extends React.Component {

static propTypes = {
radius: PropTypes.number.isRequired,
color: PropTypes.string.isRequired
};

constructor(props) {
super(props);
}

render() {
const style = {
background: 'radial-gradient(' + this.props.color +' 5%, hsla(0, 100%, 20%, 0) 90%) 0 0',
width: this.props.radius,
height: this.props.radius,
borderRadius: this.props.radius,
margin: 3,
borderWidth: 1,
borderStyle: 'solid',
borderColor: this.props.color,
float: 'left'
};
return (<div style={style}></div>);
}
}

export default Circle;
6 changes: 6 additions & 0 deletions src/components/Circle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Circle",
"version": "0.0.0",
"private": true,
"main": "./Circle.js"
}
155 changes: 155 additions & 0 deletions src/components/TaskTable/TaskTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import React, { PropTypes } from 'react';
import Table from 'material-ui/lib/table/table';
import TableHeaderColumn from 'material-ui/lib/table/table-header-column';
import TableRow from 'material-ui/lib/table/table-row';
import TableHeader from 'material-ui/lib/table/table-header';
import TableRowColumn from 'material-ui/lib/table/table-row-column';
import TableBody from 'material-ui/lib/table/table-body';
import RadioButton from 'material-ui/lib/radio-button';
import RadioButtonGroup from 'material-ui/lib/radio-button-group';

class TaskTable extends React.Component {

static propTypes = {
tasks: PropTypes.array.isRequired
};

constructor() {
super();
this.state = {
parameterToOrderBy: 'timestamp',
};
}

setParameterToOrderBy(e) {
this.setState({parameterToOrderBy: e.target.value});
}

orderTasksByParameter(tasks = [], parameterToOrderBy = 'timestamp') {
var parameter = parameterToOrderBy;
tasks.sort(function(a, b) {
if (a[parameter] < b[parameter]) {
return 1;
}
if (a[parameter] > b[parameter]) {
return -1;
}
return 0;
});
return tasks;
}

renderOrderBox() {
// We Can't just order on table header clicks due to:
//https://github.com/callemall/material-ui/issues/1783
//https://github.com/callemall/material-ui/issues/2011
return(
<div style={this.getStyles().orderBox}>
<span>Order tasks by:</span>
<RadioButtonGroup ref="orderByRadioButtonGroup" name="orderByRadioButtonGroup" valueSelected={this.state.parameterToOrderBy} onChange={this.setParameterToOrderBy.bind(this)}>
<RadioButton
ref="orderByTime"
value="timestamp"
label="Up time"
style={this.getStyles().radioButton}
/>
<RadioButton
ref="orderById"
value="id"
label="ID"
style={this.getStyles().radioButton}
/>
<RadioButton
ref="orderByHost"
value="hostname"
label="Host"
style={this.getStyles().radioButton}
/>
</RadioButtonGroup>
</div>
);
}

getStyles() {
return {
radioButton: {
width: 150,
float: 'left'

},
orderBox: {
height: 30,
padding: 20
}
};
}

//http://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site
timeSince(date) {

var seconds = Math.floor((new Date() - date*1000) / 1000);

var interval = Math.floor(seconds / 31536000);

if (interval > 1) {
return interval + ' years';
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return interval + ' months';
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return interval + ' days';
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return interval + ' hours';
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return interval + ' minutes';
}
return Math.floor(seconds) + ' seconds';
}


render() {

let tasks = this.props.tasks.slice();
let orderedTasks = this.orderTasksByParameter(tasks, this.state.parameterToOrderBy);
return (
<div>
{this.renderOrderBox()}
<Table>
<TableHeader displaySelectAll={false} adjustForCheckbox={false}>
<TableRow displayRowCheckbox={false} selectable={true}>
<TableHeaderColumn>ID</TableHeaderColumn>
<TableHeaderColumn>Name</TableHeaderColumn>
<TableHeaderColumn>Status</TableHeaderColumn>
<TableHeaderColumn>Up time</TableHeaderColumn>
<TableHeaderColumn>Framework</TableHeaderColumn>
<TableHeaderColumn>Host</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody displayRowCheckbox={false} selectable={false}>
{orderedTasks.map((task) =>
<TableRow key={task.id}>
<TableRowColumn>{task.id}</TableRowColumn>
<TableRowColumn>{task.name}</TableRowColumn>
<TableRowColumn>{task.state}</TableRowColumn>
<TableRowColumn>{this.timeSince(task.timestamp)}</TableRowColumn>
<TableRowColumn>{task.framework_name}</TableRowColumn>
<TableRowColumn>{task.hostname}</TableRowColumn>
</TableRow>
)
}
</TableBody>
</Table>
</div>
);
}
}

export default TaskTable;

6 changes: 6 additions & 0 deletions src/components/TaskTable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "TaskTable",
"version": "0.0.0",
"private": true,
"main": "./TaskTable.js"
}
Loading

0 comments on commit 6870c1b

Please sign in to comment.