mirror of
https://github.com/DragonMinded/bemaniutils.git
synced 2026-04-01 06:34:52 -05:00
180 lines
7.2 KiB
JavaScript
180 lines
7.2 KiB
JavaScript
/*** @jsx React.DOM */
|
|
|
|
var network_scores = createReactClass({
|
|
getInitialState: function(props) {
|
|
return {
|
|
songs: window.songs,
|
|
attempts: window.attempts,
|
|
players: window.players,
|
|
loading: true,
|
|
offset: 0,
|
|
limit: 10,
|
|
};
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
this.refreshScores();
|
|
},
|
|
|
|
refreshScores: function() {
|
|
AJAX.get(
|
|
Link.get('refresh'),
|
|
function(response) {
|
|
this.setState({
|
|
attempts: response.attempts,
|
|
players: response.players,
|
|
loading: false,
|
|
});
|
|
// Refresh every 15 seconds
|
|
setTimeout(this.refreshScores, 15000);
|
|
}.bind(this)
|
|
);
|
|
},
|
|
|
|
convertChart: function(chart) {
|
|
switch(chart) {
|
|
case 0:
|
|
return 'Green (\u7FE0)';
|
|
case 1:
|
|
return 'Orange (\u6A59)';
|
|
case 2:
|
|
return 'Red (\u6731)';
|
|
default:
|
|
return 'u broke it';
|
|
}
|
|
},
|
|
|
|
convertChartLink: function(chart) {
|
|
switch(chart) {
|
|
case 0:
|
|
return 'green';
|
|
case 1:
|
|
return 'orange';
|
|
case 2:
|
|
return 'red';
|
|
default:
|
|
return 'nothing';
|
|
}
|
|
},
|
|
|
|
renderScore: function(score) {
|
|
has_stats = (
|
|
score.stats.critical > 0 ||
|
|
score.stats.near > 0 ||
|
|
score.stats.error > 0
|
|
);
|
|
return (
|
|
<div className="score">
|
|
<div>
|
|
<span className="label">Score</span>
|
|
<span className="score">{score.points}</span>
|
|
<span className="label">Combo</span>
|
|
<span className="score">{score.combo < 0 ? '-' : score.combo}</span>
|
|
<span className="status">{score.grade}</span>
|
|
</div>
|
|
{has_stats ? <div title="critical / near / error">
|
|
{score.stats.critical}
|
|
<span> / </span>
|
|
{score.stats.near}
|
|
<span> / </span>
|
|
{score.stats.error}
|
|
</div> : null}
|
|
<div>
|
|
<span className="status">{score.clear_type}</span>
|
|
</div>
|
|
</div>
|
|
);
|
|
},
|
|
|
|
render: function() {
|
|
return (
|
|
<div>
|
|
<table className="list attempts">
|
|
<thead>
|
|
<tr>
|
|
{ window.shownames ? <th>Name</th> : null }
|
|
<th>Timestamp</th>
|
|
<th>Song / Artist</th>
|
|
<th>Difficulty</th>
|
|
<th>Score</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{this.state.attempts.map(function(attempt, index) {
|
|
if (index < this.state.offset || index >= this.state.offset + this.state.limit) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<tr>
|
|
{ window.shownames ? <td><a href={Link.get('player', attempt.userid)}>{
|
|
this.state.players[attempt.userid].name
|
|
}</a></td> : null }
|
|
<td>
|
|
<div>
|
|
<Timestamp timestamp={attempt.timestamp} />
|
|
{ window.shownewrecords && attempt.raised ?
|
|
<span className="raised">new high score!</span> :
|
|
null
|
|
}
|
|
</div>
|
|
</td>
|
|
<td className="center">
|
|
<a href={Link.get('individual_score', attempt.songid)}>
|
|
<div className="songname">{ this.state.songs[attempt.songid].name }</div>
|
|
<div className="songartist">{ this.state.songs[attempt.songid].artist }</div>
|
|
</a>
|
|
</td>
|
|
<td className="center">
|
|
<div>
|
|
<a href={Link.get('individual_score', attempt.songid, this.convertChartLink(attempt.chart))}>{
|
|
this.convertChart(attempt.chart)
|
|
}</a>
|
|
</div>
|
|
<div>{
|
|
this.state.songs[attempt.songid].difficulties[attempt.chart]
|
|
}</div>
|
|
</td>
|
|
<td>{ this.renderScore(attempt) }</td>
|
|
</tr>
|
|
);
|
|
}.bind(this))}
|
|
</tbody>
|
|
<tfoot>
|
|
<tr>
|
|
<td colSpan={5}>
|
|
{ this.state.offset > 0 ?
|
|
<Prev onClick={function(event) {
|
|
var page = this.state.offset - this.state.limit;
|
|
if (page < 0) { page = 0; }
|
|
this.setState({offset: page});
|
|
}.bind(this)}/> : null
|
|
}
|
|
{ (this.state.offset + this.state.limit) < this.state.attempts.length ?
|
|
<Next style={ {float: 'right'} } onClick={function(event) {
|
|
var page = this.state.offset + this.state.limit;
|
|
if (page >= this.state.attempts.length) { return }
|
|
this.setState({offset: page});
|
|
}.bind(this)}/> :
|
|
this.state.loading ?
|
|
<span className="loading" style={ {float: 'right' } }>
|
|
<img
|
|
className="loading"
|
|
src={Link.get('static', window.assets + 'loading-16.gif')}
|
|
/> loading more scores...
|
|
</span> : null
|
|
}
|
|
</td>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
);
|
|
},
|
|
});
|
|
|
|
ReactDOM.render(
|
|
React.createElement(network_scores, null),
|
|
document.getElementById('content')
|
|
);
|