From e44b8809b2ea94f81250964e680bb09f3ccb0b57 Mon Sep 17 00:00:00 2001 From: Tommy Ip Date: Fri, 17 Nov 2017 18:50:55 +0000 Subject: [PATCH] /team: Render contributors list in tabs client side. --- static/js/portico/landing-page.js | 8 +++++ static/js/portico/team.js | 57 +++++++++++++++++++++++++++++++ static/styles/portico.css | 34 ++++++++++++++++++ templates/zerver/team.html | 43 ++++++++++++++++++----- tools/check-templates | 2 ++ zerver/tests/test_docs.py | 6 ++-- 6 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 static/js/portico/team.js diff --git a/static/js/portico/landing-page.js b/static/js/portico/landing-page.js index a4a215a951..223b173fc7 100644 --- a/static/js/portico/landing-page.js +++ b/static/js/portico/landing-page.js @@ -3,6 +3,8 @@ const ELECTRON_APP_URL_LINUX = "https://github.com/zulip/zulip-electron/releases const ELECTRON_APP_URL_MAC = "https://github.com/zulip/zulip-electron/releases/download/v" + ELECTRON_APP_VERSION + "/Zulip-" + ELECTRON_APP_VERSION + ".dmg"; const ELECTRON_APP_URL_WINDOWS = "https://github.com/zulip/zulip-electron/releases/download/v" + ELECTRON_APP_VERSION + "/Zulip-Web-Setup-" + ELECTRON_APP_VERSION + ".exe"; +import render_tabs from './team.js'; + // this will either smooth scroll to an anchor where the `name` // is the same as the `scroll-to` reference, or to a px height // (as specified like `scroll-to='0px'`). @@ -241,3 +243,9 @@ if (document.readyState === "complete") { } else { $(load); } + +$(function () { + if (window.location.pathname === '/team/') { + render_tabs(); + } +}); diff --git a/static/js/portico/team.js b/static/js/portico/team.js new file mode 100644 index 0000000000..4e79f92228 --- /dev/null +++ b/static/js/portico/team.js @@ -0,0 +1,57 @@ +// Contributor list is baked into the /team's page template, so we can silent +// eslint's error. +/* global contributors_list */ + +var repos = ['server', 'desktop', 'mobile', 'python-zulip-api', 'zulipbot']; + +function contrib_total_commits(contrib) { + var commits = 0; + repos.forEach(function (repo) { + commits += contrib[repo] || 0; + }); + return commits; +} + +// TODO (for v2 of /team contributors): +// - Freeze contributions data for legacy repo (ios, android) and include them +// in totals tab. +// - Lazy-render all but the total tab. +// - Make tab header responsive. +// - Display full name instead of github username. +export default function render_tabs() { + var template = _.template($('#contributors-template').html()); + + var total_tab_html = _.chain(contributors_list) + .map(function (c) { + return { + name: c.name, + avatar: c.avatar, + commits: contrib_total_commits(c), + }; + }) + .sortBy('commits') + .reverse() + .map(function (c) { return template(c); }) + .value() + .join(''); + + $('#tab-total').html(total_tab_html); + + _.each(repos, function (repo) { + var html = _.chain(contributors_list) + .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); + }); +} diff --git a/static/styles/portico.css b/static/styles/portico.css index 67d016d591..0cb0250f86 100644 --- a/static/styles/portico.css +++ b/static/styles/portico.css @@ -904,7 +904,41 @@ a.bottom-signup-button { margin-bottom: 10px; } +.team input { + display: none; +} + +.team label { + font-size: initial; + display: inline-block; + padding: 10px; + border: 1px solid transparent; + margin: 0 0 -1px 0; +} + +.team label:hover { + cursor: pointer; +} + +.team input:checked + label { + border: 1px solid #eee; + border-top: 2px solid yellowgreen; + border-bottom-color: #fff; +} + .contributors { + display: none; +} + +/* Activated .contributors */ +input#total:checked ~ #tab-total, +input#server:checked ~ #tab-server, +input#desktop:checked ~ #tab-desktop, +input#mobile:checked ~ #tab-mobile, +input#python-zulip-api:checked ~ #tab-python-zulip-api, +input#zulipbot:checked ~ #tab-zulipbot { + border-top: 1px solid #eee; + padding-top: 20px; display: grid; grid-gap: 5px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); diff --git a/templates/zerver/team.html b/templates/zerver/team.html index 61cdb99c8e..c71ea5887a 100644 --- a/templates/zerver/team.html +++ b/templates/zerver/team.html @@ -10,6 +10,9 @@ {% stylesheet 'portico' %} {% stylesheet 'landing-page' %} + {{ render_bundle('landing-page') }} {% endblock %} @@ -127,21 +130,45 @@ team have made major contributions to the project.

-
- {% for person in data %} + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + +

Statistic last updated: {{ date }} diff --git a/tools/check-templates b/tools/check-templates index b1b9ebe26f..a818cb88d0 100755 --- a/tools/check-templates +++ b/tools/check-templates @@ -46,6 +46,8 @@ def check_html_templates(templates, all_dups): lambda fn: ('casperjs' not in fn), templates) templates = sorted(list(templates)) + # Use of underscore templates <%= %>. + templates.remove('templates/zerver/team.html') template_id_dict = build_id_dict(templates) # TODO: Clean up these cases of duplicate ids in the code diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index 987fb10292..54211c1a09 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -166,11 +166,9 @@ class AboutPageTest(ZulipTestCase): subprocess.check_call([update_script, '--use-fixture']) # nocoverage def test_endpoint(self) -> None: + """ We can't check the contributors list since it is rendered client-side """ result = self.client_get('/team/') - self.assert_in_success_response( - ['Our amazing community', 'commits', '@timabbott'], - result - ) + self.assert_in_success_response(['Our amazing community'], result) def test_split_by(self) -> None: """Utility function primarily used in authors page"""