forked from krawaller/riaguild2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.js
99 lines (95 loc) · 3.09 KB
/
actions.js
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
var React = require("react"),
_ = require("lodash"),
Badge = require("./badge"),
mem = require("../data/members"),
members = mem.members,
actions = mem.actions;
function ordernum(n){
return n + ({1:"st",2:"nd",3:"rd"}[n % 10] || "th");
}
var Actions = React.createClass({
nameFilterFunction: function(info) {
return members[info.by].name.toUpperCase().indexOf(this.state.filterName.toUpperCase()) > -1;
},
whatFilterFunction: function(info) {
return info.description.toUpperCase().indexOf(this.state.filterWhat.toUpperCase()) > -1;
},
typeFilterFunction: function(info) {
switch (this.state.filterType) {
case "posts":
return info.type === "post";
case "prs":
return info.type === "pr";
default:
return true;
}
},
getInitialState: function() {
return { filterName: "", filterWhat: "", filterType: "all" };
},
handleNameFilterChange: function(event) {
this.setState({ filterName: event.target.value });
},
handleWhatFilterChange: function(event) {
this.setState({ filterWhat: event.target.value });
},
handleTypeFilterChange: function(filterBy) {
this.setState({ filterType: filterBy });
},
render: function(){
var rows = _.map(actions.filter(this.nameFilterFunction).filter(this.whatFilterFunction).filter(this.typeFilterFunction),function(info,id){
var user = members[info.by],
tuser = members[info.target] || {github: null};
return (
<tr key={id}>
<td><Badge id={user.github} /></td>
<td>{info.when.substr(0,10)}<br/>{info.when.substr(11)}</td>
<td>
{ {pr:"made",post:"wrote"}[info.type]+" "+ordernum(info.number)+" "+{pr:"PR",post:"post"}[info.type]+(info.sageadvice?" (sage advice!)":"")+": " }
<br/>
<a href={info.url} target="_blank">{info.description}</a>
</td>
<td>{info.type ==='pr' && <span><Badge id={tuser.github} /></span> || ""}</td>
</tr>
);
});
return (
<div>
<p>There's been {mem.numberofposts} posts and {mem.numberofprs} pull requests so far:</p>
<table className="table table-striped">
<thead>
<tr><th>Who</th><th>When</th><th>What</th><th>Target (if PR)</th></tr>
<tr>
<th><input type="text" placeholder="Filter..." value={this.state.filterName} onChange={this.handleNameFilterChange} /></th>
<th></th>
<th><input type="text" placeholder="Filter..." value={this.state.filterWhat} onChange={this.handleWhatFilterChange} /></th>
<th></th>
</tr>
<tr>
<th colSpan="4">
<form>
<label>
Show all
<input type="radio" name="filter" defaultChecked onClick={ this.handleTypeFilterChange.bind(this, "all") } />
</label>
<label>
Show posts
<input type="radio" name="filter" onClick={ this.handleTypeFilterChange.bind(this, "posts") } />
</label>
<label>
Show PR:s
<input type="radio" name="filter" onClick={ this.handleTypeFilterChange.bind(this, "prs") } />
</label>
</form>
</th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
</div>
);
}
});
module.exports = Actions;