Making WordPress.org

Changeset 3814


Ignore:
Timestamp:
08/16/2016 04:28:32 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Convert [application-status] to a React-based table.

This adds the ability to search and sort the data, and lays the groundwork for adding meetups to the table.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt
Files:
24 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/applications/tracker.php

    r2910 r3814  
    22
    33namespace WordPress_Community\Applications\Tracker;
     4use \WordCamp_Loader;
    45defined( 'WPINC' ) or die();
    56
    67const SHORTCODE_SLUG = 'application-tracker';
    78
    8 add_shortcode( SHORTCODE_SLUG, __NAMESPACE__ . '\render_status_shortcode' );
    9 add_action( 'wp_print_styles', __NAMESPACE__ . '\print_shortcode_styles'  );
     9add_shortcode( SHORTCODE_SLUG,    __NAMESPACE__ . '\render_status_shortcode' );
     10add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts'         );
    1011
    1112/**
     
    1314 */
    1415function render_status_shortcode() {
    15         $statuses   = \WordCamp_Loader::get_post_statuses();
    16         $milestones = \WordCamp_Loader::map_statuses_to_milestones();
    17         $posts      = get_active_wordcamps( $statuses );
    18 
    19         ob_start();
    20 
    21         require_once( dirname( __DIR__ ) . '/wcpt-wordcamp/wordcamp-admin.php'                             );
    22         require(      dirname( __DIR__ ) . '/views/applications/tracker/shortcode-application-tracker.php' );
    23 
    24         return ob_get_clean();
     16        return '<div id="wpc-application-tracker">Loading Application Tracker...</div>';
    2517}
    2618
     
    2820 * Get camps that are active enough to be shown on the tracker
    2921 *
    30  * @param array $statuses
    31  *
    3222 * @return array
    3323 */
    34 function get_active_wordcamps( $statuses ) {
     24function get_active_wordcamps() {
     25        $wordcamps          = array();
     26        $statuses           = WordCamp_Loader::get_post_statuses();
     27        $milestones         = WordCamp_Loader::map_statuses_to_milestones();
    3528        $inactive_timestamp = strtotime( '60 days ago' );
    3629
     
    3932        $shown_statuses = array_keys( $shown_statuses );
    4033
    41         $wordcamps = get_posts( array(
     34        $raw_posts = get_posts( array(
    4235                'post_type'      => WCPT_POST_TYPE_ID,
    4336                'post_status'    => $shown_statuses,
     
    4740        ) );
    4841
    49         foreach ( $wordcamps as $key => $wordcamp ) {
    50                 $wordcamp->last_update_timestamp = get_last_update_timestamp( $wordcamp->ID );
     42        foreach ( $raw_posts as $key => $post ) {
     43                $last_update_timestamp = get_last_update_timestamp( $post->ID );
    5144
    52                 if ( $wordcamp->last_update_timestamp <= $inactive_timestamp ) {
    53                         unset( $wordcamps[ $key ] );
     45                if ( $last_update_timestamp <= $inactive_timestamp ) {
     46                        continue;
    5447                }
    5548
    56                 $wordcamp->url = filter_var( get_post_meta( $wordcamp->ID, 'URL', true ), FILTER_VALIDATE_URL );
     49                $wordcamps[] = array(
     50                        'city'       => $post->post_title,
     51                        'cityUrl'    => filter_var( get_post_meta( $post->ID, 'URL', true ), FILTER_VALIDATE_URL ),
     52                        'applicant'  => get_post_meta( $post->ID, 'Organizer Name', true ),
     53                        'milestone'  => $milestones[ $post->post_status ],
     54                        'status'     => $statuses[ $post->post_status ],
     55                        'lastUpdate' => human_time_diff( time(), $last_update_timestamp ) . ' ago',
     56                );
    5757        }
    5858
     
    8080
    8181/**
    82  * Print CSS styles for the [application-tracker] shortcode.
     82 * Enqueue scripts and styles
    8383 */
    84 function print_shortcode_styles() {
     84function enqueue_scripts() {
    8585        global $post;
    8686
    87         if ( empty( $post->post_content ) || ! has_shortcode( $post->post_content, SHORTCODE_SLUG ) ) {
     87        wp_register_script(
     88                'wpc-application-tracker',
     89                plugins_url( 'javascript/tracker/build/tracker.min.js', dirname( __FILE__ ) ),
     90                array(),
     91                1,
     92                true
     93        );
     94
     95        wp_register_style(
     96                'wpc-application-tracker',
     97                plugins_url( 'javascript/tracker/build/tracker.min.css', dirname( __FILE__ ) ),
     98                array( 'dashicons', 'list-tables' ),
     99                1
     100        );
     101
     102        if ( ! is_a( $post, 'WP_POST' ) || ! has_shortcode( $post->post_content, SHORTCODE_SLUG ) ) {
    88103                return;
    89104        }
    90        
    91         ?>
    92105
    93         <style type="text/css">
    94                 .application-tracker.striped > tbody > :nth-child( odd ) {
    95                         background-color: #f9f9f9;
    96                 }
     106        wp_enqueue_script( 'wpc-application-tracker' );
    97107
    98                 /* Show extra data on large screens */
    99                 .application-tracker .milestone,
    100                 .application-tracker .applicant {
    101                         display: none;
    102                 }
     108        wp_localize_script(
     109                'wpc-application-tracker',
     110                'wpcApplicationTracker',
     111                array(
     112                        'applications'     => get_active_wordcamps(),
     113                        'displayColumns'   => get_display_columns(),
     114                        'initialSortField' => 'city',
     115                )
     116        );
    103117
    104                 @media screen and ( min-width: 750px ) {
    105                         .application-tracker .applicant {
    106                                 display: table-cell;
    107                         }
    108                 }
     118        wp_enqueue_style( 'wpc-application-tracker' );
     119}
    109120
    110                 @media screen and ( min-width: 850px ) {
    111                         .application-tracker .milestone {
    112                                 display: table-cell;
    113                         }
    114                 }
    115         </style>
    116 
    117         <?php
     121/**
     122 * Get the columns headers
     123 *
     124 * @return array
     125 */
     126function get_display_columns() {
     127        return array(
     128                'city'       => 'City',
     129                'applicant'  => 'Applicant',
     130                'milestone'  => 'Milestone',
     131                'status'     => 'Status',
     132                'lastUpdate' => 'Updated',
     133        );
    118134}
Note: See TracChangeset for help on using the changeset viewer.