2019-09-13 01:38:24 +02:00
|
|
|
const contributors_list = page_params.contrib;
|
2017-11-17 19:50:55 +01:00
|
|
|
|
2018-08-25 19:16:33 +02:00
|
|
|
// `repos` are repositories to be shown as tabs, whereas `hidden_repos` are
|
|
|
|
// repositories that should count towards the total but not have tabs.
|
2019-11-02 00:06:25 +01:00
|
|
|
const repos = ['server', 'desktop', 'mobile', 'python-zulip-api', 'zulip-js', 'zulipbot', 'terminal'];
|
|
|
|
const hidden_repos = ['zulip-android', 'zulip-ios-legacy'];
|
2017-11-17 19:50:55 +01:00
|
|
|
|
2018-08-25 20:12:12 +02:00
|
|
|
// Remember the loaded repositories so that HTML is not redundantly edited
|
|
|
|
// if a user leaves and then revisits the same tab.
|
2019-11-02 00:06:25 +01:00
|
|
|
const loaded_repos = [];
|
2018-08-25 20:12:12 +02:00
|
|
|
|
2017-11-17 19:50:55 +01:00
|
|
|
function contrib_total_commits(contrib) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let commits = 0;
|
2018-08-25 19:16:33 +02:00
|
|
|
repos.concat(hidden_repos).forEach(function (repo) {
|
2017-11-17 19:50:55 +01:00
|
|
|
commits += contrib[repo] || 0;
|
|
|
|
});
|
|
|
|
return commits;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO (for v2 of /team contributors):
|
|
|
|
// - Make tab header responsive.
|
|
|
|
// - Display full name instead of github username.
|
|
|
|
export default function render_tabs() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const template = _.template($('#contributors-template').html());
|
2017-11-17 19:50:55 +01:00
|
|
|
|
2017-11-22 14:09:51 +01:00
|
|
|
// Since the Github API limits the number of output to 100, we want to
|
|
|
|
// remove anyone in the total tab with less commits than the 100th
|
|
|
|
// contributor to the server repo. (See #7470)
|
2019-11-02 00:06:25 +01:00
|
|
|
const least_server_commits = _.chain(contributors_list)
|
2017-11-22 14:09:51 +01:00
|
|
|
.filter('server')
|
|
|
|
.sortBy('server')
|
|
|
|
.value()[0].server;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const total_tab_html = _.chain(contributors_list)
|
2017-11-17 19:50:55 +01:00
|
|
|
.map(function (c) {
|
|
|
|
return {
|
|
|
|
name: c.name,
|
|
|
|
avatar: c.avatar,
|
|
|
|
commits: contrib_total_commits(c),
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.sortBy('commits')
|
|
|
|
.reverse()
|
2017-11-22 14:09:51 +01:00
|
|
|
.filter(function (c) { return c.commits >= least_server_commits; })
|
2017-11-17 19:50:55 +01:00
|
|
|
.map(function (c) { return template(c); })
|
|
|
|
.value()
|
|
|
|
.join('');
|
|
|
|
|
|
|
|
$('#tab-total').html(total_tab_html);
|
|
|
|
|
|
|
|
_.each(repos, function (repo) {
|
2018-08-25 20:12:12 +02:00
|
|
|
// Set as the loading template for now, and load when clicked.
|
|
|
|
$('#tab-' + repo).html($('#loading-template').html());
|
|
|
|
|
|
|
|
$('#' + repo).click(function () {
|
|
|
|
if (!_.contains(loaded_repos, repo)) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const html = _.chain(contributors_list)
|
2018-08-25 20:12:12 +02:00
|
|
|
.filter(repo)
|
|
|
|
.sortBy(repo)
|
|
|
|
.reverse()
|
|
|
|
.map(function (c) {
|
|
|
|
return template({
|
|
|
|
name: c.name,
|
|
|
|
avatar: c.avatar,
|
|
|
|
commits: c[repo],
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.value()
|
|
|
|
.join('');
|
|
|
|
|
|
|
|
$('#tab-' + repo).html(html);
|
2017-11-17 19:50:55 +01:00
|
|
|
|
2018-08-25 20:12:12 +02:00
|
|
|
loaded_repos.push(repo);
|
|
|
|
}
|
|
|
|
});
|
2017-11-17 19:50:55 +01:00
|
|
|
});
|
|
|
|
}
|