From 94fe2efb1d37bccae3c637e04eeda46b921b8562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Amieiro?= <1667814+amieiro@users.noreply.github.com> Date: Tue, 9 Apr 2024 09:46:36 +0200 Subject: [PATCH 01/31] Temp commit --- includes/routes/event/translations.php | 153 +++++++++++++++++++++++++ templates/event.php | 2 +- templates/events-list.php | 2 +- wporg-gp-translation-events.php | 1 + 4 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 includes/routes/event/translations.php diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php new file mode 100644 index 00000000..724635ef --- /dev/null +++ b/includes/routes/event/translations.php @@ -0,0 +1,153 @@ +event_repository = Translation_Events::get_event_repository(); +// $this->attendee_repository = Translation_Events::get_attendee_repository(); + } + + public function handle( int $event_id, string $locale ): void { + global $wpdb, $gp_table_prefix; + + // Get the different projects for the event and locale + $project_ids = $wpdb->get_results( + $wpdb->prepare( + " + SELECT DISTINCT p.id + FROM {$gp_table_prefix}event_actions ea + JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id + JOIN {$gp_table_prefix}projects p ON o.project_id = p.id + WHERE ea.event_id = %d + AND ea.locale = %s + ", + $event_id, + $locale + ) + ); + + // Get the translations for the current project_id, event_id and locale + foreach ( $project_ids as $project_id ) { + $translations = $wpdb->get_results( + $wpdb->prepare( + " + SELECT DISTINCT t.* + FROM {$gp_table_prefix}event_actions ea + JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id + JOIN {$gp_table_prefix}translation_sets ts ON o.project_id = ts.project_id AND ea.locale = ts.locale + JOIN {$gp_table_prefix}translations t ON ts.id = t.translation_set_id + WHERE ea.event_id = %d AND ea.locale = %s + AND o.project_id = %d + ", + $event_id, + $locale, + $project_id->id + ), + ARRAY_A + ); +// dd($translations); + $locale_slug = $locale; + $slug = null; + $project = GP::$project->get( $project_id ); + $translation_set = GP::$translation_set->get( $translations[0][ 'translation_set_id' ] ); + $can_approve = GP::$permission->current_user_can( 'approve', $project ); + $can_write = GP::$permission->current_user_can( 'write', $project ); + $url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug ); + $discard_warning_url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug . '/discard-warning' ); + $set_priority_url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug . '/set-priority' ); + $set_status_url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug . '/set-status' ); + $word_count_type = 'original'; + $filters = array(); + $sort = array(); + $glossary = GP::$glossary->get( $project->id, $locale ); + $page = 1; + $per_page = 10000; + $total_translations_count = 0; + $text_direction = 'ltr'; + foreach ( $translations as $translation ) { +// $args['trasnslations'][] = GP::$translation->get( $translation->id ); + $args['trasnslations'][] = new \Translation_Entry( $translation ); + } + + + //dd($event_id, $translations, get_defined_vars() ); + $this->tmpl('translations', get_defined_vars()); + } + + // Get the translation_set ids for the event and locale +// $translations = $wpdb->get_results( +// $wpdb->prepare( +// " +// SELECT DISTINCT t.* +// FROM {$gp_table_prefix}event_actions ea +// JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id +// JOIN {$gp_table_prefix}translation_sets ts ON o.project_id = ts.project_id AND ea.locale = ts.locale +// JOIN {$gp_table_prefix}translations t ON ts.id = t.translation_set_id +// WHERE ea.event_id = %d AND ea.locale = %s +// ", +// $event_id, +// $locale +// ) +// ); + + + $translation_set_ids = $wpdb->get_results( + $wpdb->prepare( + " + select translation_set_id + from {$gp_table_prefix}translations + where event_id = %d + and locale = %s + ", + array( + $event_id, + $locale + ) + ) + ); + + // Get the original_id of the translations for the event and locale + $originals = $wpdb->get_results( + $wpdb->prepare( + " + select original_id + from {$gp_table_prefix}event_actions + where event_id = %d + and locale = %s + ", + array( + $event_id, + $locale + ) + ) + ); + + $translation_sets = $wpdb->get_results( + $wpdb->prepare( + " + select translation_set_id + from {$gp_table_prefix}translations + where original_id = %d + ", + array( + $originals[0]->original_id + ) + ) + ); + dd($event_id, $locale, $originals); + } +} diff --git a/templates/event.php b/templates/event.php index 35b12ef9..0edf3e03 100644 --- a/templates/event.php +++ b/templates/event.php @@ -129,7 +129,7 @@ rows() as $_locale => $row ) : ?> language->english_name ); ?> - created ); ?> + created ); ?> reviewed ); ?> users ); ?> diff --git a/templates/events-list.php b/templates/events-list.php index 139eb81f..e9d9fc0d 100644 --- a/templates/events-list.php +++ b/templates/events-list.php @@ -1,4 +1,4 @@ -add( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/host/(\d+)/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); + GP::$router->add( '/events/translations/(\d+)/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); $stats_listener = new Stats_Listener( From 77c7278ed26baf3b20f630da16b223cf7cc6f0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Amieiro=20Becerra?= <1667814+amieiro@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:32:20 +0200 Subject: [PATCH 02/31] Fix typo Co-authored-by: Alex Kirk --- includes/routes/event/translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index 724635ef..2fa31766 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -80,7 +80,7 @@ public function handle( int $event_id, string $locale ): void { $text_direction = 'ltr'; foreach ( $translations as $translation ) { // $args['trasnslations'][] = GP::$translation->get( $translation->id ); - $args['trasnslations'][] = new \Translation_Entry( $translation ); + $args['translations'][] = new \Translation_Entry( $translation ); } From 5aad306ea4b68a2c537899d8bba4a147e5e43375 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 16:32:58 +0200 Subject: [PATCH 03/31] Show multiple translation sets on a page --- autoload.php | 1 + includes/routes/event/translations.php | 228 +++++++++++++----------- templates/event-translations-footer.php | 16 ++ templates/event-translations-header.php | 34 ++++ templates/event-translations.php | 145 +++++++++++++++ templates/event.php | 2 +- templates/events-list.php | 2 +- wporg-gp-translation-events.php | 2 +- 8 files changed, 324 insertions(+), 106 deletions(-) create mode 100644 templates/event-translations-footer.php create mode 100644 templates/event-translations-header.php create mode 100644 templates/event-translations.php diff --git a/autoload.php b/autoload.php index 1eefc5b3..cb68aeef 100644 --- a/autoload.php +++ b/autoload.php @@ -8,6 +8,7 @@ require_once __DIR__ . '/includes/routes/event/details.php'; require_once __DIR__ . '/includes/routes/event/edit.php'; require_once __DIR__ . '/includes/routes/event/list.php'; +require_once __DIR__ . '/includes/routes/event/translations.php'; require_once __DIR__ . '/includes/routes/user/attend-event.php'; require_once __DIR__ . '/includes/routes/user/host-event.php'; require_once __DIR__ . '/includes/routes/user/my-events.php'; diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index 2fa31766..e10044fd 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -4,6 +4,9 @@ use Exception; use GP; +use GP_Locales; +use GP_Original; +use Translation_Entry; use Wporg\TranslationEvents\Attendee_Repository; use Wporg\TranslationEvents\Event\Event_Repository_Interface; use Wporg\TranslationEvents\Routes\Route; @@ -14,140 +17,159 @@ * Displays the event details page. */ class Translations_Route extends Route { + private $event_repository; public function __construct() { parent::__construct(); -// $this->event_repository = Translation_Events::get_event_repository(); -// $this->attendee_repository = Translation_Events::get_attendee_repository(); + $this->event_repository = Translation_Events::get_event_repository(); + // $this->attendee_repository = Translation_Events::get_attendee_repository(); } - public function handle( int $event_id, string $locale ): void { + public function handle( string $event_slug, string $locale ): void { + $user = wp_get_current_user(); + $event = get_page_by_path( $event_slug, OBJECT, Translation_Events::CPT ); + if ( ! $event ) { + $this->die_with_404(); + } + $event = $this->event_repository->get_event( $event->ID ); + if ( ! $event ) { + $this->die_with_404(); + } + + $stats_calculator = new Stats_Calculator(); + $is_editable_event = true; + if ( $event->end()->is_in_the_past() || $stats_calculator->event_has_stats( $event->id() ) ) { + $is_editable_event = false; + } + global $wpdb, $gp_table_prefix; // Get the different projects for the event and locale - $project_ids = $wpdb->get_results( + $translation_sets = $wpdb->get_results( $wpdb->prepare( " - SELECT DISTINCT p.id + SELECT DISTINCT ts.id as translation_set_id, o.project_id as project_id FROM {$gp_table_prefix}event_actions ea JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id - JOIN {$gp_table_prefix}projects p ON o.project_id = p.id + JOIN {$gp_table_prefix}translation_sets ts ON o.project_id = ts.project_id AND ea.locale = ts.locale WHERE ea.event_id = %d AND ea.locale = %s ", - $event_id, + $event->id(), $locale ) ); + gp_tmpl_load( 'event-translations-header', get_defined_vars(), $this->template_path ); // Get the translations for the current project_id, event_id and locale - foreach ( $project_ids as $project_id ) { - $translations = $wpdb->get_results( + foreach ( $translation_sets as $ts ) { + $rows = $wpdb->get_results( $wpdb->prepare( " - SELECT DISTINCT t.* + SELECT + t.*, + o.*, + t.id as id, + o.id as original_id, + t.status as translation_status, + o.status as original_status, + t.date_added as translation_added, + o.date_added as original_added FROM {$gp_table_prefix}event_actions ea JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id - JOIN {$gp_table_prefix}translation_sets ts ON o.project_id = ts.project_id AND ea.locale = ts.locale - JOIN {$gp_table_prefix}translations t ON ts.id = t.translation_set_id - WHERE ea.event_id = %d AND ea.locale = %s - AND o.project_id = %d + JOIN {$gp_table_prefix}translations t ON t.original_id = ea.original_id + WHERE ea.event_id = %d + AND t.translation_set_id = %d + AND t.date_added >= ea.happened_at ", - $event_id, - $locale, - $project_id->id - ), - ARRAY_A + $event->id(), + $ts->translation_set_id + ) ); -// dd($translations); - $locale_slug = $locale; - $slug = null; - $project = GP::$project->get( $project_id ); - $translation_set = GP::$translation_set->get( $translations[0][ 'translation_set_id' ] ); - $can_approve = GP::$permission->current_user_can( 'approve', $project ); - $can_write = GP::$permission->current_user_can( 'write', $project ); - $url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug ); - $discard_warning_url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug . '/discard-warning' ); - $set_priority_url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug . '/set-priority' ); - $set_status_url = gp_url( '/projects/' . $project->slug . '/' . $locale_slug . '/' . $slug . '/set-status' ); - $word_count_type = 'original'; - $filters = array(); - $sort = array(); - $glossary = GP::$glossary->get( $project->id, $locale ); - $page = 1; - $per_page = 10000; - $total_translations_count = 0; - $text_direction = 'ltr'; - foreach ( $translations as $translation ) { -// $args['trasnslations'][] = GP::$translation->get( $translation->id ); - $args['translations'][] = new \Translation_Entry( $translation ); + if ( empty( $rows ) ) { + continue; } + $translations = array(); + $project = GP::$project->get( $ts->project_id ); + $translation_set = GP::$translation_set->get( $ts->translation_set_id ); + $filters = array(); + $sort = array(); + $glossary = GP::$glossary->get( $project->id, $locale ); + $page = 1; + $per_page = 10000; + $total_translations_count = 0; + $text_direction = 'ltr'; + $locale = GP_Locales::by_slug( $translation_set->locale ); + $locale_slug = $translation_set->slug; + $word_count_type = $locale->word_count_type; + $can_edit = $this->can( 'edit', 'translation-set', $translation_set->id ); + $can_write = $this->can( 'write', 'project', $project->id ); + $can_approve = $this->can( 'approve', 'translation-set', $translation_set->id ); + $can_import_current = $can_approve; + $can_import_waiting = $can_approve || $this->can( 'import-waiting', 'translation-set', $translation_set->id ); + $url = gp_url_project( $project, gp_url_join( $translation_set->locale, $translation_set->slug ) ); + $set_priority_url = gp_url( '/originals/%original-id%/set_priority' ); + $discard_warning_url = gp_url_project( $project, gp_url_join( $translation_set->locale, $translation_set->slug, '-discard-warning' ) ); + $set_status_url = gp_url_project( $project, gp_url_join( $translation_set->locale, $translation_set->slug, '-set-status' ) ); + $bulk_action = gp_url_join( $url, '-bulk' ); + $editor_options[ $translation_set->id ] = compact( 'can_approve', 'can_write', 'url', 'discard_warning_url', 'set_priority_url', 'set_status_url', 'word_count_type' ); - //dd($event_id, $translations, get_defined_vars() ); - $this->tmpl('translations', get_defined_vars()); - } + foreach ( (array) $rows as $row ) { + $row->user = $row->user_last_modified = null; - // Get the translation_set ids for the event and locale -// $translations = $wpdb->get_results( -// $wpdb->prepare( -// " -// SELECT DISTINCT t.* -// FROM {$gp_table_prefix}event_actions ea -// JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id -// JOIN {$gp_table_prefix}translation_sets ts ON o.project_id = ts.project_id AND ea.locale = ts.locale -// JOIN {$gp_table_prefix}translations t ON ts.id = t.translation_set_id -// WHERE ea.event_id = %d AND ea.locale = %s -// ", -// $event_id, -// $locale -// ) -// ); - - - $translation_set_ids = $wpdb->get_results( - $wpdb->prepare( - " - select translation_set_id - from {$gp_table_prefix}translations - where event_id = %d - and locale = %s - ", - array( - $event_id, - $locale - ) - ) - ); + if ( $row->user_id ) { + $user = get_userdata( $row->user_id ); + if ( $user ) { + $row->user = (object) array( + 'ID' => $user->ID, + 'user_login' => $user->user_login, + 'display_name' => $user->display_name, + 'user_nicename' => $user->user_nicename, + ); + } + } - // Get the original_id of the translations for the event and locale - $originals = $wpdb->get_results( - $wpdb->prepare( - " - select original_id - from {$gp_table_prefix}event_actions - where event_id = %d - and locale = %s - ", - array( - $event_id, - $locale - ) - ) - ); + if ( $row->user_id_last_modified ) { + $user = get_userdata( $row->user_id_last_modified ); + if ( $user ) { + $row->user_last_modified = (object) array( + 'ID' => $user->ID, + 'user_login' => $user->user_login, + 'display_name' => $user->display_name, + 'user_nicename' => $user->user_nicename, + ); + } + } - $translation_sets = $wpdb->get_results( - $wpdb->prepare( - " - select translation_set_id - from {$gp_table_prefix}translations - where original_id = %d - ", - array( - $originals[0]->original_id - ) - ) - ); - dd($event_id, $locale, $originals); + $row->translations = array(); + for ( $i = 0; $i < $locale->nplurals; $i++ ) { + $row->translations[] = $row->{'translation_' . $i}; + } + $row->references = $row->references ? preg_split( '/\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY ) : array(); + $row->extracted_comments = $row->comment; + $row->warnings = $row->warnings ? maybe_unserialize( $row->warnings ) : null; + unset( $row->comment ); + + // Reduce range by one since we're starting at 0, see GH#516. + foreach ( range( 0, 5 ) as $i ) { + $member = "translation_$i"; + unset( $row->$member ); + } + + $row->row_id = $row->original_id . ( $row->id ? "-$row->id" : '' ); + + if ( '0' !== $row->priority ) { + $row->flags = array( + 'gp-priority: ' . GP_Original::$priorities[ $row->priority ], + ); + } + + $translations[] = new Translation_Entry( (array) $row ); + } + gp_tmpl_load( 'event-translations', get_defined_vars(), $this->template_path ); + } + + gp_tmpl_load( 'event-translations-footer', get_defined_vars(), $this->template_path ); } } diff --git a/templates/event-translations-footer.php b/templates/event-translations-footer.php new file mode 100644 index 00000000..7a608fcd --- /dev/null +++ b/templates/event-translations-footer.php @@ -0,0 +1,16 @@ + +
+ + diff --git a/templates/event-translations-header.php b/templates/event-translations-header.php new file mode 100644 index 00000000..b4a0ef06 --- /dev/null +++ b/templates/event-translations-header.php @@ -0,0 +1,34 @@ +title() ) ) ); +gp_breadcrumb_translation_events( array( '' . esc_html( $event->title() ) . '', __( 'Translations', 'glotpress' ), $locale ) ); +gp_enqueue_scripts( array( 'gp-editor', 'gp-translations-page' ) ); +wp_localize_script( + 'gp-translations-page', + '$gp_translations_options', + array( + 'sort' => __( 'Sort', 'glotpress' ), + 'filter' => __( 'Filter', 'glotpress' ), + ) +); + +gp_tmpl_header(); +?> + +
+

+ title() ); ?> + status() ) : ?> + status() ); ?> + +

+
+
diff --git a/templates/event-translations.php b/templates/event-translations.php new file mode 100644 index 00000000..2d627110 --- /dev/null +++ b/templates/event-translations.php @@ -0,0 +1,145 @@ + +
+
+

+ name ) + ); + ?> +

+
+
+ +
+ +text_direction ? ' translation-sets-rtl' : ''; ?> + + + + + + + + + + + + + +translation_set_id ) { + $translation->translation_set_id = $translation_set->id; + } + + $can_approve_translation = GP::$permission->current_user_can( 'approve', 'translation', $translation->id, array( 'translation' => $translation ) ); + gp_tmpl_load( 'translation-row', get_defined_vars() ); +} +?> + + + + +
+ + +
+ +
+
+ get_static( 'statuses' ) as $legend_status ) : + if ( ( 'changesrequested' == $legend_status ) && ( ! apply_filters( 'gp_enable_changesrequested_status', false ) ) ) { // todo: delete when we merge the gp-translation-helpers in GlotPress + continue; + } + ?> +
+
+ +
+ +
+
+
+
+
+
diff --git a/templates/event.php b/templates/event.php index 0edf3e03..175c06c1 100644 --- a/templates/event.php +++ b/templates/event.php @@ -129,7 +129,7 @@ rows() as $_locale => $row ) : ?> language->english_name ); ?> - created ); ?> + created ); ?> reviewed ); ?> users ); ?> diff --git a/templates/events-list.php b/templates/events-list.php index e9d9fc0d..139eb81f 100644 --- a/templates/events-list.php +++ b/templates/events-list.php @@ -1,4 +1,4 @@ -xadd( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/host/(\d+)/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); - GP::$router->add( '/events/translations/(\d+)/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( '/events/([a-z0-9_-]+)/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); $stats_listener = new Stats_Listener( From 10cf33739496193fd72a197cfebc6e824b08a2fa Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 16:34:43 +0200 Subject: [PATCH 04/31] typo --- templates/event-translations-footer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/event-translations-footer.php b/templates/event-translations-footer.php index 7a608fcd..c349277f 100644 --- a/templates/event-translations-footer.php +++ b/templates/event-translations-footer.php @@ -6,7 +6,7 @@ ?> $('#translations_' ).click( function() { $gp_editor_options = ; - $( '#translation' ).attr('id', null); + $( '#translations' ).attr( 'id', null ); $( '#translations_ table' ).attr( 'id', 'translations' ); $gp.editor.init( $( '#translations_' ) ); } ); From e589b8aca436556af9b89bb619f6fb3d3d8e777a Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 16:41:29 +0200 Subject: [PATCH 05/31] Use a h3 for the headlines --- templates/event-translations.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/event-translations.php b/templates/event-translations.php index 2d627110..26a5abcd 100644 --- a/templates/event-translations.php +++ b/templates/event-translations.php @@ -8,7 +8,7 @@ ?>
-

+

name ) ); ?> -

+
Date: Wed, 17 Apr 2024 16:44:53 +0200 Subject: [PATCH 06/31] Filter by the user --- includes/routes/event/translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index e10044fd..cee14782 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -80,7 +80,7 @@ public function handle( string $event_slug, string $locale ): void { JOIN {$gp_table_prefix}translations t ON t.original_id = ea.original_id WHERE ea.event_id = %d AND t.translation_set_id = %d - AND t.date_added >= ea.happened_at + AND t.user_id = ea.user_id ", $event->id(), $ts->translation_set_id From 0722fa7ab4fc07ef9c2187719b289d3b862366da Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 16:51:15 +0200 Subject: [PATCH 07/31] Already assign the editor options upon mouse move --- templates/event-translations-footer.php | 11 +++++++++-- templates/event-translations.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/templates/event-translations-footer.php b/templates/event-translations-footer.php index c349277f..95449d56 100644 --- a/templates/event-translations-footer.php +++ b/templates/event-translations-footer.php @@ -4,12 +4,19 @@ jQuery( function($) { $options ) { ?> - $('#translations_' ).click( function() { + $('#translations_' ).click( set_translation_table_ ); + $('#translations_' ).mousemove( function() { + if ( ! $( '#translations', this ).length ) { + set_translation_table_(); + } + }); + + function set_translation_table_() { $gp_editor_options = ; $( '#translations' ).attr( 'id', null ); $( '#translations_ table' ).attr( 'id', 'translations' ); $gp.editor.init( $( '#translations_' ) ); - } ); + } } ); diff --git a/templates/event-translations.php b/templates/event-translations.php index 26a5abcd..397a66b5 100644 --- a/templates/event-translations.php +++ b/templates/event-translations.php @@ -43,7 +43,7 @@ */ do_action( 'gp_before_translation_table', get_defined_vars() ); ?> - +
Date: Wed, 17 Apr 2024 17:02:04 +0200 Subject: [PATCH 08/31] Link the translation set --- templates/event-translations.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/event-translations.php b/templates/event-translations.php index 397a66b5..ab647fb0 100644 --- a/templates/event-translations.php +++ b/templates/event-translations.php @@ -13,8 +13,8 @@ printf( /* translators: 1: Project name. 2: Translation set name. */ __( 'Translation of %1$s: %2$s', 'glotpress' ), - gp_link_project_get( - $project, + gp_link_get( + gp_url_project_locale( $project, $translation_set->locale, $translation_set->slug ), esc_html( gp_project_names_from_root( $project ) ) From 681122dd9f95a504d43bb70ff190f0e7cdf120ff Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 17:11:55 +0200 Subject: [PATCH 09/31] Ensure to enqueue the wporg-translate-editor --- templates/event-translations-footer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/event-translations-footer.php b/templates/event-translations-footer.php index 95449d56..7a94fab2 100644 --- a/templates/event-translations-footer.php +++ b/templates/event-translations-footer.php @@ -20,4 +20,6 @@ function set_translation_table_() } ); - + From 35991308019eda2c30e3bd8b629dcfe1411846e5 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 17:20:30 +0200 Subject: [PATCH 10/31] Add a table of contents --- includes/routes/event/translations.php | 10 ++++++++-- templates/event-translations-header.php | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index cee14782..ecc37608 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -48,7 +48,7 @@ public function handle( string $event_slug, string $locale ): void { $translation_sets = $wpdb->get_results( $wpdb->prepare( " - SELECT DISTINCT ts.id as translation_set_id, o.project_id as project_id + SELECT DISTINCT ts.id as translation_set_id, ts.name, o.project_id as project_id FROM {$gp_table_prefix}event_actions ea JOIN {$gp_table_prefix}originals o ON ea.original_id = o.id JOIN {$gp_table_prefix}translation_sets ts ON o.project_id = ts.project_id AND ea.locale = ts.locale @@ -59,6 +59,11 @@ public function handle( string $event_slug, string $locale ): void { $locale ) ); + $projects = array(); + $translations = array(); + foreach ( $translation_sets as $ts ) { + $projects[ $ts->translation_set_id ] = GP::$project->get( $ts->project_id ); + } gp_tmpl_load( 'event-translations-header', get_defined_vars(), $this->template_path ); // Get the translations for the current project_id, event_id and locale @@ -87,10 +92,11 @@ public function handle( string $event_slug, string $locale ): void { ) ); if ( empty( $rows ) ) { + echo ''; continue; } $translations = array(); - $project = GP::$project->get( $ts->project_id ); + $project = $projects[ $ts->translation_set_id ]; $translation_set = GP::$translation_set->get( $ts->translation_set_id ); $filters = array(); $sort = array(); diff --git a/templates/event-translations-header.php b/templates/event-translations-header.php index b4a0ef06..7bb6932e 100644 --- a/templates/event-translations-header.php +++ b/templates/event-translations-header.php @@ -32,3 +32,10 @@
+

Projects

+ +
From 0256e31988f7c9a985bca0207bc1b0ca9d790323 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 17:32:40 +0200 Subject: [PATCH 11/31] Allow toggling between waiting and all contributions --- includes/routes/event/translations.php | 9 ++++++--- templates/event-translations-header.php | 24 +++++++++++++++++++++++- templates/event-translations.php | 2 +- wporg-gp-translation-events.php | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index ecc37608..0e5e36c1 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -25,7 +25,7 @@ public function __construct() { // $this->attendee_repository = Translation_Events::get_attendee_repository(); } - public function handle( string $event_slug, string $locale ): void { + public function handle( string $event_slug, string $locale, string $status = '%' ): void { $user = wp_get_current_user(); $event = get_page_by_path( $event_slug, OBJECT, Translation_Events::CPT ); if ( ! $event ) { @@ -61,8 +61,10 @@ public function handle( string $event_slug, string $locale ): void { ); $projects = array(); $translations = array(); + $locale = GP_Locales::by_slug( $locale ); foreach ( $translation_sets as $ts ) { $projects[ $ts->translation_set_id ] = GP::$project->get( $ts->project_id ); + } gp_tmpl_load( 'event-translations-header', get_defined_vars(), $this->template_path ); @@ -86,9 +88,11 @@ public function handle( string $event_slug, string $locale ): void { WHERE ea.event_id = %d AND t.translation_set_id = %d AND t.user_id = ea.user_id + AND t.status LIKE %s ", $event->id(), - $ts->translation_set_id + $ts->translation_set_id, + $status ) ); if ( empty( $rows ) ) { @@ -105,7 +109,6 @@ public function handle( string $event_slug, string $locale ): void { $per_page = 10000; $total_translations_count = 0; $text_direction = 'ltr'; - $locale = GP_Locales::by_slug( $translation_set->locale ); $locale_slug = $translation_set->slug; $word_count_type = $locale->word_count_type; $can_edit = $this->can( 'edit', 'translation-set', $translation_set->id ); diff --git a/templates/event-translations-header.php b/templates/event-translations-header.php index 7bb6932e..32ff6051 100644 --- a/templates/event-translations-header.php +++ b/templates/event-translations-header.php @@ -32,10 +32,32 @@
-

Projects

+

+ english_name + ) + ); + ?> +

+ + + + + +
diff --git a/templates/event-translations.php b/templates/event-translations.php index ab647fb0..731a7ef2 100644 --- a/templates/event-translations.php +++ b/templates/event-translations.php @@ -19,7 +19,7 @@ gp_project_names_from_root( $project ) ) ), - esc_html( $translation_set->name ) + esc_html( $locale->name ) ); ?> diff --git a/wporg-gp-translation-events.php b/wporg-gp-translation-events.php index af3d0fdb..efba6764 100644 --- a/wporg-gp-translation-events.php +++ b/wporg-gp-translation-events.php @@ -95,7 +95,7 @@ public function gp_init() { GP::$router->add( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/host/(\d+)/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); - GP::$router->add( '/events/([a-z0-9_-]+)/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( '/events/([a-z0-9_-]+)/([a-z0-9_-]+)(?:/([a-z0-9_-]+))?', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); $stats_listener = new Stats_Listener( From 8c0e1787df057333c492119708457ab05eef08c3 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 17:36:18 +0200 Subject: [PATCH 12/31] styling --- assets/css/translation-events.css | 6 ++++++ templates/event-translations-header.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/css/translation-events.css b/assets/css/translation-events.css index 19eb8b05..21ba4f05 100644 --- a/assets/css/translation-events.css +++ b/assets/css/translation-events.css @@ -53,6 +53,7 @@ .event-details-stats table { margin: 1rem; } + .event-details-stats table { width: 100%; table-layout: fixed; @@ -348,6 +349,7 @@ a.event-page-edit-link:hover { border-bottom: var(--gp-color-btn-primary-bg) thin solid; text-decoration: none; } + ul.text-snippets { padding: 0; margin-left: 160px; @@ -356,6 +358,10 @@ ul.text-snippets { content: ' 🎉'; } +ul#translation-links li { + margin-bottom: .5em; +} + /* show the event-details-right below instead of on the right on mobile */ @media (max-width: 768px) { diff --git a/templates/event-translations-header.php b/templates/event-translations-header.php index 32ff6051..5513afa3 100644 --- a/templates/event-translations-header.php +++ b/templates/event-translations-header.php @@ -43,7 +43,7 @@ ); ?> -
    +
- - + + + @@ -73,7 +81,7 @@ - + @@ -96,10 +104,10 @@ } ?>
-
+
get_static( 'statuses' ) as $legend_status ) : - if ( ( 'changesrequested' == $legend_status ) && ( ! apply_filters( 'gp_enable_changesrequested_status', false ) ) ) { // todo: delete when we merge the gp-translation-helpers in GlotPress + if ( ( 'changesrequested' === $legend_status ) && ( ! apply_filters( 'gp_enable_changesrequested_status', false ) ) ) { // todo: delete when we merge the gp-translation-helpers in GlotPress. continue; } ?> @@ -108,25 +116,25 @@
-
+
From 450b798dd4846bbf3e141378de94db87094d2003 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 19:52:19 +0200 Subject: [PATCH 15/31] Improve regex --- includes/routes/event/translations.php | 4 ++-- templates/event-translations-header.php | 2 +- wporg-gp-translation-events.php | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index 22990b13..d6544c80 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -24,7 +24,7 @@ public function __construct() { $this->event_repository = Translation_Events::get_event_repository(); } - public function handle( string $event_slug, string $locale, string $status = '%' ): void { + public function handle( string $event_slug, string $locale, string $status = 'any' ): void { $user = wp_get_current_user(); $event = get_page_by_path( $event_slug, OBJECT, Translation_Events::CPT ); if ( ! $event ) { @@ -92,7 +92,7 @@ public function handle( string $event_slug, string $locale, string $status = '%' ", $event->id(), $ts->translation_set_id, - $status + trim( $status, '/' ) === 'waiting' ? 'waiting' : '%' ) ); // phpcs:enable diff --git a/templates/event-translations-header.php b/templates/event-translations-header.php index 5513afa3..a010fa97 100644 --- a/templates/event-translations-header.php +++ b/templates/event-translations-header.php @@ -50,7 +50,7 @@ add( '/events?', array( 'Wporg\TranslationEvents\Routes\Event\List_Route', 'handle' ) ); GP::$router->add( '/events/new', array( 'Wporg\TranslationEvents\Routes\Event\Create_Route', 'handle' ) ); GP::$router->add( '/events/edit/(\d+)', array( 'Wporg\TranslationEvents\Routes\Event\Edit_Route', 'handle' ) ); GP::$router->add( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/host/(\d+)/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); - GP::$router->add( '/events/([a-z0-9_-]+)/([a-z0-9_-]+)(?:/([a-z0-9_-]+))?', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( '/events/([a-z0-9_-]+)/' . $locale . '(/waiting)?', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); $stats_listener = new Stats_Listener( From eb9294932ce2ce8b26f6ad0f7373ded14f486ccc Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 19:52:44 +0200 Subject: [PATCH 16/31] Update includes/routes/event/translations.php Co-authored-by: Paulo Pinto --- includes/routes/event/translations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index d6544c80..ae05e63b 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -2,7 +2,6 @@ namespace Wporg\TranslationEvents\Routes\Event; -use Exception; use GP; use GP_Locales; use GP_Original; From ba11cbeba7e17ed05367ea7a22b6892174239ce3 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 19:52:50 +0200 Subject: [PATCH 17/31] Update includes/routes/event/translations.php Co-authored-by: Paulo Pinto --- includes/routes/event/translations.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index ae05e63b..d376aa15 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -6,8 +6,6 @@ use GP_Locales; use GP_Original; use Translation_Entry; -use Wporg\TranslationEvents\Attendee_Repository; -use Wporg\TranslationEvents\Event\Event_Repository_Interface; use Wporg\TranslationEvents\Routes\Route; use Wporg\TranslationEvents\Stats\Stats_Calculator; use Wporg\TranslationEvents\Translation_Events; From 8ec253b98c0dbfd43ae086a31d9904410942c712 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 19:52:56 +0200 Subject: [PATCH 18/31] Update includes/routes/event/translations.php Co-authored-by: Paulo Pinto --- includes/routes/event/translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index d376aa15..cdc3c441 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -14,7 +14,7 @@ * Displays the event details page. */ class Translations_Route extends Route { - private $event_repository; + private Event_Repository_Interface $event_repository; public function __construct() { parent::__construct(); From 94312438336cf35db6b0c7ef67d2b6567e792e90 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 19:57:36 +0200 Subject: [PATCH 19/31] Use variables in regex --- wporg-gp-translation-events.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wporg-gp-translation-events.php b/wporg-gp-translation-events.php index ace71acd..c0775ad3 100644 --- a/wporg-gp-translation-events.php +++ b/wporg-gp-translation-events.php @@ -91,15 +91,19 @@ public function __construct() { public function gp_init() { $locale = '(' . implode( '|', wp_list_pluck( GP_Locales::locales(), 'slug' ) ) . ')'; + $slug = '([a-z0-9_-]+)'; + $status = '(waiting)'; + $id = '(\d+)'; GP::$router->add( '/events?', array( 'Wporg\TranslationEvents\Routes\Event\List_Route', 'handle' ) ); GP::$router->add( '/events/new', array( 'Wporg\TranslationEvents\Routes\Event\Create_Route', 'handle' ) ); - GP::$router->add( '/events/edit/(\d+)', array( 'Wporg\TranslationEvents\Routes\Event\Edit_Route', 'handle' ) ); - GP::$router->add( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); - GP::$router->add( '/events/host/(\d+)/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); + GP::$router->add( '/events/edit/', array( 'Wporg\TranslationEvents\Routes\Event\Edit_Route', 'handle' ) ); + GP::$router->add( "/events/attend/$id", array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); + GP::$router->add( "/events/host/$id/$id", array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); - GP::$router->add( '/events/([a-z0-9_-]+)/' . $locale . '(/waiting)?', array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); - GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); + GP::$router->add( "/events/$slug/$locale/$status", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( "/events/$slug/$locale", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( "/events/$slug", array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); $stats_listener = new Stats_Listener( self::get_event_repository(), From b9e8bd3bd27bb0837f0dc03cadc303ce21849259 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 17 Apr 2024 20:00:31 +0200 Subject: [PATCH 20/31] Add missing use --- includes/routes/event/translations.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index cdc3c441..7e3b40b1 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -9,6 +9,8 @@ use Wporg\TranslationEvents\Routes\Route; use Wporg\TranslationEvents\Stats\Stats_Calculator; use Wporg\TranslationEvents\Translation_Events; +use Wporg\TranslationEvents\Event\Event_Repository_Cached; +use Wporg\TranslationEvents\Event\Event_Repository_Interface; /** * Displays the event details page. From f27f39ec21b9e893141b91c78354a56b8b303580 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Thu, 18 Apr 2024 18:12:21 +0200 Subject: [PATCH 21/31] Move add "translations" to the URL --- templates/event.php | 2 +- wporg-gp-translation-events.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/event.php b/templates/event.php index 175c06c1..ff36b51f 100644 --- a/templates/event.php +++ b/templates/event.php @@ -129,7 +129,7 @@ rows() as $_locale => $row ) : ?> - + diff --git a/wporg-gp-translation-events.php b/wporg-gp-translation-events.php index c0775ad3..abad4fd9 100644 --- a/wporg-gp-translation-events.php +++ b/wporg-gp-translation-events.php @@ -101,8 +101,8 @@ public function gp_init() { GP::$router->add( "/events/attend/$id", array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); GP::$router->add( "/events/host/$id/$id", array( 'Wporg\TranslationEvents\Routes\User\Host_Event_Route', 'handle' ), 'post' ); GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); - GP::$router->add( "/events/$slug/$locale/$status", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); - GP::$router->add( "/events/$slug/$locale", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( "/events/$slug/translations/$locale/$status", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); + GP::$router->add( "/events/$slug/translations/$locale", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) ); GP::$router->add( "/events/$slug", array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); $stats_listener = new Stats_Listener( From 315f590c9590fb0c0ed8849ee1dac5105b743fec Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 19 Apr 2024 09:10:15 +0200 Subject: [PATCH 22/31] Show waiting strings --- includes/stats/stats-calculator.php | 11 ++++++++--- templates/event.php | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/stats/stats-calculator.php b/includes/stats/stats-calculator.php index 0df792f3..4ec53b0a 100644 --- a/includes/stats/stats-calculator.php +++ b/includes/stats/stats-calculator.php @@ -14,12 +14,14 @@ class Stats_Row { public int $created; public int $reviewed; + public int $waiting; public int $users; public ?GP_Locale $language = null; - public function __construct( $created, $reviewed, $users, ?GP_Locale $language = null ) { + public function __construct( $created, $reviewed, $waiting, $users, ?GP_Locale $language = null ) { $this->created = $created; $this->reviewed = $reviewed; + $this->waiting = $waiting; $this->users = $users; $this->language = $language; } @@ -103,8 +105,10 @@ public function for_event( int $event_id ): Event_Stats { select locale, sum(action = 'create') as created, count(*) as total, - count(distinct user_id) as users - from {$gp_table_prefix}event_actions + sum(t.status = 'waiting') as waiting, + count(distinct ea.user_id) as users + from {$gp_table_prefix}event_actions ea + left join {$gp_table_prefix}translations t ON ea.original_id = t.original_id and ea.user_id = t.user_id where event_id = %d group by locale with rollup ", @@ -133,6 +137,7 @@ public function for_event( int $event_id ): Event_Stats { $stats_row = new Stats_Row( $row->created, $row->total - $row->created, + $row->waiting, $row->users, $lang ); diff --git a/templates/event.php b/templates/event.php index ff36b51f..372317b3 100644 --- a/templates/event.php +++ b/templates/event.php @@ -118,9 +118,10 @@
language->english_name ); ?>created ); ?>created ); ?> reviewed ); ?> users ); ?>
- - - + + + + @@ -137,6 +138,7 @@ + From 5270c2fd1e86cf4ccd40eb9d7834a51bbcf35055 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 19 Apr 2024 09:11:23 +0200 Subject: [PATCH 23/31] typo --- templates/event.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/event.php b/templates/event.php index 372317b3..d9465ab0 100644 --- a/templates/event.php +++ b/templates/event.php @@ -131,6 +131,7 @@ + From 2f429699395964f20dae42bc73924e323247611b Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 19 Apr 2024 10:12:26 +0200 Subject: [PATCH 24/31] Fix tests --- includes/stats/stats-calculator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/stats/stats-calculator.php b/includes/stats/stats-calculator.php index 4ec53b0a..a93baa7b 100644 --- a/includes/stats/stats-calculator.php +++ b/includes/stats/stats-calculator.php @@ -134,6 +134,10 @@ public function for_event( int $event_id ): Event_Stats { $lang = null; } + if ( is_null( $row->waiting ) ) { + $row->waiting = 0; + } + $stats_row = new Stats_Row( $row->created, $row->total - $row->created, From f2eb27d69008733b0bfd7a4b3d271c271320f3ae Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 19 Apr 2024 10:13:49 +0200 Subject: [PATCH 25/31] comment --- includes/stats/stats-calculator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/stats/stats-calculator.php b/includes/stats/stats-calculator.php index a93baa7b..e34b5b8c 100644 --- a/includes/stats/stats-calculator.php +++ b/includes/stats/stats-calculator.php @@ -135,6 +135,7 @@ public function for_event( int $event_id ): Event_Stats { } if ( is_null( $row->waiting ) ) { + // The corresponding translations are missing. Could be a unit test or data corruption. $row->waiting = 0; } From b7514a8d93c3a618407b9488df2f82c88acfa95b Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Tue, 23 Apr 2024 14:19:48 +0200 Subject: [PATCH 26/31] Load translation helpers editor --- templates/event-translations-footer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/event-translations-footer.php b/templates/event-translations-footer.php index 7a94fab2..72ab2576 100644 --- a/templates/event-translations-footer.php +++ b/templates/event-translations-footer.php @@ -16,6 +16,7 @@ function set_translation_table_() $( '#translations' ).attr( 'id', null ); $( '#translations_ table' ).attr( 'id', 'translations' ); $gp.editor.init( $( '#translations_' ) ); + $gp_translation_helpers_editor = $gp_translation_helpers_editor_; } } ); From eee97f48f8d63cd5dc3e393c77a8d4ba3b749cde Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Tue, 23 Apr 2024 17:08:44 +0200 Subject: [PATCH 27/31] Make things work with gp-translation-helpers --- includes/routes/event/translations.php | 7 ++++--- templates/event-translations-footer.php | 16 +++++++++++++--- .../{event-translations.php => translations.php} | 0 3 files changed, 17 insertions(+), 6 deletions(-) rename templates/{event-translations.php => translations.php} (100%) diff --git a/includes/routes/event/translations.php b/includes/routes/event/translations.php index 7e3b40b1..f5ac8735 100644 --- a/includes/routes/event/translations.php +++ b/includes/routes/event/translations.php @@ -109,7 +109,8 @@ public function handle( string $event_slug, string $locale, string $status = 'an $per_page = 10000; $total_translations_count = 0; $text_direction = 'ltr'; - $locale_slug = $translation_set->slug; + $locale_slug = $translation_set->locale; + $translation_set_slug = $translation_set->slug; $word_count_type = $locale->word_count_type; $can_edit = $this->can( 'edit', 'translation-set', $translation_set->id ); $can_write = $this->can( 'write', 'project', $project->id ); @@ -175,9 +176,9 @@ public function handle( string $event_slug, string $locale, string $status = 'an ); } - $translations[] = new Translation_Entry( (array) $row ); + $translations[ $row->row_id ] = new Translation_Entry( (array) $row ); } - gp_tmpl_load( 'event-translations', get_defined_vars(), $this->template_path ); + gp_tmpl_load( 'translations', get_defined_vars(), $this->template_path ); } gp_tmpl_load( 'event-translations-footer', get_defined_vars(), $this->template_path ); diff --git a/templates/event-translations-footer.php b/templates/event-translations-footer.php index 72ab2576..f740bdca 100644 --- a/templates/event-translations-footer.php +++ b/templates/event-translations-footer.php @@ -2,7 +2,10 @@
Total totals()->created ); ?>totals()->waiting ); ?> totals()->reviewed ); ?> totals()->users ); ?>
language->english_name ); ?> created ); ?>waiting ); ?> reviewed ); ?> users ); ?>