-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render top contributors in detaild stats via react
Fix #4699
- Loading branch information
Showing
9 changed files
with
181 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) Pootle contributors. | ||
* | ||
* This file is a part of the Pootle project. It is distributed under the GPL3 | ||
* or later license. See the LICENSE file for a copy of the license and the | ||
* AUTHORS file for copyright and authorship information. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import StatsAPI from 'api/StatsAPI'; | ||
import TopContributors from './TopContributors'; | ||
|
||
|
||
const Stats = React.createClass({ | ||
|
||
propTypes: { | ||
topContributors: React.PropTypes.array.isRequired, | ||
hasMoreContributors: React.PropTypes.bool.isRequired, | ||
pootlePath: React.PropTypes.string.isRequired, | ||
}, | ||
|
||
getInitialState() { | ||
return { | ||
topContributors: this.props.topContributors, | ||
hasMoreContributors: this.props.hasMoreContributors, | ||
}; | ||
}, | ||
|
||
onLoadMoreTopContributors(data) { | ||
const topContributors = this.state.topContributors.concat(data.items); | ||
this.setState({ | ||
topContributors, | ||
hasMoreContributors: data.has_more_items, | ||
}); | ||
}, | ||
|
||
loadMoreTopContributors() { | ||
if (!this.state.hasMoreContributors) { | ||
return false; | ||
} | ||
const params = { offset: this.state.topContributors.length }; | ||
return StatsAPI.getTopContributors(this.props.pootlePath, params) | ||
.done(this.onLoadMoreTopContributors); | ||
}, | ||
|
||
render() { | ||
return ( | ||
<TopContributors | ||
items={this.state.topContributors} | ||
hasMoreItems={this.state.hasMoreContributors} | ||
loadMore={this.loadMoreTopContributors} | ||
/> | ||
); | ||
}, | ||
|
||
}); | ||
|
||
|
||
export default Stats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) Pootle contributors. | ||
* | ||
* This file is a part of the Pootle project. It is distributed under the GPL3 | ||
* or later license. See the LICENSE file for a copy of the license and the | ||
* AUTHORS file for copyright and authorship information. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import Avatar from 'components/Avatar'; | ||
import { t } from 'utils/i18n'; | ||
|
||
|
||
function getScoreText(score) { | ||
if (score > 0) { | ||
return t('+%(score)s', { score }); | ||
} | ||
return score; | ||
} | ||
|
||
|
||
const TopContributors = React.createClass({ | ||
|
||
propTypes: { | ||
items: React.PropTypes.array.isRequired, | ||
hasMoreItems: React.PropTypes.bool.isRequired, | ||
loadMore: React.PropTypes.func.isRequired, | ||
}, | ||
|
||
createRow(item, index) { | ||
const title = (` | ||
<span class="value">${item.suggested}</span> suggested<br/> | ||
<span class="value">${item.translated}</span> translated<br/> | ||
<span class="value">${item.reviewed}</span> reviewed<br/> | ||
`); | ||
return ( | ||
<tr key={`top-contibutor-${index}`}> | ||
<td className="number">{t('#%(position)s', { position: index + 1 })}</td> | ||
<td className="user top-scorer"> | ||
<Avatar | ||
email={item.email} | ||
label={item.display_name} | ||
size={20} | ||
username={item.username} | ||
/> | ||
</td> | ||
<td className="number"> | ||
<span title={title}>{getScoreText(item.public_total_score)}</span> | ||
</td> | ||
</tr> | ||
); | ||
}, | ||
|
||
render() { | ||
let loadMore; | ||
|
||
if (this.props.hasMoreItems) { | ||
loadMore = ( | ||
<div className="more-top-contributors"> | ||
<a onClick={this.props.loadMore}> | ||
<span className="show-more">{gettext('More...')}</span> | ||
</a> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div> | ||
<table className="top-scorers-table"> | ||
<tbody> | ||
{this.props.items.map(this.createRow)} | ||
</tbody> | ||
</table> | ||
{loadMore} | ||
</div> | ||
); | ||
}, | ||
|
||
}); | ||
|
||
|
||
export default TopContributors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.