WordPress.org

Making WordPress.org

Changeset 2072


Ignore:
Timestamp:
11/11/2015 02:00:12 AM (4 years ago)
Author:
dd32
Message:

Translate: Add a basic sorting dropdown to project views.
Patches welcome to integrate the UI into the listing UI better.

Fixes #1122

Location:
sites/trunk/translate.wordpress.org
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/routes/locale.php

    r1901 r2072  
    2626        $page = (int) gp_get( 'page', 1 );
    2727        $search = gp_get( 's', '' );
    28         $filter = gp_get( 'filter', 'default' );
     28        $filter = gp_get( 'filter', false );
    2929
    3030        $locale = GP_Locales::by_slug( $locale_slug );
     
    8888        $sub_projects = $paged_sub_projects['projects'];
    8989        $pages        = $paged_sub_projects['pages'];
     90        $filter       = $paged_sub_projects['filter'];
    9091        unset( $paged_sub_projects );
    9192
     
    386387            'set_slug' => '',
    387388            'locale'   => '',
    388             'filter'     => 'default',
     389            'filter'   => false,
    389390        );
    390391        $r = wp_parse_args( $args, $defaults );
     
    408409        if ( 'waiting' == $project->slug && GP::$user->current()->id && isset( GP::$plugins->wporg_rosetta_roles ) ) {
    409410
    410             if ( 'default' === $filter ) {
    411                 $filter = 'strings-waiting';
     411            if ( ! $filter ) {
     412                $filter = 'strings-waiting-and-fuzzy';
    412413            }
    413414
     
    452453
    453454        $filter_order_by = $filter_where = '';
    454         switch ( $filter ) {
     455        $sort_order = 'DESC';
     456        $filter_name = $filter;
     457        if ( $filter && '-asc' == substr( $filter, -4 ) ) {
     458            $sort_order = 'ASC';
     459            $filter_name = substr( $filter, 0, -4 );
     460        }
     461        switch ( $filter_name ) {
    455462            default:
    456             case 'default':
     463            case 'special':
    457464                // Float favorites to the start, but only if they have untranslated strings
    458465                $user_fav_projects = array_map( array( $gpdb, 'escape' ), $this->get_user_favorites( $project->slug ) );
     
    481488            case 'strings-remaining':
    482489                $filter_where = 'AND stats.untranslated > 0';
    483                 $filter_order_by = 'stats.untranslated DESC, tp.name ASC';
     490                $filter_order_by = "stats.untranslated $sort_order, tp.name ASC";
    484491                break;
    485492
    486             case 'strings-waiting':
     493            case 'strings-waiting-and-fuzzy':
    487494                $filter_where = 'AND (stats.waiting > 0 OR stats.fuzzy > 0 )';
    488495                $filter_order_by = "tp.path LIKE 'wp/%%' AND (stats.fuzzy + stats.waiting) > 0 DESC, (stats.fuzzy + stats.waiting) DESC, tp.name ASC";
    489496                break;
    490497
    491             case 'strings-fuzzy-and-warnings':
    492                 $filter_where = 'AND ( stats.fuzzy > 0 OR stats.warnings > 0 )';
    493                 $filter_order_by = '(stats.fuzzy+stats.warnings) DESC, tp.name ASC';
    494                 break;
    495 
    496498            case 'percent-completed':
    497499                $filter_where = 'AND stats.untranslated > 0';
    498                 $filter_order_by = ' ( stats.current / stats.all ) DESC, tp.name ASC';
     500                $filter_order_by = "( stats.current / stats.all ) $sort_order, tp.name ASC";
    499501                break;
    500502        }
     
    534536            'pages' => compact( 'pages', 'page', 'per_page', 'results' ),
    535537            'projects' => $projects,
     538            'filter' => $filter,
    536539        );
    537540    }
  • sites/trunk/translate.wordpress.org/public_html/gp-templates/locale-projects.php

    r1888 r2072  
    7575    </div>
    7676</div>
     77<div class="sort-bar">
     78    <select id="sort-filter" disabled="disabled">
     79        <?php
     80            $sorts = array();
     81            if ( GP::$user->current()->id && in_array( $project->slug, array( 'waiting', 'wp-themes', 'wp-plugins' ) ) ) {
     82                $sorts['special'] = 'Untranslated Favorites, Remaining Strings (Most first)';
     83                $sorts['favorites'] = 'My Favorites';
     84            }
     85            $sorts['strings-remaining'] = 'Remaining Strings (Most first)';
     86            $sorts['strings-remaining-asc'] = 'Remaining Strings (Least first)';
     87            $sorts['strings-waiting-and-fuzzy'] = 'Waiting + Fuzzy (Most first)';
     88            $sorts['strings-waiting-and-fuzzy-asc'] = 'Waiting + Fuzzy (Least first)';
     89            $sorts['percent-completed'] = 'Percent Completed (Most first)';
     90            $sorts['percent-completed-asc'] = 'Percent Completed (Least first)';
     91
     92            foreach ( $sorts as $value => $text ) {
     93                printf( '<option value="%s" %s>%s</option>', esc_attr( $value ), ( $value == $filter ? 'selected="selected"' : '' ), esc_attr( $text ) );
     94            }
     95        ?>
     96    </select>
     97</div>
     98<script>
     99    jQuery('#sort-filter').change( function() {
     100        var current_url = document.location.href.replace(/[?&]filter=[^&$]*/, '' );
     101        document.location.replace(
     102            current_url +
     103            ( -1 == current_url.indexOf('?') ? '?filter=' : '&filter=' ) +
     104            this.options[ this.options.selectedIndex ].value
     105        );
     106    } ).prop('disabled', '');
     107</script>
    77108
    78109<div id="projects" class="projects">
  • sites/trunk/translate.wordpress.org/public_html/gp-templates/style.css

    r2070 r2072  
    10241024    content: "\f142";
    10251025}
     1026
     1027.sort-bar {
     1028    float: right;
     1029    margin: -30px 0 5px 5px;
     1030    background-color: #eee;
     1031    padding: 5px;
     1032    border: 1px solid #dfdfdf;
     1033    border-top: none;
     1034}
Note: See TracChangeset for help on using the changeset viewer.