From 87d795a4d6c7e5eddcc3e7a7d67e3aa2aac0fa2b Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 31 Aug 2015 23:45:12 -0400 Subject: [PATCH 1/2] Implement tabs for Team review state --- js/gratipay.js | 1 + js/gratipay/giving.js | 29 ------- js/gratipay/tabs.js | 29 +++++++ www/index.html.spt | 116 +++++++++++++++----------- www/~/%username/giving/index.html.spt | 11 +-- 5 files changed, 102 insertions(+), 84 deletions(-) delete mode 100644 js/gratipay/giving.js create mode 100644 js/gratipay/tabs.js diff --git a/js/gratipay.js b/js/gratipay.js index 6429168501..dededc58ba 100644 --- a/js/gratipay.js +++ b/js/gratipay.js @@ -17,6 +17,7 @@ Gratipay.init = function() { Gratipay.signIn(); Gratipay.signOut(); Gratipay.payments.initSupportGratipay(); + Gratipay.tabs.init(); }; Gratipay.warnOffUsersFromDeveloperConsole = function() { diff --git a/js/gratipay/giving.js b/js/gratipay/giving.js deleted file mode 100644 index 93db2ccd2e..0000000000 --- a/js/gratipay/giving.js +++ /dev/null @@ -1,29 +0,0 @@ -Gratipay.giving = {} - -Gratipay.giving.init = function() { - Gratipay.giving.activateTab('active'); - $('.giving #tab-nav a').on('click', Gratipay.giving.handleClick); -} - -Gratipay.giving.handleClick = function(e) { - e.preventDefault(); - var $target = $(e.target); - Gratipay.giving.activateTab($target.data('tab')); -} - -Gratipay.giving.activateTab = function(tab) { - $.each($('.giving #tab-nav a'), function(i, obj) { - var $obj = $(obj); - if ($obj.data('tab') == tab) { - $obj.addClass('selected'); - } else { - $obj.removeClass('selected'); - } - }) - - $.each($('.giving .tab'), function(i, obj) { - var $obj = $(obj); - if ($obj.data('tab') == tab) { $obj.show(); } else { $obj.hide(); } - }) -} - diff --git a/js/gratipay/tabs.js b/js/gratipay/tabs.js new file mode 100644 index 0000000000..c1419bebe0 --- /dev/null +++ b/js/gratipay/tabs.js @@ -0,0 +1,29 @@ +Gratipay.tabs = {} + +Gratipay.tabs.init = function() { + var firstTab = $('.tab').first().data('tab'); + Gratipay.tabs.activateTab(firstTab); + $('.tabs #tab-nav a').on('click', Gratipay.tabs.handleClick); +} + +Gratipay.tabs.handleClick = function(e) { + e.preventDefault(); + var $target = $(e.target); + Gratipay.tabs.activateTab($target.data('tab')); +} + +Gratipay.tabs.activateTab = function(tab) { + $.each($('.tabs #tab-nav a'), function(i, obj) { + var $obj = $(obj); + if ($obj.data('tab') == tab) { + $obj.addClass('selected'); + } else { + $obj.removeClass('selected'); + } + }) + + $.each($('.tabs .tab'), function(i, obj) { + var $obj = $(obj); + if ($obj.data('tab') == tab) { $obj.show(); } else { $obj.hide(); } + }) +} diff --git a/www/index.html.spt b/www/index.html.spt index 6aa6148a19..41c30bc121 100644 --- a/www/index.html.spt +++ b/www/index.html.spt @@ -1,4 +1,10 @@ +from collections import OrderedDict [---] +i18ned_statuses = { "unreviewed" : _("Under Review") + , "rejected": _("Rejected") + , "approved": _("Approved") + } + teams = website.db.all(""" SELECT teams.*::teams @@ -6,13 +12,20 @@ teams = website.db.all(""" ORDER BY ctime DESC """) -napproved = len([t for t in teams if t.is_approved]) -nteams = len(teams) if user.ADMIN else napproved -statuses = { "unreviewed" : _("under review") - , "rejected": _("rejected") - , "approved": _("approved") - } +tabs = OrderedDict() +tabs['approved'] = {'teams': []} +tabs['unreviewed'] = {'teams': []} +tabs['rejected'] = {'teams': []} + +for team in teams: + tabs[team.status]['teams'].append(team) + +nteams = 0 +for key, tab in tabs.items(): + n = tab['n'] = len(tab['teams']) + nteams += n + tab['name'] = "{} (n={})".format(i18ned_statuses[key], n) title = _("Teams (N={0})", nteams) suppress_sidebar = True @@ -60,56 +73,65 @@ suppress_welcome = 'suppress-welcome' in request.cookie {% endif %} - - {% for team in teams %} - - + + {% endfor %} +
- {{ team.name }} +
+ -
- {{ statuses[team.status] }} - · {{ _("created {ago}", - ago=to_age(team.ctime, add_direction=True)) }} - · - {{ _( "owned by {a}{owner}{_a}" - , owner='~'+team.owner - , a=(''|safe).format(team.owner) - , _a=''|safe - ) }} - -
+ {% for tab in tabs %} + + {% for team in tabs[tab]['teams'] %} + + - +
+ {{ i18ned_statuses[team.status] }} + · {{ _("created {ago}", + ago=to_age(team.ctime, add_direction=True)) }} + · + {{ _( "owned by {a}{owner}{_a}" + , owner='~'+team.owner + , a=(''|safe).format(team.owner) + , _a=''|safe + ) }} + +
+ + {% if team.status == 'approved' %} +
+ {{ team.name }} - {% if team.status == 'approved' %} - - - - - - - - - - - - - - - - -
{{ _("Weekly") }}Σ  n
{{ _("Receiving") }}{{ format_currency(team.receiving, 'USD') - if team.receiving else '-  '|safe }}{{ team.nreceiving_from if team.nreceiving_from else '-' }}
{{ _("Sharing") }}-  -
- {% endif %} -
+ + + + + + + + + + + + + + + +
{{ _("Weekly") }}Σ  n
{{ _("Receiving") }}{{ format_currency(team.receiving, 'USD') + if team.receiving else '-  '|safe }}{{ team.nreceiving_from if team.nreceiving_from else '-' }}
{{ _("Sharing") }}-  -
+ {% endif %} +
{% endfor %} - + {% endblock %} {% block scripts %} -{{ super() }} -{% endblock %} - {% block content %} -
+
-{% for tab in tabs.keys() %} +{% for tab in tabs %}
{% if tabs[tab]['ngiving'] %} From fd32b8fd5e2b86b6788c738c673aa1529f28f1e9 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Tue, 1 Sep 2015 00:13:28 -0400 Subject: [PATCH 2/2] Show n for tabs, no top-level N --- tests/js/test_authed_homepage.js | 2 +- www/index.html.spt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/js/test_authed_homepage.js b/tests/js/test_authed_homepage.js index d09c3effe0..e1174935fd 100644 --- a/tests/js/test_authed_homepage.js +++ b/tests/js/test_authed_homepage.js @@ -23,7 +23,7 @@ describe('authed homepage', function() { browser .url('http://localhost:8537') .getText('#content h1', function(err, text) { - assert.equal(text, 'Teams (N=0)'); + assert.equal(text, 'Teams'); }) .deleteCookie('session') .call(done); diff --git a/www/index.html.spt b/www/index.html.spt index 41c30bc121..2a2814aee0 100644 --- a/www/index.html.spt +++ b/www/index.html.spt @@ -27,7 +27,7 @@ for key, tab in tabs.items(): nteams += n tab['name'] = "{} (n={})".format(i18ned_statuses[key], n) -title = _("Teams (N={0})", nteams) +title = _("Teams") suppress_sidebar = True suppress_welcome = 'suppress-welcome' in request.cookie [---] @@ -61,7 +61,7 @@ suppress_welcome = 'suppress-welcome' in request.cookie

{{ _("Welcome to Gratipay!") }}

{{ _( "We have {nteams} Teams receiving and sharing money each week." - , nteams=napproved + , nteams=tabs['approved']['n'] ) }}

{{ _( "Continue to explore our Teams, or {a}read more about us{_a}." , a=''|safe