| 1 |
/* global metasyncOttoDebugData, jQuery, ajaxurl */ |
| 2 |
/** |
| 3 |
* MetaSync OTTO Debug Panel |
| 4 |
* |
| 5 |
* Extracted for Phase 5, #887. |
| 6 |
* Debug tools: API test, notification test, cache clear, crawl simulation, |
| 7 |
* URL testing, OTTO change emulation, simple AJAX test, DB permissions test. |
| 8 |
* |
| 9 |
* Localized object: metasyncOttoDebugData |
| 10 |
* - nonce (string) |
| 11 |
* |
| 12 |
* @since Phase 5 |
| 13 |
*/ |
| 14 |
jQuery(document).ready(function ($) { |
| 15 |
var nonce = metasyncOttoDebugData.nonce; |
| 16 |
|
| 17 |
// Test API connectivity |
| 18 |
$('#test-otto-api').on('click', function () { |
| 19 |
var button = $(this); |
| 20 |
button.prop('disabled', true).text('Testing...'); |
| 21 |
|
| 22 |
$.post(ajaxurl, { |
| 23 |
action: 'metasync_otto_debug_test_api', |
| 24 |
nonce: nonce |
| 25 |
}, function (response) { |
| 26 |
$('#api-test-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 27 |
button.prop('disabled', false).text('Test API Connectivity'); |
| 28 |
}); |
| 29 |
}); |
| 30 |
|
| 31 |
// Test notification endpoint |
| 32 |
$('#test-notification-endpoint').on('click', function () { |
| 33 |
var button = $(this); |
| 34 |
button.prop('disabled', true).text('Testing...'); |
| 35 |
|
| 36 |
$.post(ajaxurl, { |
| 37 |
action: 'metasync_otto_debug_test_notification', |
| 38 |
nonce: nonce |
| 39 |
}, function (response) { |
| 40 |
$('#notification-test-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 41 |
button.prop('disabled', false).text('Test Notification Endpoint'); |
| 42 |
}); |
| 43 |
}); |
| 44 |
|
| 45 |
// Clear OTTO cache |
| 46 |
$('#clear-otto-cache').on('click', function () { |
| 47 |
if (!confirm('Are you sure you want to clear all OTTO cache data?')) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
var button = $(this); |
| 52 |
button.prop('disabled', true).text('Clearing...'); |
| 53 |
|
| 54 |
$.post(ajaxurl, { |
| 55 |
action: 'metasync_otto_debug_clear_cache', |
| 56 |
nonce: nonce |
| 57 |
}, function (response) { |
| 58 |
$('#cache-clear-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 59 |
button.prop('disabled', false).text('Clear OTTO Cache'); |
| 60 |
}); |
| 61 |
}); |
| 62 |
|
| 63 |
// Simulate crawl notification |
| 64 |
$('#simulate-crawl').on('click', function () { |
| 65 |
var button = $(this); |
| 66 |
button.prop('disabled', true).text('Simulating...'); |
| 67 |
|
| 68 |
$.post(ajaxurl, { |
| 69 |
action: 'metasync_otto_debug_simulate_crawl', |
| 70 |
nonce: nonce |
| 71 |
}, function (response) { |
| 72 |
$('#crawl-simulate-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 73 |
button.prop('disabled', false).text('Simulate Crawl Notification'); |
| 74 |
}); |
| 75 |
}); |
| 76 |
|
| 77 |
// Test specific URL |
| 78 |
$('#test-specific-url').on('click', function () { |
| 79 |
var button = $(this); |
| 80 |
var testUrl = $('#test-url-input').val(); |
| 81 |
|
| 82 |
if (!testUrl) { |
| 83 |
alert('Please enter a URL to test'); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
button.prop('disabled', true).text('Testing...'); |
| 88 |
|
| 89 |
console.log('Testing URL:', testUrl); |
| 90 |
|
| 91 |
$.post(ajaxurl, { |
| 92 |
action: 'metasync_otto_debug_test_url', |
| 93 |
nonce: nonce, |
| 94 |
test_url: testUrl |
| 95 |
}, function (response) { |
| 96 |
console.log('URL Test Response:', response); |
| 97 |
$('#url-test-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 98 |
button.prop('disabled', false).text('Test URL & Check All Points'); |
| 99 |
}).fail(function (xhr, status, error) { |
| 100 |
console.error('URL Test Error:', error, xhr.responseText); |
| 101 |
$('#url-test-results').empty().append($('<div class="error">').text('Error: ' + error + '\nResponse: ' + xhr.responseText)).show(); |
| 102 |
button.prop('disabled', false).text('Test URL & Check All Points'); |
| 103 |
}); |
| 104 |
}); |
| 105 |
|
| 106 |
// Emulate OTTO changes |
| 107 |
$('#emulate-otto-changes').on('click', function () { |
| 108 |
var button = $(this); |
| 109 |
var testUrl = $('#test-url-input').val(); |
| 110 |
|
| 111 |
if (!testUrl) { |
| 112 |
alert('Please enter a URL to test'); |
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
button.prop('disabled', true).text('Emulating...'); |
| 117 |
|
| 118 |
console.log('Emulating OTTO changes for URL:', testUrl); |
| 119 |
|
| 120 |
$.post(ajaxurl, { |
| 121 |
action: 'metasync_otto_debug_emulate_changes', |
| 122 |
nonce: nonce, |
| 123 |
test_url: testUrl |
| 124 |
}, function (response) { |
| 125 |
console.log('Emulation Response:', response); |
| 126 |
$('#emulation-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 127 |
button.prop('disabled', false).text('Emulate OTTO Changes'); |
| 128 |
}).fail(function (xhr, status, error) { |
| 129 |
console.error('Emulation Error:', error, xhr.responseText); |
| 130 |
$('#emulation-results').empty().append($('<div class="error">').text('Error: ' + error + '\nResponse: ' + xhr.responseText)).show(); |
| 131 |
button.prop('disabled', false).text('Emulate OTTO Changes'); |
| 132 |
}); |
| 133 |
}); |
| 134 |
|
| 135 |
// Simple AJAX test |
| 136 |
$('#simple-ajax-test').on('click', function () { |
| 137 |
var button = $(this); |
| 138 |
button.prop('disabled', true).text('Testing...'); |
| 139 |
|
| 140 |
console.log('Testing basic AJAX connection'); |
| 141 |
|
| 142 |
$.post(ajaxurl, { |
| 143 |
action: 'metasync_otto_debug_simple_test', |
| 144 |
nonce: nonce |
| 145 |
}, function (response) { |
| 146 |
console.log('Simple Test Response:', response); |
| 147 |
$('#url-test-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 148 |
button.prop('disabled', false).text('Test AJAX Connection'); |
| 149 |
}).fail(function (xhr, status, error) { |
| 150 |
console.error('Simple Test Error:', error, xhr.responseText); |
| 151 |
$('#url-test-results').empty().append($('<div class="error">').text('AJAX Error: ' + error + '\nResponse: ' + xhr.responseText)).show(); |
| 152 |
button.prop('disabled', false).text('Test AJAX Connection'); |
| 153 |
}); |
| 154 |
}); |
| 155 |
|
| 156 |
// Test database permissions |
| 157 |
$('#test-db-permissions').on('click', function () { |
| 158 |
var button = $(this); |
| 159 |
button.prop('disabled', true).text('Testing...'); |
| 160 |
|
| 161 |
console.log('Testing database permissions'); |
| 162 |
|
| 163 |
$.post(ajaxurl, { |
| 164 |
action: 'metasync_otto_debug_test_db_permissions', |
| 165 |
nonce: nonce |
| 166 |
}, function (response) { |
| 167 |
console.log('DB Permissions Response:', response); |
| 168 |
$('#db-permissions-results').empty().append($('<div class="json-output">').text(JSON.stringify(response, null, 2))).show(); |
| 169 |
button.prop('disabled', false).text('Test Database Permissions'); |
| 170 |
}).fail(function (xhr, status, error) { |
| 171 |
console.error('DB Permissions Error:', error, xhr.responseText); |
| 172 |
$('#db-permissions-results').empty().append($('<div class="error">').text('Error: ' + error + '\nResponse: ' + xhr.responseText)).show(); |
| 173 |
button.prop('disabled', false).text('Test Database Permissions'); |
| 174 |
}); |
| 175 |
}); |
| 176 |
}); |
| 177 |
|