Skip to content

Commit 41e594e

Browse files
committed
filter by level
1 parent b0d9637 commit 41e594e

File tree

6 files changed

+117
-14
lines changed

6 files changed

+117
-14
lines changed

css/app.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,15 @@ ol.trace > li {
8585
ol.trace .file, ol.trace .line {
8686
font-style: italic;
8787
}
88+
89+
a.checkbox-holder {
90+
line-height: 30px;
91+
}
92+
93+
input[type="checkbox"] {
94+
margin: 5px;
95+
}
96+
97+
label {
98+
margin: 5px;
99+
}

js/App.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import ReactScrolla from 'react-scrolla';
44

55
import {LogProvider} from './Providers/LogProvider.js';
66
import {LogTable} from './Components/LogTable.js';
7-
import {SideBar} from './Components/SideBar.js';
7+
import {SideBar, Entry, Separator} from './Components/SideBar.js';
8+
import {ToggleEntry} from './Components/ToggleEntry.js';
9+
import {App as OCApp} from './Components/App.js';
810

911
import {LogSearch} from './Search.js';
1012

1113
export class App extends Component {
1214
state = {
1315
'entries': [],
14-
'loading': false
16+
'loading': false,
17+
'levels': [true, true, true, true, true]
1518
};
1619

1720
constructor () {
@@ -31,23 +34,40 @@ export class App extends Component {
3134
this.setState({loading: false});
3235
};
3336

37+
setLevel (level, newState) {
38+
let levels = this.state.levels;
39+
levels[level] = newState;
40+
this.setState({levels});
41+
}
42+
3443
render () {
44+
let entries = this.state.entries.filter(entry=> {
45+
return this.state.levels[entry.level];
46+
});
47+
48+
let filters = this.state.levels.map((status, level)=> {
49+
return (
50+
<ToggleEntry active={status}
51+
onChange={this.setLevel.bind(this, level)}>
52+
{LogProvider.levels[level]}
53+
</ToggleEntry>
54+
);
55+
});
56+
3557
return (
36-
<div id="content" role="main" className={"app-" + this.props.appId}>
58+
<OCApp appId="logreader">
3759
<SideBar>
38-
<p>Dummy 1</p>
39-
40-
<p>Dummy 2</p>
60+
{filters}
4161
</SideBar>
4262

4363
<ReactScrolla
4464
id="app-content"
4565
percentage={85}
4666
onPercentage={this.fetchNextPage}
4767
isLoading={this.state.loading}>
48-
<LogTable entries={this.state.entries}/>
68+
<LogTable entries={entries}/>
4969
</ReactScrolla>
50-
</div>
70+
</OCApp>
5171
);
5272
}
5373
}

js/Components/App.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from 'react/addons';
2+
3+
export class App extends Component {
4+
render () {
5+
return (
6+
<div id="content" role="main" className={"app-" + this.props.appId}>
7+
{this.props.children}
8+
</div>
9+
);
10+
}
11+
}

js/Components/SideBar.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@ export class SideBar extends Component {
77
return <li key={i}>{child}</li>
88
});
99
return (
10-
<div id="app-navigation">
11-
<ul>
12-
{entries}
13-
</ul>
14-
</div>
10+
<ul id="app-navigation">
11+
{this.props.children}
12+
</ul>
13+
);
14+
}
15+
}
16+
17+
export class Entry extends Component {
18+
render () {
19+
return (
20+
<li>{this.props.children}</li>
21+
);
22+
}
23+
}
24+
25+
export class Separator extends Component {
26+
render () {
27+
return (
28+
<li className="app-navigation-separator"/>
1529
);
1630
}
1731
}

js/Components/ToggleEntry.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {Component} from 'react/addons';
2+
3+
export class ToggleEntry extends Component {
4+
static idCounter = 0;
5+
_id = null;
6+
7+
state = {
8+
active: false
9+
};
10+
11+
constructor (props) {
12+
super();
13+
this.state.active = props.active || false;
14+
}
15+
16+
get id () {
17+
if (!this._id) {
18+
this._id = this.props.id || '__checkbox_' + (++ToggleEntry.idCounter);
19+
}
20+
return this._id;
21+
}
22+
23+
onChange = (event)=> {
24+
25+
};
26+
27+
onClick = () => {
28+
let active = !this.state.active;
29+
this.setState({active});
30+
if (this.props.onChange) {
31+
this.props.onChange(active);
32+
}
33+
};
34+
35+
render () {
36+
return (
37+
<li>
38+
<a className="checkbox-holder" onClick={this.onClick}>
39+
<input id={this.id} type="checkbox"
40+
checked={this.state.active}/>
41+
<label htmlFor={this.id}>{this.props.children}</label>
42+
</a>
43+
</li>
44+
);
45+
}
46+
}

js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ if (process.env.NODE_ENV !== 'production') {
1010
}
1111

1212
$(document).ready(() => {
13-
React.render(<App appId="logreader" />, document.getElementById('content'));
13+
React.render(<App />, document.getElementById('content'));
1414
});

0 commit comments

Comments
 (0)