Niharika29 has uploaded a new change for review. https://gerrit.wikimedia.org/r/186161
Change subject: Pull out the macros from the template files into helper.html ...................................................................... Pull out the macros from the template files into helper.html This makes the template files code more comprehensible. As it is in Wikimania app. Change-Id: I004afebe0b34d02dc1d5e5ed61696f6b2d8ed572 --- M data/templates/admin/users.html A data/templates/inc/helpers.html M data/templates/proposals/edit.html M data/templates/proposals/queue.html M data/templates/proposals/search.html M data/templates/proposals/view_reviews.html M data/templates/reports/report.html 7 files changed, 192 insertions(+), 180 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/iegreview refs/changes/61/186161/1 diff --git a/data/templates/admin/users.html b/data/templates/admin/users.html index 05c818e..daa6d28 100644 --- a/data/templates/admin/users.html +++ b/data/templates/admin/users.html @@ -2,24 +2,12 @@ {% set route = app.router.getCurrentRoute.getName %} {% set ctx = _context %} -{% macro showBool( val ) %} -{{ val ? 'admin-users-yes'|message : 'admin-users-no'|message }} -{% endmacro %} - -{% macro sortHeader( label, column, ctx, class ) %} -{% set sorted = ctx.s == column %} -{% if sorted %} - {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} - {% set nextO = o == 'asc' ? 'desc' : 'asc' %} -{% else %} - {% set nextO = 'asc' %} -{% endif %} -<th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class|default( '' ) }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> -{% endmacro %} - {% block subtitle %}{{ 'nav-users'|message }}{% endblock %} {% block content %} {% spaceless %} + +{% import "inc/helpers.html" as helpers %} + <ol class="breadcrumb"> <li>{{ 'nav-admin'|message }}</li> <li>{{ 'nav-users'|message }}</li> @@ -55,25 +43,25 @@ <table class="table table-striped table-hover table-condensed table-responsive"> <tr> - {{ _self.sortHeader( 'admin-users-id', 'id', ctx, 'text-right' ) }} - {{ _self.sortHeader( 'admin-users-username', 'username', ctx ) }} - {{ _self.sortHeader( 'admin-users-email', 'email', ctx ) }} - {{ _self.sortHeader( 'admin-users-admin', 'isadmin', ctx ) }} - {{ _self.sortHeader( 'admin-users-reviewer', 'reviewer', ctx ) }} - {{ _self.sortHeader( 'admin-users-viewreports', 'viewreports', ctx ) }} - {{ _self.sortHeader( 'admin-users-valid', 'isvalid', ctx ) }} - {{ _self.sortHeader( 'admin-users-blocked', 'blocked', ctx ) }} + {{ helpers.sortHeader( 'admin-users-id', 'id', ctx, 'text-right' ) }} + {{ helpers.sortHeader( 'admin-users-username', 'username', ctx ) }} + {{ helpers.sortHeader( 'admin-users-email', 'email', ctx ) }} + {{ helpers.sortHeader( 'admin-users-admin', 'isadmin', ctx ) }} + {{ helpers.sortHeader( 'admin-users-reviewer', 'reviewer', ctx ) }} + {{ helpers.sortHeader( 'admin-users-viewreports', 'viewreports', ctx ) }} + {{ helpers.sortHeader( 'admin-users-valid', 'isvalid', ctx ) }} + {{ helpers.sortHeader( 'admin-users-blocked', 'blocked', ctx ) }} </tr> {% for row in records %} <tr class="{{ cycle( [ 'oddrow', 'evenrow' ], loop.index ) }}"> <td class="text-right">{{ row.id }}</td> <td><a href="{{ urlFor( 'admin_user', { 'id':row.id} ) }}">{{ row.username }}</a></td> <td><a href="mailto:{{ row.email|url_encode }}">{{ row.email }}</a></td> - <td>{{ _self.showBool( row.isadmin ) }}</td> - <td>{{ _self.showBool( row.reviewer ) }}</td> - <td>{{ _self.showBool( row.viewreports ) }}</td> - <td>{{ _self.showBool( row.isvalid ) }}</td> - <td>{{ _self.showBool( row.blocked ) }}</td> + <td>{{ helpers.showBool( row.isadmin ) }}</td> + <td>{{ helpers.showBool( row.reviewer ) }}</td> + <td>{{ helpers.showBool( row.viewreports ) }}</td> + <td>{{ helpers.showBool( row.isvalid ) }}</td> + <td>{{ helpers.showBool( row.blocked ) }}</td> </tr> {% else %} <tr><td colspan="8">{{ 'no-results'|message }}</td></tr> diff --git a/data/templates/inc/helpers.html b/data/templates/inc/helpers.html new file mode 100644 index 0000000..ee50fe9 --- /dev/null +++ b/data/templates/inc/helpers.html @@ -0,0 +1,156 @@ +{% macro sortHeader2( label, column, ctx, format ) %} +{% set sorted = ctx.s == column %} +{% if sorted %} + {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} + {% set nextO = o == 'asc' ? 'desc' : 'asc' %} +{% else %} + {% set nextO = 'asc' %} +{% endif %} +{% if format == 'number' or format == 'usd' %} + {% set class = 'text-right' %} +{% elseif format == 'message' %} + {% set class = 'text-center' %} +{% else %} + {% set class = '' %} +{% endif %} +<th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> +{% endmacro %} + +{% macro showBool( val ) %} +{{ val ? 'admin-users-yes'|message : 'admin-users-no'|message }} +{% endmacro %} + +{% macro sortHeader( label, column, ctx, class ) %} +{% set sorted = ctx.s == column %} +{% if sorted %} + {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} + {% set nextO = o == 'asc' ? 'desc' : 'asc' %} +{% else %} + {% set nextO = 'asc' %} +{% endif %} +<th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class|default( '' ) }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> +{% endmacro %} + +{% macro sortHeader4( label, column, ctx, class ) %} +{% set sorted = ctx.s == column %} +{% if sorted %} + {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} + {% set nextO = o == 'asc' ? 'desc' : 'asc' %} +{% else %} + {% set nextO = 'asc' %} +{% endif %} +{% endmacro %} + +{% macro format( row, spec ) %} +{% set val = row[spec.column] %} +{% if spec.format == 'number' %} + <td class="text-right">{{ row[spec.column]|number_format( spec.precision ) }}</td> +{% elseif spec.format == 'usd' %} + <td class="text-right nowrap"> + {{ row[spec.column]|number_format( spec.precision ) }} + {{ 'currency-usd'|message }} + </td> +{% elseif spec.format == 'proposal' %} + <td><a href="{{ urlFor( 'proposals_view', { 'id':row[spec.column] } ) }}">{{ row[spec.text] }}</a></td> +{% elseif spec.format == 'message' %} + {% set vals = [] %} + {% for key in spec.columns %} + {% set vals = vals|merge( [ row[key] ] ) %} + {% endfor %} + <td class="text-center">{{ spec.message|message( vals ) }}</td> +{% else %} + <td>{{ row[spec.column] }}</td> +{% endif %} +{% endmacro %} + +{% macro sortHeader3( column, ctx, class ) %} +{% set sorted = ctx.s == column %} +{% set label = "proposals-list-#{column}" %} +{% if sorted %} + {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} + {% set nextO = o == 'asc' ? 'desc' : 'asc' %} +{% else %} + {% set nextO = 'asc' %} +{% endif %} +<th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class|default( '' ) }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> +{% endmacro %} + + +{% macro criteria( reviews, crit, ctx ) %} +{% import _self as helpers %} +{% set note = crit ~ '_note' %} +<section class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title">{{ ( 'review-' ~ crit )|message }}</h3> + </div> + <table class="table table-bordered table-hover table-condensed"> + <thead> + <tr> + <th>{{ 'summary-list-mean'|message }}</th> + <th>{{ 'summary-list-median'|message }}</th> + <th>{{ 'summary-list-range'|message }}</th> + <th>{{ 'summary-list-stddev'|message }}</th> + </tr> + </thead> + <tbody> + {{ helpers.stats( reviews, crit ) }} + </tbody> + </table> + <section class="panel panel-default muted"> + <div class="panel-heading"> + <a class="accordion-toggle collapsed" data-toggle="collapse" href="#{{ crit }}-notes"> + <span class="text-muted">{{ 'reviews-notes'|message }}</span> + </a> + </div> + <div id="{{ crit }}-notes" class="panel-body panel-collapse collapse"> + <ul class="list-group"> + {% for review in reviews %} + {% if review[note] %} + <li class="list-group-item clearfix"> + {{ review[note] }} + {% if ctx.isadmin|default( false ) %} + <cite class="pull-right text-muted">— {{ review.reviewer_name }}</cite> + {% endif %} + </li> + {% endif %} + {% endfor %} + </ul> + </div> + </section> +</section> +{% endmacro %} + +{% macro stats( reviews, name ) %} +{% import _self as helpers %} +{% set scores = [] %} +{% set sum = 0 %} +{% set squares = 0 %} +{% for review in reviews %} +{% set val = review[name] %} + {% set scores = scores|merge( [ val ] ) %} + {% set sum = sum + val %} + {% set squares = squares + ( val * val ) %} +{% endfor %} +<tr> + <td class="text-right">{{ ( sum / scores|length )|number_format( 2 ) }}</td> + <td class="text-right">{{ helpers.median( scores ) }}</td> + <td class="text-right">{{ max( scores ) - min( scores ) }}</td> + <td class="text-right">{{ ( ( squares - ( ( sum * sum ) / scores|length ) ) ** ( 1 / 2 ) )|number_format( 2 ) }}</td> +</tr> +{% endmacro %} + +{% macro median( list, precision = 2 ) %} +{% set midlow = ( list|length / 2 )|round( 1, 'floor') %} +{% set midhi = ( list|length / 2 )|round( 1, 'ceil') %} +{{ ( ( list[midlow] + list[midhi] ) / 2 )|number_format( precision ) }} +{% endmacro %} + +{% macro count( reviews, name, value ) %} +{% set count = 0 %} +{% for review in reviews %} + {% if review[name] == value %} + {% set count = count + 1 %} + {% endif %} +{% endfor %} +{{ count }} +{% endmacro %} diff --git a/data/templates/proposals/edit.html b/data/templates/proposals/edit.html index 279cf3d..0a81b20 100644 --- a/data/templates/proposals/edit.html +++ b/data/templates/proposals/edit.html @@ -5,6 +5,7 @@ {% block subtitle %}{{ 'nav-proposals-edit'|message }}{% endblock %} {% block content %} {% spaceless %} + <ol class="breadcrumb"> <li><a href="{{ urlFor( 'proposals_home' ) }}">{{ 'nav-proposals'|message }}</a></li> {% if id != 'new' %} diff --git a/data/templates/proposals/queue.html b/data/templates/proposals/queue.html index 86780d5..497f116 100644 --- a/data/templates/proposals/queue.html +++ b/data/templates/proposals/queue.html @@ -2,21 +2,12 @@ {% set route = 'proposals_queue' %} {% set ctx = _context %} -{% macro sortHeader( column, ctx, class ) %} -{% set sorted = ctx.s == column %} -{% set label = "proposals-list-#{column}" %} -{% if sorted %} - {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} - {% set nextO = o == 'asc' ? 'desc' : 'asc' %} -{% else %} - {% set nextO = 'asc' %} -{% endif %} -<th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class|default( '' ) }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> -{% endmacro %} - {% block subtitle %}{{ 'nav-proposals-queue'|message }}{% endblock %} {% block content %} {% spaceless %} + +{% import "inc/helpers.html" as helpers %} + <ol class="breadcrumb"> <li><a href="{{ urlFor( 'proposals_home' ) }}">{{ 'nav-proposals'|message }}</a></li> <li>{{ 'nav-proposals-queue'|message }}</li> @@ -59,10 +50,10 @@ <p></p> <table class="table table-striped table-hover table-condensed table-responsive"> <tr> - {{ _self.sortHeader( 'title', ctx ) }} - {{ _self.sortHeader( 'theme', ctx ) }} - {{ _self.sortHeader( 'amount', ctx, 'text-right' ) }} - {{ _self.sortHeader( 'reviews', ctx, 'text-right' ) }} + {{ helpers.sortHeader3( 'title', ctx ) }} + {{ helpers.sortHeader3( 'theme', ctx ) }} + {{ helpers.sortHeader3( 'amount', ctx, 'text-right' ) }} + {{ helpers.sortHeader3( 'reviews', ctx, 'text-right' ) }} </tr> {% for row in records %} <tr> diff --git a/data/templates/proposals/search.html b/data/templates/proposals/search.html index f11dbf0..73af0e1 100644 --- a/data/templates/proposals/search.html +++ b/data/templates/proposals/search.html @@ -2,14 +2,8 @@ {% set route = app.router.getCurrentRoute.getName %} {% set ctx = _context %} -{% macro sortHeader( label, column, ctx, class ) %} -{% set sorted = ctx.s == column %} -{% if sorted %} - {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} - {% set nextO = o == 'asc' ? 'desc' : 'asc' %} -{% else %} - {% set nextO = 'asc' %} -{% endif %} +{% import "inc/helpers.html" as helpers %} + <th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class|default( '' ) }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> {% endmacro %} @@ -49,12 +43,12 @@ {% if found is not null %} <table class="table table-striped table-hover table-condensed table-responsive"> <tr> - {{ _self.sortHeader( 'proposals-list-id', 'id', ctx, 'text-right' ) }} - {{ _self.sortHeader( 'proposals-list-title', 'title', ctx ) }} - {{ _self.sortHeader( 'proposals-list-theme', 'theme', ctx ) }} - {{ _self.sortHeader( 'proposals-list-amount', 'amount', ctx, 'text-right' ) }} - {{ _self.sortHeader( 'proposals-list-reviews', 'reviews', ctx, 'text-right' ) }} - {{ _self.sortHeader( 'proposals-list-myreviews', 'myreviews', ctx, 'text-center' ) }} + {{ helpers.sortHeader4( 'proposals-list-id', 'id', ctx, 'text-right' ) }} + {{ helpers.sortHeader4( 'proposals-list-title', 'title', ctx ) }} + {{ helpers.sortHeader4( 'proposals-list-theme', 'theme', ctx ) }} + {{ helpers.sortHeader4( 'proposals-list-amount', 'amount', ctx, 'text-right' ) }} + {{ helpers.sortHeader4( 'proposals-list-reviews', 'reviews', ctx, 'text-right' ) }} + {{ helpers.sortHeader4( 'proposals-list-myreviews', 'myreviews', ctx, 'text-center' ) }} </tr> {% for row in records %} <tr> diff --git a/data/templates/proposals/view_reviews.html b/data/templates/proposals/view_reviews.html index ebbcccd..fcf3ab0 100644 --- a/data/templates/proposals/view_reviews.html +++ b/data/templates/proposals/view_reviews.html @@ -1,83 +1,4 @@ -{% import _self as helpers %} - -{% macro criteria( reviews, crit, ctx ) %} -{% import _self as helpers %} -{% set note = crit ~ '_note' %} -<section class="panel panel-default"> - <div class="panel-heading"> - <h3 class="panel-title">{{ ( 'review-' ~ crit )|message }}</h3> - </div> - <table class="table table-bordered table-hover table-condensed"> - <thead> - <tr> - <th>{{ 'summary-list-mean'|message }}</th> - <th>{{ 'summary-list-median'|message }}</th> - <th>{{ 'summary-list-range'|message }}</th> - <th>{{ 'summary-list-stddev'|message }}</th> - </tr> - </thead> - <tbody> - {{ helpers.stats( reviews, crit ) }} - </tbody> - </table> - <section class="panel panel-default muted"> - <div class="panel-heading"> - <a class="accordion-toggle collapsed" data-toggle="collapse" href="#{{ crit }}-notes"> - <span class="text-muted">{{ 'reviews-notes'|message }}</span> - </a> - </div> - <div id="{{ crit }}-notes" class="panel-body panel-collapse collapse"> - <ul class="list-group"> - {% for review in reviews %} - {% if review[note] %} - <li class="list-group-item clearfix"> - {{ review[note] }} - {% if ctx.isadmin|default( false ) %} - <cite class="pull-right text-muted">— {{ review.reviewer_name }}</cite> - {% endif %} - </li> - {% endif %} - {% endfor %} - </ul> - </div> - </section> -</section> -{% endmacro %} - -{% macro stats( reviews, name ) %} -{% import _self as helpers %} -{% set scores = [] %} -{% set sum = 0 %} -{% set squares = 0 %} -{% for review in reviews %} -{% set val = review[name] %} - {% set scores = scores|merge( [ val ] ) %} - {% set sum = sum + val %} - {% set squares = squares + ( val * val ) %} -{% endfor %} -<tr> - <td class="text-right">{{ ( sum / scores|length )|number_format( 2 ) }}</td> - <td class="text-right">{{ helpers.median( scores ) }}</td> - <td class="text-right">{{ max( scores ) - min( scores ) }}</td> - <td class="text-right">{{ ( ( squares - ( ( sum * sum ) / scores|length ) ) ** ( 1 / 2 ) )|number_format( 2 ) }}</td> -</tr> -{% endmacro %} - -{% macro median( list, precision = 2 ) %} -{% set midlow = ( list|length / 2 )|round( 1, 'floor') %} -{% set midhi = ( list|length / 2 )|round( 1, 'ceil') %} -{{ ( ( list[midlow] + list[midhi] ) / 2 )|number_format( precision ) }} -{% endmacro %} - -{% macro count( reviews, name, value ) %} -{% set count = 0 %} -{% for review in reviews %} - {% if review[name] == value %} - {% set count = count + 1 %} - {% endif %} -{% endfor %} -{{ count }} -{% endmacro %} +{% import "inc/helpers.html" as helpers %} {% spaceless %} <article id="summary" class="panel-group"> diff --git a/data/templates/reports/report.html b/data/templates/reports/report.html index bce35b2..e81b5bb 100644 --- a/data/templates/reports/report.html +++ b/data/templates/reports/report.html @@ -14,46 +14,7 @@ {% set suffix = route|split( '_' )|last %} {% set ctx = _context %} -{% macro sortHeader( label, column, ctx, format ) %} -{% set sorted = ctx.s == column %} -{% if sorted %} - {% set o = ctx.o == 'desc' ? 'desc' : 'asc' %} - {% set nextO = o == 'asc' ? 'desc' : 'asc' %} -{% else %} - {% set nextO = 'asc' %} -{% endif %} -{% if format == 'number' or format == 'usd' %} - {% set class = 'text-right' %} -{% elseif format == 'message' %} - {% set class = 'text-center' %} -{% else %} - {% set class = '' %} -{% endif %} -<th><a class="sortable {{ sorted ? "sorted-#{o}" : 'unsorted' }} {{ class }}" href="{{ urlFor( ctx.route ) }}?{{ qsMerge( { 's':column, 'o':nextO } ) }}">{{ label|message }}</a></th> -{% endmacro %} - -{% macro format( row, spec ) %} -{% set val = row[spec.column] %} -{% if spec.format == 'number' %} - <td class="text-right">{{ row[spec.column]|number_format( spec.precision ) }}</td> -{% elseif spec.format == 'usd' %} - <td class="text-right nowrap"> - {{ row[spec.column]|number_format( spec.precision ) }} - {{ 'currency-usd'|message }} - </td> -{% elseif spec.format == 'proposal' %} - <td><a href="{{ urlFor( 'proposals_view', { 'id':row[spec.column] } ) }}">{{ row[spec.text] }}</a></td> -{% elseif spec.format == 'message' %} - {% set vals = [] %} - {% for key in spec.columns %} - {% set vals = vals|merge( [ row[key] ] ) %} - {% endfor %} - <td class="text-center">{{ spec.message|message( vals ) }}</td> -{% else %} - <td>{{ row[spec.column] }}</td> -{% endif %} -{% endmacro %} - +{% import "inc/helpers.html" as helpers %} {% block subtitle %}{{ ( 'nav-reports-' ~ suffix )|message }}{% endblock %} @@ -69,7 +30,7 @@ <tr> {% for msg,col in columns %} {% if col.sortable %} - {{ _self.sortHeader( msg, col.sortcolumn, ctx, col.format ) }} + {{ helpers.sortHeader2( msg, col.sortcolumn, ctx, col.format ) }} {% else %} <th>{{ msg|message }}</th> {% endif %} @@ -80,7 +41,7 @@ {% for row in report.rows %} <tr> {% for col in columns %} - {{ _self.format( row, col ) }} + {{ helpers.format( row, col ) }} {% endfor %} </tr> {% else %} -- To view, visit https://gerrit.wikimedia.org/r/186161 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I004afebe0b34d02dc1d5e5ed61696f6b2d8ed572 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/iegreview Gerrit-Branch: master Gerrit-Owner: Niharika29 <niharikakohl...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits