You've already forked wp-prometheus
Initial plugin setup (v0.0.1)
Some checks failed
Create Release Package / build-release (push) Failing after 48s
Some checks failed
Create Release Package / build-release (push) Failing after 48s
- Create initial WordPress plugin structure - Add Prometheus metrics collector with default metrics - Implement authenticated /metrics endpoint with Bearer token - Add license management integration - Create admin settings page under Settings > Metrics - Set up Gitea CI/CD pipeline for automated releases - Add extensibility via wp_prometheus_collect_metrics hook Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
100
assets/js/admin.js
Normal file
100
assets/js/admin.js
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* WP Prometheus Admin JavaScript
|
||||
*
|
||||
* @package WP_Prometheus
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
// Validate license button.
|
||||
$('#wp-prometheus-validate-license').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
performLicenseAction('wp_prometheus_validate_license', 'Validating...');
|
||||
});
|
||||
|
||||
// Activate license button.
|
||||
$('#wp-prometheus-activate-license').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
performLicenseAction('wp_prometheus_activate_license', 'Activating...');
|
||||
});
|
||||
|
||||
// Regenerate token button.
|
||||
$('#wp-prometheus-regenerate-token').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
if (confirm('Are you sure you want to regenerate the auth token? You will need to update your Prometheus configuration.')) {
|
||||
var newToken = generateToken(32);
|
||||
$('#wp_prometheus_auth_token').val(newToken);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Perform a license action via AJAX.
|
||||
*
|
||||
* @param {string} action AJAX action name.
|
||||
* @param {string} message Loading message.
|
||||
*/
|
||||
function performLicenseAction(action, message) {
|
||||
var $spinner = $('#wp-prometheus-license-spinner');
|
||||
var $message = $('#wp-prometheus-license-message');
|
||||
|
||||
$spinner.addClass('is-active');
|
||||
$message.hide();
|
||||
|
||||
$.ajax({
|
||||
url: wpPrometheus.ajaxUrl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: action,
|
||||
nonce: wpPrometheus.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
$spinner.removeClass('is-active');
|
||||
|
||||
if (response.success) {
|
||||
$message
|
||||
.removeClass('notice-error')
|
||||
.addClass('notice notice-success')
|
||||
.html('<p>' + response.data.message + '</p>')
|
||||
.show();
|
||||
|
||||
// Reload page after successful validation/activation.
|
||||
setTimeout(function() {
|
||||
location.reload();
|
||||
}, 1500);
|
||||
} else {
|
||||
$message
|
||||
.removeClass('notice-success')
|
||||
.addClass('notice notice-error')
|
||||
.html('<p>' + (response.data.message || 'An error occurred.') + '</p>')
|
||||
.show();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$spinner.removeClass('is-active');
|
||||
$message
|
||||
.removeClass('notice-success')
|
||||
.addClass('notice notice-error')
|
||||
.html('<p>Connection error. Please try again.</p>')
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random token.
|
||||
*
|
||||
* @param {number} length Token length.
|
||||
* @return {string} Generated token.
|
||||
*/
|
||||
function generateToken(length) {
|
||||
var charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
var token = '';
|
||||
for (var i = 0; i < length; i++) {
|
||||
token += charset.charAt(Math.floor(Math.random() * charset.length));
|
||||
}
|
||||
return token;
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user