/
ReviewInterface.jsx
233 lines (223 loc) · 9.89 KB
/
ReviewInterface.jsx
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
var Intervaller = require('./Intervaller.jsx');
var ReviewContent = require('./ReviewContent.jsx');
module.exports = React.createClass({
getInitialState() {
return {
progressState: "profileChoice",
activeProfileKey: false
};
},
componentWillMount(){
// Skip Profile choice if there's only one
if(_.keys(this.props.profiles).length === 1){
this.setState({
activeProfileKey: _.keys(this.props.profiles)[0]
});
}
},
focusInput(){
if(this.state.progressState === "frontSide" && !this.props.useGuess){
this.refs.flipButton.getDOMNode().focus();
}
},
componentDidMount(){
this.focusInput();
},
componentDidUpdate : function(){
this.focusInput();
},
flip(){
this.setState({progressState: "backSide"});
},
applyInterval(infoIndex, reviewKey, newInterval){
this.props.applyInterval(infoIndex, reviewKey, newInterval);
this.setState({
progressState: "frontSide"
});
},
selectProfile(profileKey){
this.setState({
activeProfileKey: profileKey,
progressState: "frontSide"
})
},
getUrgency(templateReviews){
if(templateReviews.length > 0) {
var lastReview = _.last(templateReviews);
var realInterval = moment().diff(moment(lastReview.reviewTime));
var plannedInterval = moment(lastReview.dueTime).diff(moment(lastReview.reviewTime));
return realInterval / plannedInterval;
}else {
return 1.1;
}
},
guessChange(event){
this.setState({guess: event.target.value});
},
handleGuessKeyDown(evt) {
if (evt.keyCode == 13 ) {
this.flip()
}
},
getDueCounts(){
//var dueCounts =
//_(this.props.profiles).mapValues((profile, profileKey) =>
// _(this.props.infos).map((info, infoIndex) =>
// _(info.reviews).filter((template, templateID) =>
// this.filterInfo(this.props.types[info.typeID].templates[templateID].condition, info) &&
// this.filterInfo(this.props.profiles[profileKey].condition, info) &&
// this.getUrgency(template) >= this.props.profiles[profileKey].dueThreshold
// ).value().length
// ).reduce((a,b) => a+b)
//).value();
var dueCounts =
_(this.props.profiles).mapValues((profile, profileKey) =>
_(this.props.infos).map((info, infoIndex) =>
_(info.reviews).filter((review, reviewKey) =>
filterInfo(this.props.types[info.typeID].templates[reviewKey].condition, info, this.props.types[info.typeID].name) &&
filterInfo(this.props.profiles[profileKey].condition, info, this.props.types[info.typeID].name) &&
(
review.length > 0 ?
moment().diff(moment(_.last(review).reviewTime)) / moment(_.last(review).dueTime).diff(moment(_.last(review).reviewTime)) :
1.1
) >= this.props.profiles[profileKey].dueThreshold
).value().length
).reduce((a,b) => a+b)
).value();
//var dueCounts = _.mapValues(this.props.profiles, () => 0);
//for(var profileKey in this.props.profiles) {
// for (let infoIndex = 0; infoIndex < this.props.infos.length; ++infoIndex) {
// var info = this.props.infos[infoIndex];
// for(var templateID in info.reviews){
// if (
// this.filterInfo(this.props.types[info.typeID].templates[templateID].condition, info) &&
// this.filterInfo(this.props.profiles[profileKey].condition, info) &&
// this.getUrgency(info.reviews[templateID]) >= this.props.profiles[profileKey].dueThreshold
// ) {
// dueCounts[profileKey] += 1;
// }
// }
// }
//}
return dueCounts;
},
getNextReview(profileKey){
var dueness;
var realInterval;
var nextReview = {
dueness: 0.0,
dueCount: 0
};
for (var infoIndex = 0; infoIndex < this.props.infos.length; ++infoIndex) {
var info = this.props.infos[infoIndex];
for(var templateID in info.reviews){
if(info.reviews[templateID].length > 0) {
realInterval = moment().diff(moment(_.last(info.reviews[templateID]).reviewTime));
dueness = realInterval / info.plannedIntervals[templateID];
}else {
dueness = 1.1;
realInterval = 0;
}
if( info["templateConditions"][templateID] &&
info["profileConditions"][profileKey] &&
dueness >= this.props.profiles[profileKey].dueThreshold
){
nextReview.dueCount++;
if (dueness > nextReview.dueness) {
nextReview.dueness = dueness;
nextReview.info = info;
nextReview.infoIndex = infoIndex;
nextReview.templateID = templateID;
nextReview.realInterval = realInterval;
}
}
}
}
return nextReview;
},
render() {
if(!this.state.activeProfileKey){
var nextReviews = _.mapValues(this.props.profiles, (val, profileKey) => this.getNextReview(profileKey));
var sortedProfiles = _(this.props.profiles).mapValues((n, i) => _.merge(n, {"id":i})).values().value();
sortedProfiles = sortedProfiles.sort((a, b) =>a.name.localeCompare(b.name));
return(
<div className="Component">
<section className="Component">
<h3>Select review profile</h3>
</section>
<table className = "profileTable" >
<thead>
<tr>
<th>Profile</th>
<th>Due Count</th>
</tr>
</thead>
< tbody >
{_(sortedProfiles).map((profile) =>
<tr onClick={this.selectProfile.bind(null, profile.id)}>
<td>{profile.name}</td>
<td>{nextReviews[profile.id].dueCount}</td>
</tr>
).value()}
</tbody>
</table>
</div>
);
}
else{
let nextReview = this.getNextReview(this.state.activeProfileKey);
return (
<div className="Component">
<div className="flexRowDistribute">
<button
tabIndex="2"
onClick={this.props.gotoEdit.bind(null, nextReview.infoIndex, nextReview.templateID)}>
Edit Info
</button>
<div className="reviewStatusElement">
<span className="reviewStatusHeading">Due: </span>
<span>{nextReview.dueCount}</span>
</div>
<div className="reviewStatusElement">
<span className="reviewStatusHeading">Dueness: </span>
<span>{nextReview.dueness.toFixed(1)}</span>
</div>
<div className="reviewStatusElement">
<span className="reviewStatusHeading">Profile: </span>
<span>{this.props.profiles[this.state.activeProfileKey].name}</span>
</div>
</div>
{nextReview.dueCount >=1 &&
<div>
<ReviewContent
template={this.props.types[nextReview.info.typeID].templates[nextReview.templateID]}
templateData={_.zipObject(this.props.types[nextReview.info.typeID].entryNames, nextReview.info.entries)}
progressState={this.state.progressState}
useGuess={this.props.useGuess}
onFlip={this.flip}
/>
{this.state.progressState === "frontSide" &&
<div style={{textAlign: "center"}}>
<button
tabIndex="1"
ref="flipButton"
className="buttonGood"
onClick={this.flip}>
Show backside
</button>
</div>
}
<Intervaller
show={this.state.progressState === "backSide"}
lastInterval={nextReview.realInterval}
applyInterval={this.applyInterval.bind(this, nextReview.infoIndex, nextReview.templateID)}
timeIntervalChoices={this.props.timeIntervalChoices}
rememberModType={this.props.rememberModType}
/>
</div>
}
</div>
);
}
}
});