Making WordPress.org

Changeset 8497


Ignore:
Timestamp:
03/24/2019 05:14:26 PM (6 years ago)
Author:
ocean90
Message:

Translate: Extend contributors table for locale projects with a toggle to view per-project stats.

Fixes #3613.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/locale-project.php

    r7480 r8497  
    207207        <table class="locale-project-contributors-table">
    208208            <thead>
    209                 <th class="contributor-name">Contributor</th>
    210                 <th class="contributor-stats">Translations*</th>
     209                <tr>
     210                    <th class="contributor-name">Contributor</th>
     211                    <th class="contributor-stats">Translations</th>
     212                </tr>
    211213            </thead>
    212214            <tbody>
    213215            <?php
    214216            foreach ( $locale_contributors['contributors'] as $contributor ) {
     217                $detailed = '';
     218
     219                if ( 'wp-plugins' === $project->path ) {
     220                    // Ensure consistent order of development and stable projects.
     221                    usort( $contributor->detailed, function( $a, $b ) {
     222                        return strnatcasecmp( $a->project->name, $b->project->name );
     223                    } );
     224                }
     225
     226                foreach ( $contributor->detailed as $detail_project_id => $detail_data ) {
     227                    $detailed .= '<strong class="detailed__project-name">' . $detail_data->project->name . ':</strong>';
     228
     229                    if ( $detail_data->total_count > 0 ) {
     230                        $total_count = gp_link_get(
     231                            gp_url_project(
     232                                $detail_data->project->path,
     233                                gp_url_join( $locale->slug, $set_slug ),
     234                                [
     235                                    'filters[translated]' => 'yes',
     236                                    'filters[status]'     => 'current_or_waiting_or_fuzzy_or_untranslated',
     237                                    'filters[user_login]' => $contributor->login,
     238                                ]
     239                            ),
     240                            number_format_i18n( $detail_data->total_count )
     241                        );
     242                    } else {
     243                        $total_count = number_format_i18n( $detail_data->total_count );
     244                    }
     245
     246                    if ( $detail_data->current_count > 0 ) {
     247                        $current_count = gp_link_get(
     248                            gp_url_project(
     249                                $detail_data->project->path,
     250                                gp_url_join( $locale->slug, $set_slug ),
     251                                [
     252                                    'filters[translated]' => 'yes',
     253                                    'filters[status]'     => 'current',
     254                                    'filters[user_login]' => $contributor->login,
     255                                ]
     256                            ),
     257                            number_format_i18n( $detail_data->current_count )
     258                        );
     259                    } else {
     260                        $current_count = number_format_i18n( $detail_data->current_count );
     261                    }
     262
     263                    if ( $detail_data->waiting_count > 0 ) {
     264                        $waiting_count = gp_link_get(
     265                            gp_url_project(
     266                                $detail_data->project->path,
     267                                gp_url_join( $locale->slug, $set_slug ),
     268                                [
     269                                    'filters[translated]' => 'yes',
     270                                    'filters[status]'     => 'waiting',
     271                                    'filters[user_login]' => $contributor->login,
     272                                ]
     273                            ),
     274                            number_format_i18n( $detail_data->waiting_count )
     275                        );
     276                    } else {
     277                        $waiting_count = number_format_i18n( $detail_data->waiting_count );
     278                    }
     279
     280                    if ( $detail_data->fuzzy_count > 0 ) {
     281                        $fuzzy_count = gp_link_get(
     282                            gp_url_project(
     283                                $detail_data->project->path,
     284                                gp_url_join( $locale->slug, $set_slug ),
     285                                [
     286                                    'filters[translated]' => 'yes',
     287                                    'filters[status]'     => 'fuzzy',
     288                                    'filters[user_login]' => $contributor->login,
     289                                ]
     290                            ),
     291                            number_format_i18n( $detail_data->fuzzy_count )
     292                        );
     293                    } else {
     294                        $fuzzy_count = number_format_i18n( $detail_data->fuzzy_count );
     295                    }
     296
     297                    $detailed .= sprintf(
     298                        '
     299                            <div class="total">
     300                                <p>%s</p>
     301                            </div>
     302                            <div class="current">
     303                                <p>%s</p>
     304                            </div>
     305                            <div class="waiting">
     306                                <p>%s</p>
     307                            </div>
     308                            <div class="fuzzy">
     309                                <p>%s</p>
     310                            </div>
     311                        ',
     312                        $total_count,
     313                        $current_count,
     314                        $waiting_count,
     315                        $fuzzy_count
     316                    );
     317                }
     318
    215319                printf(
    216320                    '<tr>
     
    218322                            %s
    219323                            <a href="https://profiles.wordpress.org/%s/">%s %s</a>
    220                             <span>Last Activity: %s ago</span>
     324                            <span>Last translation submitted: %s ago</span>
    221325                        </td>
    222326                        <td class="contributor-stats">
     
    237341                                <p>%s</p>
    238342                            </div>
    239                         <td>
     343                            <div class="detailed">
     344                                <details>
     345                                    <summary>Per project</summary>
     346                                    %s
     347                                </details>
     348                            </div>
     349                        </td>
    240350                    </tr>',
    241351                    $contributor->is_editor ? '<span class="translation-editor">Editor</span>' : '',
    242352                    $contributor->nicename,
    243353                    get_avatar( $contributor->email, 40 ),
    244                     $contributor->display_name ? $contributor->display_name : $contributor->nicename,
     354                    $contributor->display_name ?: $contributor->nicename,
    245355                    human_time_diff( strtotime( $contributor->last_update ) ),
    246356                    number_format_i18n( $contributor->total_count ),
    247357                    number_format_i18n( $contributor->current_count ),
    248358                    number_format_i18n( $contributor->waiting_count ),
    249                     number_format_i18n( $contributor->fuzzy_count )
     359                    number_format_i18n( $contributor->fuzzy_count ),
     360                    $detailed
    250361                );
    251362            }
     
    253364            </tbody>
    254365        </table>
    255         <p class="stats-hint">* Data for the last 365 days.</p>
    256366        <?php else : ?>
    257367            <p>None, be the first?</p>
     
    272382                        $editor->nicename,
    273383                        get_avatar( $editor->email, 40 ),
    274                         $editor->display_name ? $editor->display_name : $editor->nicename
     384                        $editor->display_name ?: $editor->nicename
    275385                    );
    276386                }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/style.css

    r8496 r8497  
    17731773.locale-project-contributors-table td.contributor-stats div.fuzzy span {
    17741774    color: #f78b53;
     1775}
     1776
     1777.locale-project-contributors-table td.contributor-stats .detailed {
     1778    width: 100%;
     1779    clear: left;
     1780    float: none;
     1781}
     1782
     1783.detailed summary {
     1784    text-align: right;
     1785    font-size: 10px;
     1786    outline: none;
     1787    cursor: pointer;
     1788}
     1789
     1790.detailed__project-name {
     1791    display: block;
     1792    clear: left;
     1793    text-align: left;
     1794    font-size: 10px;
     1795    padding-top: 5px;
    17751796}
    17761797
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php

    r8496 r8497  
    503503        }
    504504
     505        $projects = [];
     506
    505507        // Get the names of the contributors.
    506508        foreach ( $contributors as $contributor ) {
     
    516518                $locale_contributors['contributors'][ $contributor->user_id ]->waiting_count += $contributor->waiting_count;
    517519                $locale_contributors['contributors'][ $contributor->user_id ]->fuzzy_count   += $contributor->fuzzy_count;
     520
     521                if ( ! isset( $projects[ $contributor->project_id ] ) ) {
     522                    $projects[ $contributor->project_id ] = GP::$project->get( $contributor->project_id );
     523                }
     524
     525                $locale_contributors['contributors'][ $contributor->user_id ]->detailed[ $contributor->project_id ] = (object) [
     526                    'total_count'   => $contributor->total_count,
     527                    'current_count' => $contributor->current_count,
     528                    'waiting_count' => $contributor->waiting_count,
     529                    'fuzzy_count'   => $contributor->fuzzy_count,
     530                    'project'       => $projects[ $contributor->project_id ],
     531                ];
     532
    518533                continue;
    519534            }
     
    524539            }
    525540
     541            if ( ! isset( $projects[ $contributor->project_id ] ) ) {
     542                $projects[ $contributor->project_id ] = GP::$project->get( $contributor->project_id );
     543            }
     544
    526545            $locale_contributors['contributors'][ $contributor->user_id ] = (object) array(
     546                'login'         => $user->user_login,
    527547                'nicename'      => $user->user_nicename,
    528548                'display_name'  => $this->_encode( $user->display_name ),
     
    533553                'waiting_count' => $contributor->waiting_count,
    534554                'fuzzy_count'   => $contributor->fuzzy_count,
     555                'detailed'      => [
     556                    $contributor->project_id => (object) [
     557                        'total_count'   => $contributor->total_count,
     558                        'current_count' => $contributor->current_count,
     559                        'waiting_count' => $contributor->waiting_count,
     560                        'fuzzy_count'   => $contributor->fuzzy_count,
     561                        'project'       => $projects[ $contributor->project_id ],
     562                    ],
     563                ],
    535564                'is_editor'     => in_array( $user->ID, $editor_ids ),
    536565            );
     
    557586            SELECT
    558587                `t`.`user_id` as `user_id`,
     588                `o`.`project_id` as `project_id`,
    559589                MAX( `t`.`date_added` ) AS `last_update`,
    560590                COUNT( * ) as `total_count`,
     
    569599                AND `t`.`user_id` IS NOT NULL AND `t`.`user_id` != 0
    570600                AND `t`.`status` IN( 'current', 'waiting', 'fuzzy' )
    571                 AND `t`.`date_modified` > %s
    572601            GROUP BY `t`.`user_id`
    573         ", $translation_set->id, date( 'Y-m-d', time() - YEAR_IN_SECONDS ) ) );
     602        ", $translation_set->id ) );
    574603
    575604        return $contributors;
Note: See TracChangeset for help on using the changeset viewer.