Changeset 12656
- Timestamp:
- 06/14/2023 10:54:45 AM (2 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/css/discussion.css
r12624 r12656 197 197 padding: 8px; 198 198 } 199 .meta summary.feedback-summary {200 font-size: 1. 2em;199 .meta summary.feedback-summary, .meta summary.chatgpt-summary{ 200 font-size: 1.1em; 201 201 font-weight: bold; 202 202 padding: 7px 0; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers-assets/js/translation-discussion.js
r11837 r12656 2 2 jQuery( function( $ ) { 3 3 $( document ).on( 'click', '.helper-translation-discussion .comments-selector a', function( e ) { 4 var $comments, $selector;5 6 4 e.preventDefault(); 7 5 $( '.comments-selector a' ).removeClass( 'active-link' ); 8 6 $( this ).addClass( 'active-link' ); 9 $comments = jQuery( e.target ).parents( 'h6' ).next( '.discussion-list' );10 $selector = $( e.target ).data( 'selector' );7 const $comments = jQuery( e.target ).parents( 'h6' ).next( '.discussion-list' ); 8 const $selector = $( e.target ).data( 'selector' ); 11 9 if ( 'all' === $selector ) { 12 10 $comments.children().show(); … … 23 21 24 22 function createShadowPost( formdata, submitComment ) { 25 vardata = {23 const data = { 26 24 action: 'create_shadow_post', 27 25 data: formdata, … … 33 31 type: 'POST', 34 32 url: wpApiSettings.admin_ajax_url, 35 data : data,36 } 33 data, 34 }, 37 35 ).done( 38 36 function( response ) { 39 37 formdata.post = response.data; 40 38 submitComment( formdata ); 41 } 39 }, 42 40 ); 43 41 } 44 42 45 43 $( document ).on( 'submit', '.helper-translation-discussion .comment-form', function( e ) { 46 var$commentform = $( e.target );47 varpostId = $commentform.attr( 'id' ).split( '-' )[ 1 ];48 varsubmitComment = function( formdata ) {44 const $commentform = $( e.target ); 45 const postId = $commentform.attr( 'id' ).split( '-' )[ 1 ]; 46 const submitComment = function( formdata ) { 49 47 $.ajax( { 50 48 url: wpApiSettings.root + 'wp/v2/comments', 51 49 method: 'POST', 52 beforeSend : function( xhr ) {50 beforeSend( xhr ) { 53 51 xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce ); 54 52 }, … … 65 63 }; 66 64 67 varformdata = {65 const formdata = { 68 66 content: $commentform.find( 'textarea[name=comment]' ).val(), 69 67 parent: $commentform.find( 'input[name=comment_parent]' ).val(), -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-openai-review.php
r12629 r12656 27 27 return array( 28 28 'status' => 404, 29 'error' => ' No OpenAI Key defined',29 'error' => 'no-openai-key', 30 30 ); 31 31 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/editor.js
r12635 r12656 1 /* global $gp, $gp_translation_helpers_editor, wpApiSettings, $gp_comment_feedback_settings, console, $gp_editor_options, EventSource*/1 /* global $gp, $gp_translation_helpers_editor, wpApiSettings, $gp_comment_feedback_settings, $gp_editor_options, fetch, TextDecoderStream */ 2 2 /* eslint camelcase: "off" */ 3 3 jQuery( function( $ ) { … … 69 69 url: wpApiSettings.admin_ajax_url, 70 70 data, 71 } 71 }, 72 72 ).done( 73 73 function( response ) { 74 74 formdata.post = response.data; 75 75 submitComment( formdata ); 76 } 76 }, 77 77 ); 78 78 } … … 339 339 index, 340 340 fieldLength, 341 lineLength 341 lineLength, 342 342 ) { 343 343 if ( lineLength === 0 ) { … … 409 409 response_span.text( event.value ); 410 410 } else if ( event.type === 'reconnect-interval' ) { 411 console.log( 'We should set reconnect interval to %d milliseconds', event.value );411 // console.log( 'We should set reconnect interval to %d milliseconds', event.value ); 412 412 } 413 413 } ); 414 414 415 let response = await fetch(415 const response = await fetch( 416 416 'https://api.openai.com/v1/chat/completions', 417 417 { … … 422 422 method: 'POST', 423 423 body: JSON.stringify( request ), 424 } 424 }, 425 425 ); 426 const reader = response.body.pipeThrough( new TextDecoderStream()).getReader();427 428 while ( true) {426 const reader = response.body.pipeThrough( new TextDecoderStream() ).getReader(); 427 428 while ( true ) { 429 429 const { value, done } = await reader.read(); 430 if ( done ) break; 430 if ( done ) { 431 break; 432 } 431 433 parser.feed( value ); 432 434 } … … 438 440 * @param {string} rowId The row-id attribute of the current row. 439 441 * @param {string} currentRow The current row. 442 * @param {boolean} isRetry This is a retry. 440 443 */ 441 444 function fetchOpenAIReviewResponse( rowId, currentRow, isRetry ) { … … 443 446 const original_str = currentRow.find( '.original' ); 444 447 let glossary_prompt = ''; 445 let result = '';446 448 447 449 $.each( $( original_str ).find( '.glossary-word' ), function( k, word ) { … … 468 470 currentRow.find( '.openai-review .suggestions__loading-indicator' ).hide(); 469 471 currentRow.find( '.openai-review .auto-review-result' ).html( '<h4>Review by ChatGPT' ).append( '<span style="white-space: pre-line">' ); 470 invokeChatGPT( messages, currentRow.find( '.openai-review .auto-review-result span' ) ).then( ()=>currentRow.find( '.openai-review .auto-review-result' ).append( ' <a href="#" class="retry-auto-review">Retry</a>' ));472 invokeChatGPT( messages, currentRow.find( '.openai-review .auto-review-result span' ) ).then( () => currentRow.find( '.openai-review .auto-review-result' ).append( ' <a href="#" class="retry-auto-review">Retry</a>' ) ); 471 473 } 472 474 } ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/reject-feedback.js
r12435 r12656 3 3 $( document ).ready( 4 4 function() { 5 varrowIds = [];6 vartranslationIds = [];7 varoriginalIds = [];8 varbulkTranslationStatus = [];9 vartranslationStatuses = {};10 varstatusIndex = 0;11 varmodalFeedbackForm =5 let rowIds = []; 6 const translationIds = []; 7 const originalIds = []; 8 const bulkTranslationStatus = []; 9 const translationStatuses = {}; 10 let statusIndex = 0; 11 const modalFeedbackForm = 12 12 '<div id="reject-feedback-form" style="display:none;">' + 13 13 '<form>' + … … 32 32 rowIds = $( 'input:checked', $( 'table#translations th.checkbox' ) ).map( 33 33 function() { 34 varselectedRow = $( this ).parents( 'tr.preview' );35 vartranslationStatus = '';34 const selectedRow = $( this ).parents( 'tr.preview' ); 35 let translationStatus = ''; 36 36 37 37 if ( ( selectedRow.length ) && ( ! selectedRow.hasClass( 'untranslated' ) ) ) { … … 42 42 $( this ).prop( 'checked', false ); 43 43 return null; 44 } 44 }, 45 45 ).get(); 46 46 47 47 rowIds.forEach( 48 48 function( rowId ) { 49 varoriginalId = $gp.editor.original_id_from_row_id( rowId );50 vartranslationId = $gp.editor.translation_id_from_row_id( rowId );49 const originalId = $gp.editor.original_id_from_row_id( rowId ); 50 const translationId = $gp.editor.translation_id_from_row_id( rowId ); 51 51 52 52 if ( originalId && translationId ) { … … 56 56 } 57 57 statusIndex++; 58 } 58 }, 59 59 ); 60 60 … … 70 70 tb_show( 'Reject with Feedback', '#TB_inline?inlineId=reject-feedback-form' ); 71 71 } 72 } 72 }, 73 73 ); 74 74 … … 79 79 */ 80 80 function updateBulkRejectStatus( thisObj ) { 81 varform = thisObj.closest( 'form' );82 varcommentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val();83 varnumberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length;81 const form = thisObj.closest( 'form' ); 82 const commentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val(); 83 const numberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length; 84 84 if ( commentText || numberOfCheckedReasons ) { 85 85 $( 'form#bulk-actions-toolbar-top option[value="reject"]' ).attr( 'value', 'changesrequested' ).text( 'Changes requested' ); … … 91 91 '#modal-reject-btn, #modal-requestchanges-btn', 92 92 function( e ) { 93 varcomment = '';94 varcommentReason = [];95 varcommentData = {};96 varform = $( this ).closest( 'form' );93 let comment = ''; 94 const commentReason = []; 95 const commentData = {}; 96 const form = $( this ).closest( 'form' ); 97 97 98 98 form.find( 'input[name="modal_feedback_reason"]:checked' ).each( 99 99 function() { 100 100 commentReason.push( this.value ); 101 } 101 }, 102 102 ); 103 103 … … 118 118 commentWithFeedback( commentData, false, 'rejected' ); 119 119 e.preventDefault(); 120 } 120 }, 121 121 ); 122 122 … … 125 125 function( e ) { 126 126 toggleButtons( $( this ), e ); 127 } 127 }, 128 128 ); 129 129 $( '.feedback-comment' ).on( … … 131 131 function( e ) { 132 132 toggleButtons( $( this ), e ); 133 } 133 }, 134 134 ); 135 135 … … 145 145 */ 146 146 function toggleButtons( thisObj, event ) { 147 varform = thisObj.closest( 'form' );148 varcommentText = form.find( 'textarea[name="feedback_comment"]' ).val();149 vardiv = thisObj.closest( '.meta' );150 varrejectButton = $( '.reject', div );151 varchangesRequestedtButton = $( '.changesrequested', div );152 varnumberOfCheckedReasons = form.find( 'input[name="feedback_reason"]:checked' ).length;147 const form = thisObj.closest( 'form' ); 148 const commentText = form.find( 'textarea[name="feedback_comment"]' ).val(); 149 const div = thisObj.closest( '.meta' ); 150 const rejectButton = $( '.reject', div ); 151 const changesRequestedtButton = $( '.changesrequested', div ); 152 const numberOfCheckedReasons = form.find( 'input[name="feedback_reason"]:checked' ).length; 153 153 154 154 if ( commentText.trim() !== '' || numberOfCheckedReasons ) { … … 166 166 function( e ) { 167 167 toggleModalButtons( $( this ), e ); 168 } 168 }, 169 169 ); 170 170 $( 'textarea[name="modal_feedback_comment"]' ).on( … … 172 172 function( e ) { 173 173 toggleModalButtons( $( this ), e ); 174 } 174 }, 175 175 ); 176 176 … … 186 186 */ 187 187 function toggleModalButtons( thisObj, event ) { 188 varform = thisObj.closest( 'form' );189 varcommentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val();190 vardiv = thisObj.closest( '#TB_ajaxContent' );191 varrejectButton = $( '#modal-reject-btn', div );192 varchangesRequestedtButton = $( '#modal-requestchanges-btn', div );193 varnumberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length;188 const form = thisObj.closest( 'form' ); 189 const commentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val(); 190 const div = thisObj.closest( '#TB_ajaxContent' ); 191 const rejectButton = $( '#modal-reject-btn', div ); 192 const changesRequestedtButton = $( '#modal-requestchanges-btn', div ); 193 const numberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length; 194 194 195 195 if ( commentText.trim() !== '' || numberOfCheckedReasons ) { … … 206 206 { 207 207 tooltipClass: 'hoverTooltip', 208 } 208 }, 209 209 ); 210 210 211 211 $( 'input[name="feedback_reason"][value="glossary"]' ).change( 212 212 function() { 213 varglossaryWords = $( this ).closest( 'tr' ).find( '.original .glossary-word' ).get().map( function( word ) {213 const glossaryWords = $( this ).closest( 'tr' ).find( '.original .glossary-word' ).get().map( function( word ) { 214 214 return word.innerText; 215 215 } ); 216 216 if ( $( this ).is( ':checked' ) && glossaryWords.length ) { 217 217 // eslint-disable-next-line vars-on-top 218 varglossaryList = document.createElement( 'ul' );218 const glossaryList = document.createElement( 'ul' ); 219 219 glossaryList.innerHTML = '<h6>Glossary Words</h6>'; 220 220 $( glossaryList ).attr( 'id', 'glossary-item-list' ); 221 221 glossaryWords.forEach( 222 222 function( item ) { 223 varli = document.createElement( 'li' );224 varcheckbox = $( '<input />', { type: 'checkbox', class: 'glossary-word-item', value: item } );223 const li = document.createElement( 'li' ); 224 const checkbox = $( '<input />', { type: 'checkbox', class: 'glossary-word-item', value: item } ); 225 225 $( '<label></label>' ).html( checkbox ).append( item ).appendTo( li ); 226 226 glossaryList.appendChild( li ); 227 } 227 }, 228 228 ); 229 229 $( this ).closest( 'ul' ).after( glossaryList ); … … 232 232 $( this ).closest( '.feedback-reason-list' ).siblings( '.feedback-comment' ).find( 'textarea' ).val( '' ); 233 233 } 234 } 234 }, 235 235 ); 236 236 … … 238 238 'change', 239 239 'input.glossary-word-item', function( ) { 240 vartextArea = $( this ).closest( 'ul' ).next().find( 'textarea' );240 const textArea = $( this ).closest( 'ul' ).next().find( 'textarea' ); 241 241 if ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 0 ) { 242 242 textArea.val( '' ); … … 244 244 } 245 245 // eslint-disable-next-line vars-on-top 246 varmessage = 'There is a problem with ' + ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 1 ? 'the glossary term' : 'the following glossary terms' ) + ': ' + $( this ).closest( 'ul' ).find( 'input:checked' ).get().map( function( word ) {246 const message = 'There is a problem with ' + ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 1 ? 'the glossary term' : 'the following glossary terms' ) + ': ' + $( this ).closest( 'ul' ).find( 'input:checked' ).get().map( function( word ) { 247 247 return word.defaultValue; 248 248 } ).join( ', ' ); … … 250 250 textArea.val( message ); 251 251 } ); 252 } 252 }, 253 253 ); 254 254 … … 270 270 271 271 function setStatus( that, status ) { 272 varbutton = $( that );273 varfeedbackData = {};274 varcommentReason = [];275 varcomment = '';276 vardiv = button.closest( 'div.meta' );272 const button = $( that ); 273 const feedbackData = {}; 274 const commentReason = []; 275 let comment = ''; 276 const div = button.closest( 'div.meta' ); 277 277 278 278 div.find( 'input[name="feedback_reason"]:checked' ).each( 279 279 function() { 280 280 commentReason.push( this.value ); 281 } 281 }, 282 282 ); 283 283 … … 300 300 301 301 function commentWithFeedback( feedbackData, button, status ) { 302 vardata = {};303 vardiv = {};302 let data = {}; 303 let div = {}; 304 304 if ( button ) { 305 305 div = button.closest( 'div.meta' ); … … 318 318 319 319 url: $gp_comment_feedback_settings.url, 320 data : data,321 } 320 data, 321 }, 322 322 ).done( 323 323 function() { … … 329 329 div.find( 'textarea[name="feedback_comment"]' ).val( '' ); 330 330 } 331 } 331 }, 332 332 ).fail( 333 333 function( xhr, msg ) { … … 340 340 msg += '. Please, take a screenshot of the output in the browser console, send it to the developers, and reload the page to see if it works.'; 341 341 $gp.notices.error( msg ); 342 } 342 }, 343 343 ); 344 344 } 345 345 346 346 function getReasonList( ) { 347 varcommentReasons = $gp_comment_feedback_settings.comment_reasons;348 varcommentList = '';349 varprefix = '';350 varsuffix = '';351 varinputName = '';347 const commentReasons = $gp_comment_feedback_settings.comment_reasons; 348 let commentList = ''; 349 let prefix = ''; 350 let suffix = ''; 351 let inputName = ''; 352 352 353 353 // eslint-disable-next-line vars-on-top 354 for ( varreason in commentReasons ) {354 for ( const reason in commentReasons ) { 355 355 prefix = '<div class="modal-item"><label>'; 356 356 suffix = '<span class="tooltip dashicons dashicons-info" title="' + commentReasons[ reason ].explanation + '"></span></label></div>'; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/translation-helpers.js
r11992 r12656 3 3 function( $ ) { 4 4 return { 5 init : function( table, fetchNow ) {5 init( table, fetchNow ) { 6 6 $gp.translation_helpers.table = table; 7 7 $gp.translation_helpers.install_hooks(); … … 10 10 } 11 11 }, 12 install_hooks : function() {12 install_hooks() { 13 13 $( $gp.translation_helpers.table ) 14 14 .on( 'beforeShow', '.editor', $gp.translation_helpers.hooks.initial_fetch ) … … 17 17 .on( 'click', 'a.opt-out-discussion,a.opt-in-discussion', $gp.translation_helpers.hooks.optin_optout_discussion ); 18 18 }, 19 initial_fetch : function( $element ) {20 var$helpers = $element.find( '.translation-helpers' );19 initial_fetch( $element ) { 20 const $helpers = $element.find( '.translation-helpers' ); 21 21 22 22 if ( $helpers.hasClass( 'loaded' ) || $helpers.hasClass( 'loading' ) ) { … … 26 26 $gp.translation_helpers.fetch( false, $element ); 27 27 }, 28 fetch : function( which, $element ) {29 var$helpers;28 fetch( which, $element ) { 29 let $helpers; 30 30 if ( $element ) { 31 31 $helpers = $element.find( '.translation-helpers' ); … … 34 34 } 35 35 36 varoriginalId = $helpers.parent().attr( 'row' ); // eslint-disable-line vars-on-top37 varreplytocom = $helpers.parent().attr( 'replytocom' ); // eslint-disable-line vars-on-top36 const originalId = $helpers.parent().attr( 'row' ); // eslint-disable-line vars-on-top 37 const replytocom = $helpers.parent().attr( 'replytocom' ); // eslint-disable-line vars-on-top 38 38 var requestUrl = $gp_translation_helpers_settings.th_url + originalId + '?nohc'; // eslint-disable-line 39 39 … … 61 61 } ); 62 62 $( '.helper-translation-discussion' ).find( 'form.comment-form' ).removeAttr( 'novalidate' ); 63 } 63 }, 64 64 ); 65 65 }, 66 tab_select : function( $tab ) {67 vartabId = $tab.attr( 'data-tab' );66 tab_select( $tab ) { 67 const tabId = $tab.attr( 'data-tab' ); 68 68 69 69 $tab.siblings().removeClass( 'current' ); … … 73 73 $( '#' + tabId ).addClass( 'current' ); 74 74 }, 75 reply_comment_form : function( $comment ) {76 varcommentId = $comment.attr( 'data-commentid' );75 reply_comment_form( $comment ) { 76 const commentId = $comment.attr( 'data-commentid' ); 77 77 $( '#comment-reply-' + commentId ).toggle().find( 'textarea' ).focus(); 78 78 if ( 'Reply' === $comment.text() ) { … … 82 82 } 83 83 }, 84 optin_optout_discussion : function( $link ) {85 vardata = {84 optin_optout_discussion( $link ) { 85 const data = { 86 86 action: 'optout_discussion_notifications', 87 87 data: { … … 95 95 type: 'POST', 96 96 url: $gp_translation_helpers_settings.ajax_url, 97 data : data,98 } 97 data, 98 }, 99 99 ).done( 100 100 function() { 101 101 $gp.translation_helpers.fetch( 'discussion' ); 102 } 102 }, 103 103 ); 104 104 }, 105 105 hooks: { 106 initial_fetch : function() {106 initial_fetch() { 107 107 $gp.translation_helpers.initial_fetch( $( this ) ); 108 108 return false; 109 109 }, 110 tab_select : function() {110 tab_select() { 111 111 $gp.translation_helpers.tab_select( $( this ) ); 112 112 return false; 113 113 }, 114 reply_comment_form : function( event ) {114 reply_comment_form( event ) { 115 115 event.preventDefault(); 116 116 $gp.translation_helpers.reply_comment_form( $( this ) ); 117 117 return false; 118 118 }, 119 optin_optout_discussion : function( event ) {119 optin_optout_discussion( event ) { 120 120 event.preventDefault(); 121 121 $gp.translation_helpers.optin_optout_discussion( $( this ) ); … … 128 128 129 129 jQuery( function( $ ) { 130 var_oldShow = $.fn.show;130 const _oldShow = $.fn.show; 131 131 $gp.translation_helpers.init( $( '.translations' ), true ); 132 132 if ( typeof window.newShowFunctionAttached === 'undefined' ) { … … 134 134 $.fn.show = function( speed, oldCallback ) { 135 135 return $( this ).each( function() { 136 varobj = $( this ),136 const obj = $( this ), 137 137 newCallback = function() { 138 138 if ( $.isFunction( oldCallback ) ) { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/templates/translation-row-editor-meta-feedback.php
r12624 r12656 5 5 if ( 'waiting' === $translation->translation_status || 'fuzzy' === $translation->translation_status ) : 6 6 ?> 7 <div> 8 <div class="openai-review"> 9 <p class="suggestions__loading-indicator">ChatGPT review in progress <span aria-hidden="true" class="suggestions__loading-indicator__icon"><span></span><span></span><span></span></span></p> 10 <div class="auto-review-result"></div> 7 <details open> 8 <summary class="chatgpt-summary"><?php esc_html_e( 'ChatGPT Review', 'glotpress' ); ?></summary> 9 <div> 10 <div class="openai-review"> 11 <p class="suggestions__loading-indicator">ChatGPT review in progress <span aria-hidden="true" class="suggestions__loading-indicator__icon"><span></span><span></span><span></span></span></p> 12 <div class="auto-review-result"></div> 13 </div> 11 14 </div> 12 </d iv>15 </details> 13 16 <?php endif; ?> 14 17 <details open>
Note: See TracChangeset
for help on using the changeset viewer.