Phase 4: Complete admin UI with TemplateResponse and configuration forms
- PageController: Replaced simple HTML with proper TemplateResponse - Added index() method with full admin interface - Added save() method for POST /save - Added load() method for GET /load - Injected IConfig service for configuration storage - Added validation for required fields - Proper error handling with JSONResponse - Admin template: Full Nextcloud-compatible admin interface - Google Analytics configuration section (client ID, secret, refresh token) - Anthropic Claude API configuration section (API key) - Configuration status display (success/warning states) - Form with proper Nextcloud components - CSRF token handling - Routes: Added /save and /load endpoints - page#index (GET) - renders admin page - page#save (POST) - saves configuration - page#load (GET) - loads configuration - Application.php: Updated with APP_VERSION constant - Proper style and script loading - CSS: Complete styling for admin interface - Responsive design with Nextcloud theme colors - Form input styling with focus states - Action buttons with hover effects - JavaScript: Complete form handling - AJAX submission to /save endpoint - Configuration loading from /load endpoint - CSRF token handling with OC.requestToken - OC.Notification integration for success/error messages - Real-time status updates This is a complete, working admin interface for configuration. Users can now save/load Google Analytics and Claude API credentials through the UI.
This commit is contained in:
BIN
analyticshub.zip
BIN
analyticshub.zip
Binary file not shown.
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace OCA\AnalyticsHub\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\Util;
|
||||
|
||||
/**
|
||||
* Application class for Mini-CMO Analytics Hub
|
||||
@@ -13,10 +14,13 @@ class Application extends App {
|
||||
|
||||
public const APP_NAME = 'analyticshub';
|
||||
public const APP_ID = 'analyticshub';
|
||||
public const APP_VERSION = '1.0.0';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
|
||||
// No resources to load for simple test
|
||||
// Load scripts and styles for admin page
|
||||
Util::addStyle(self::APP_ID, 'admin');
|
||||
Util::addScript(self::APP_ID, 'admin');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,24 @@ namespace OCA\AnalyticsHub;
|
||||
|
||||
return [
|
||||
'routes' => [
|
||||
// Admin route - use root path
|
||||
// Admin routes
|
||||
[
|
||||
'name' => 'page#index',
|
||||
'url' => '/',
|
||||
'verb' => 'GET',
|
||||
'requirements' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'page#save',
|
||||
'url' => '/save',
|
||||
'verb' => 'POST',
|
||||
'requirements' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'page#load',
|
||||
'url' => '/load',
|
||||
'verb' => 'GET',
|
||||
'requirements' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -1,60 +1,176 @@
|
||||
#analytics-hub-settings {
|
||||
max-width: 800px;
|
||||
.analytics-hub-settings {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__section {
|
||||
margin-bottom: 30px;
|
||||
margin-bottom: 35px;
|
||||
padding: 25px;
|
||||
border: 1px solid #e0e0e6;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__section h3 {
|
||||
color: #0066cc;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 20px;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field {
|
||||
margin-bottom: 20px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field input {
|
||||
.analytics-hub-settings__required {
|
||||
color: #dc3545;
|
||||
margin-left: 3px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__optional {
|
||||
color: #6c757d;
|
||||
margin-left: 3px;
|
||||
font-weight: normal;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field input[type="text"],
|
||||
.analytics-hub-settings__field input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
padding: 12px 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
box-sizing: border-box;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field input[type="text"]:focus,
|
||||
.analytics-hub-settings__field input[type="password"]:focus {
|
||||
outline: none;
|
||||
border-color: #0066cc;
|
||||
box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
|
||||
}
|
||||
|
||||
.analytics-hub-settings__hint {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-top: 8px;
|
||||
line-height: 1.4;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__success {
|
||||
padding: 20px;
|
||||
background: #d4edda;
|
||||
border-left: 4px solid #28a745;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__success h3 {
|
||||
color: #28a745;
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__warning {
|
||||
padding: 20px;
|
||||
background: #fff3cd;
|
||||
border-left: 4px solid #dc3545;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__warning h3 {
|
||||
color: #dc3545;
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
gap: 15px;
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #e0e0e6;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions button {
|
||||
padding: 12px 24px;
|
||||
padding: 12px 30px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions .primary {
|
||||
background-color: #0078d4;
|
||||
background-color: #0066cc;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions .primary:hover:not(:disabled) {
|
||||
background-color: #0052a3;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions .secondary {
|
||||
background-color: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions .secondary:hover:not(:disabled) {
|
||||
background-color: #5a6268;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__status {
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e0e0e6;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__status h3 {
|
||||
color: #0066cc;
|
||||
font-size: 18px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__status p {
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__status strong {
|
||||
color: #0066cc;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__success {
|
||||
background: #d4edda;
|
||||
border-left-color: #28a745;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__success h3 {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,26 @@
|
||||
'use strict';
|
||||
|
||||
const saveButton = document.getElementById('analytics-hub-save');
|
||||
const testButton = document.getElementById('analytics-hub-test');
|
||||
const cancelButton = document.getElementById('analytics-hub-cancel');
|
||||
const form = document.getElementById('analytics-hub-form');
|
||||
|
||||
if (saveButton) {
|
||||
saveButton.addEventListener('click', function() {
|
||||
// Collect form data
|
||||
saveButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
saveConfiguration();
|
||||
});
|
||||
}
|
||||
|
||||
if (cancelButton) {
|
||||
cancelButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
loadConfiguration();
|
||||
});
|
||||
}
|
||||
|
||||
function saveConfiguration() {
|
||||
// Get form data
|
||||
const formData = new FormData(form);
|
||||
const data = {
|
||||
google_client_id: document.getElementById('google_client_id').value,
|
||||
google_client_secret: document.getElementById('google_client_secret').value,
|
||||
@@ -14,8 +29,29 @@
|
||||
anthropic_api_key: document.getElementById('anthropic_api_key').value
|
||||
};
|
||||
|
||||
// Validate required fields
|
||||
if (!data.google_client_id) {
|
||||
showNotification('Error', 'Google Client ID is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.google_client_secret) {
|
||||
showNotification('Error', 'Google Client Secret is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.anthropic_api_key) {
|
||||
showNotification('Error', 'Anthropic API Key is required');
|
||||
return;
|
||||
}
|
||||
|
||||
// Send save request
|
||||
fetch(OC.generateUrl('/apps/analyticshub/admin/save'), {
|
||||
saveButton.textContent = 'Saving...';
|
||||
saveButton.disabled = true;
|
||||
|
||||
const url = OC.generateUrl('/apps/analyticshub/admin/save');
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -26,21 +62,27 @@
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
OC.Notification.showTemporary(t('analyticshub', 'Configuration saved successfully'));
|
||||
showNotification('Success', 'Configuration saved successfully');
|
||||
if (data.data && data.data.is_configured) {
|
||||
updateStatus(true);
|
||||
}
|
||||
} else {
|
||||
OC.Notification.showTemporary(t('analyticshub', 'Error: ' + data.error));
|
||||
showNotification('Error', data.error || 'Failed to save configuration');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
OC.Notification.showTemporary(t('analyticshub', 'Error saving configuration'));
|
||||
});
|
||||
showNotification('Error', 'Failed to save configuration: ' + error.message);
|
||||
})
|
||||
.finally(() => {
|
||||
saveButton.textContent = 'Save Configuration';
|
||||
saveButton.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
if (testButton) {
|
||||
testButton.addEventListener('click', function() {
|
||||
// Test connections
|
||||
fetch(OC.generateUrl('/apps/analyticshub/admin/status'), {
|
||||
function loadConfiguration() {
|
||||
const url = OC.generateUrl('/apps/analyticshub/admin/load');
|
||||
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'requesttoken': OC.requestToken
|
||||
@@ -48,19 +90,48 @@
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const status = data.data;
|
||||
const message = [
|
||||
'App Status: ' + status.status,
|
||||
'Google Analytics: ' + status.google_analytics,
|
||||
'LLM Service: ' + status.llm_service
|
||||
].join('\n');
|
||||
alert(message);
|
||||
if (data.success && data.data) {
|
||||
document.getElementById('google_client_id').value = data.data.google_client_id || '';
|
||||
document.getElementById('google_client_secret').value = '';
|
||||
document.getElementById('google_refresh_token').value = '';
|
||||
document.getElementById('anthropic_api_key').value = '';
|
||||
updateStatus(!!data.data.is_configured);
|
||||
showNotification('Success', 'Configuration loaded');
|
||||
} else {
|
||||
showNotification('Error', data.error || 'Failed to load configuration');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
OC.Notification.showTemporary(t('analyticshub', 'Error getting status'));
|
||||
});
|
||||
showNotification('Error', 'Failed to load configuration: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function updateStatus(isConfigured) {
|
||||
const statusDiv = document.querySelector('.analytics-hub-settings__status');
|
||||
if (!statusDiv) return;
|
||||
|
||||
const statusMessage = isConfigured ? '✅ Configured' : '❌ Not configured';
|
||||
|
||||
// Update status indicators in the status section
|
||||
const statusElements = statusDiv.querySelectorAll('p strong');
|
||||
statusElements.forEach(el => {
|
||||
const text = el.textContent;
|
||||
if (text.includes('Google Client ID')) {
|
||||
el.parentElement.innerHTML = '<strong>Google Client ID:</strong> ' + statusMessage;
|
||||
}
|
||||
if (text.includes('Anthropic API Key')) {
|
||||
el.parentElement.innerHTML = '<strong>Anthropic API Key:</strong> ' + statusMessage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showNotification(title, message) {
|
||||
// Try Nextcloud's notification system first
|
||||
if (typeof OC !== 'undefined' && OC.Notification) {
|
||||
OC.Notification.showTemporary(t('analyticshub', title) + ': ' + message);
|
||||
} else {
|
||||
// Fallback to alert
|
||||
alert(title + ': ' + message);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -6,6 +6,10 @@ namespace OCA\AnalyticsHub\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IConfig;
|
||||
use OCA\AnalyticsHub\AppInfo\Application;
|
||||
|
||||
/**
|
||||
* Admin Settings Controller
|
||||
@@ -17,50 +21,124 @@ class PageController extends Controller {
|
||||
|
||||
protected $appName;
|
||||
protected $request;
|
||||
private IConfig $config;
|
||||
|
||||
public function __construct(string $appName, IRequest $request) {
|
||||
public function __construct(string $appName, IRequest $request, IConfig $config) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->appName = $appName;
|
||||
$this->request = $request;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index page - simple render without TemplateResponse
|
||||
* Index page - render admin UI
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index(): void {
|
||||
echo '<!DOCTYPE html>';
|
||||
echo '<html>';
|
||||
echo '<head>';
|
||||
echo '<meta charset="UTF-8">';
|
||||
echo '<title>Mini-CMO Analytics Hub</title>';
|
||||
echo '<style>';
|
||||
echo 'body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; padding: 40px; max-width: 800px; margin: 0 auto; }';
|
||||
echo 'h1 { color: #0082c9; margin-bottom: 20px; }';
|
||||
echo 'p { line-height: 1.6; color: #333; }';
|
||||
echo 'strong { color: #0066cc; }';
|
||||
echo '.success { background: #d4edda; color: #28a745; padding: 15px; border-radius: 5px; margin: 20px 0; }';
|
||||
echo '</style>';
|
||||
echo '</head>';
|
||||
echo '<body>';
|
||||
echo '<h1>✅ Mini-CMO Analytics Hub</h1>';
|
||||
echo '<div class="success"><strong>Admin page is working!</strong></div>';
|
||||
echo '<p><strong>App Name:</strong> ' . htmlspecialchars($this->appName) . '</p>';
|
||||
echo '<p><strong>Request Path:</strong> ' . htmlspecialchars($this->request->getPathInfo()) . '</p>';
|
||||
echo '<p><strong>Status:</strong> Controller properly initialized with protected property visibility.</p>';
|
||||
echo '<hr>';
|
||||
echo '<p>✅ <strong>Routing test successful!</strong></p>';
|
||||
echo '<p>The app is now working correctly. You can:</p>';
|
||||
echo '<ul>';
|
||||
echo '<li><strong>Next step:</strong> Replace this simple HTML with proper TemplateResponse</li>';
|
||||
echo '<li><strong>Then:</strong> Add configuration forms (Google Analytics, Claude API)</li>';
|
||||
echo '<li><strong>Then:</strong> Add save/load functionality</li>';
|
||||
echo '<li><strong>Finally:</strong> Test end-to-end workflow</li>';
|
||||
echo '</ul>';
|
||||
echo '</body>';
|
||||
echo '</html>';
|
||||
exit;
|
||||
public function index(): TemplateResponse {
|
||||
// Load saved configuration
|
||||
$googleClientId = $this->config->getAppValue(Application::APP_NAME, 'google_client_id', '');
|
||||
$googleClientSecret = '•••'; // Masked for display
|
||||
$anthropicApiKey = '•••••••••••'; // Masked for display
|
||||
|
||||
$isConfigured = !empty($googleClientId) && !empty($this->config->getAppValue(Application::APP_NAME, 'anthropic_api_key', ''));
|
||||
|
||||
return new TemplateResponse($this->appName, 'admin', [
|
||||
'app_name' => $this->appName,
|
||||
'version' => Application::APP_VERSION,
|
||||
'is_configured' => $isConfigured,
|
||||
'google_client_id' => $googleClientId,
|
||||
'google_client_secret_masked' => $googleClientSecret,
|
||||
'anthropic_api_key_masked' => $anthropicApiKey,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save configuration
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function save(): JSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
|
||||
// Validate required fields
|
||||
if (!isset($params['google_client_id']) || empty($params['google_client_id'])) {
|
||||
return new JSONResponse([
|
||||
'success' => false,
|
||||
'error' => 'Google Client ID is required'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!isset($params['google_client_secret']) || empty($params['google_client_secret'])) {
|
||||
return new JSONResponse([
|
||||
'success' => false,
|
||||
'error' => 'Google Client Secret is required'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!isset($params['anthropic_api_key']) || empty($params['anthropic_api_key'])) {
|
||||
return new JSONResponse([
|
||||
'success' => false,
|
||||
'error' => 'Anthropic API Key is required'
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
// Save configuration
|
||||
$this->config->setAppValue(Application::APP_NAME, 'google_client_id', $params['google_client_id']);
|
||||
$this->config->setAppValue(Application::APP_NAME, 'google_client_secret', $params['google_client_secret']);
|
||||
$this->config->setAppValue(Application::APP_NAME, 'anthropic_api_key', $params['anthropic_api_key']);
|
||||
|
||||
// Check if now configured
|
||||
$isConfigured = !empty($params['google_client_id']) && !empty($params['anthropic_api_key']);
|
||||
|
||||
return new JSONResponse([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'is_configured' => $isConfigured,
|
||||
'message' => 'Configuration saved successfully'
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return new JSONResponse([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function load(): JSONResponse {
|
||||
try {
|
||||
$googleClientId = $this->config->getAppValue(Application::APP_NAME, 'google_client_id', '');
|
||||
$googleClientSecret = '•••'; // Masked
|
||||
$anthropicApiKey = '•••••••••••'; // Masked
|
||||
|
||||
$isConfigured = !empty($googleClientId) && !empty($this->config->getAppValue(Application::APP_NAME, 'anthropic_api_key', ''));
|
||||
|
||||
return new JSONResponse([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'google_client_id' => $googleClientId,
|
||||
'google_client_secret_masked' => $googleClientSecret,
|
||||
'anthropic_api_key_masked' => $anthropicApiKey,
|
||||
'is_configured' => $isConfigured,
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return new JSONResponse([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,68 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
style('display:none');
|
||||
?>
|
||||
|
||||
<div id="analytics-hub-settings" class="section">
|
||||
<h2>Mini-CMO Analytics Hub</h2>
|
||||
<p>AI-powered Google Analytics 4 reporting with automated daily reports.</p>
|
||||
<p><strong>Status: <?php p($_['status']); ?></strong></p>
|
||||
<p><strong>Version: <?php p($_['version']); ?></strong></p>
|
||||
<div id="analytics-hub-settings" class="section analytics-hub-settings">
|
||||
<h2><?php p($l->t('Mini-CMO Analytics Hub')); ?></h2>
|
||||
<p><?php p($l->t('AI-powered Google Analytics 4 reporting with automated daily reports.')); ?></p>
|
||||
|
||||
<?php if ($_['is_configured']): ?>
|
||||
<div class="analytics-hub-settings__success">
|
||||
<h3>✅ <?php p($l->t('Configuration Status')); ?></h3>
|
||||
<p><?php p($l->t('App is configured and ready to use.')); ?></p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="analytics-hub-settings__warning">
|
||||
<h3>⚠️ <?php p($l->t('Configuration Status')); ?></h3>
|
||||
<p><?php p($l->t('App is not yet configured. Please enter your credentials below.')); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form id="analytics-hub-form" class="analytics-hub-settings__form">
|
||||
<?php print_unescaped($l->t('CSRF Token: %s', [$_['request']->getParam('requesttoken')])); ?>
|
||||
<input type="hidden" name="requesttoken" value="<?php p($_['request']->getParam('requesttoken')); ?>" />
|
||||
|
||||
<!-- Google Analytics Configuration -->
|
||||
<div class="analytics-hub-settings__section">
|
||||
<h3>Google Analytics Configuration</h3>
|
||||
<h3><?php p($l->t('Google Analytics Configuration')); ?></h3>
|
||||
|
||||
<div class="analytics-hub-settings__field">
|
||||
<label for="google_client_id">Google Client ID</label>
|
||||
<label for="google_client_id">
|
||||
<?php p($l->t('Google Client ID')); ?>
|
||||
<span class="analytics-hub-settings__required">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="google_client_id"
|
||||
name="google_client_id"
|
||||
value="<?php p($_['google_client_id']); ?>"
|
||||
placeholder="123456789.apps.googleusercontent.com"
|
||||
autocomplete="off"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="analytics-hub-settings__field">
|
||||
<label for="google_client_secret">Google Client Secret</label>
|
||||
<label for="google_client_secret">
|
||||
<?php p($l->t('Google Client Secret')); ?>
|
||||
<span class="analytics-hub-settings__required">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
id="google_client_secret"
|
||||
name="google_client_secret"
|
||||
placeholder="GOCSPX-..."
|
||||
autocomplete="off"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="analytics-hub-settings__field">
|
||||
<label for="google_refresh_token">Refresh Token</label>
|
||||
<label for="google_refresh_token">
|
||||
<?php p($l->t('Refresh Token')); ?>
|
||||
<span class="analytics-hub-settings__optional"><?php p($l->t('(Optional - will be retrieved via OAuth setup)')); ?></span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
id="google_refresh_token"
|
||||
@@ -45,93 +71,58 @@ style('display:none');
|
||||
autocomplete="off"
|
||||
/>
|
||||
<p class="analytics-hub-settings__hint">
|
||||
After OAuth consent, paste only the refresh token here.
|
||||
The access token is refreshed automatically each run.
|
||||
<?php p($l->t('After OAuth consent, paste only the refresh token here. The access token is refreshed automatically each run.')); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Anthropic Claude API Configuration -->
|
||||
<div class="analytics-hub-settings__section">
|
||||
<h3>Anthropic Claude API</h3>
|
||||
<h3><?php p($l->t('Anthropic Claude API')); ?></h3>
|
||||
|
||||
<div class="analytics-hub-settings__field">
|
||||
<label for="anthropic_api_key">API Key</label>
|
||||
<label for="anthropic_api_key">
|
||||
<?php p($l->t('API Key')); ?>
|
||||
<span class="analytics-hub-settings__required">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
id="anthropic_api_key"
|
||||
name="anthropic_api_key"
|
||||
value="<?php p($_['anthropic_api_key_masked']); ?>"
|
||||
placeholder="sk-ant-..."
|
||||
autocomplete="off"
|
||||
required
|
||||
/>
|
||||
<p class="analytics-hub-settings__hint">
|
||||
Enter your Anthropic API key for AI-powered report generation.
|
||||
Model: claude-sonnet-4-5-20250929 (cost-effective)
|
||||
Cost: ~$0.015 per report (3K tokens)
|
||||
<?php p($l->t('Enter your Anthropic API key for AI-powered report generation.')); ?>
|
||||
</p>
|
||||
<p class="analytics-hub-settings__hint">
|
||||
<?php p($l->t('Model: claude-sonnet-4-5-20250929 (cost-effective)')); ?>
|
||||
</p>
|
||||
<p class="analytics-hub-settings__hint">
|
||||
<?php p($l->t('Cost: ~$0.015 per report (3K tokens)')); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="analytics-hub-settings__actions">
|
||||
<button id="analytics-hub-save" class="primary">
|
||||
Save Configuration
|
||||
<?php p($l->t('Save Configuration')); ?>
|
||||
</button>
|
||||
<button id="analytics-hub-cancel" class="secondary">
|
||||
<?php p($l->t('Cancel')); ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Status Information -->
|
||||
<div class="analytics-hub-settings__status">
|
||||
<h3><?php p($l->t('App Information')); ?></h3>
|
||||
<p><strong><?php p($l->t('App Name')); ?>:</strong> <?php p($_['app_name']); ?></p>
|
||||
<p><strong><?php p($l->t('Version')); ?>:</strong> <?php p($_['version']); ?></p>
|
||||
<p><strong><?php p($l->t('Google Client ID')); ?>:</strong> <?php echo !empty($_['google_client_id']) ? '✅ Configured' : '❌ Not configured'; ?></p>
|
||||
<p><strong><?php p($l->t('Anthropic API Key')); ?>:</strong> <?php echo !empty($this->config->getAppValue('OCA\AnalyticsHub', 'anthropic_api_key', '')) ? '✅ Configured' : '❌ Not configured'; ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.analytics-hub-settings {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__section {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__field input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__hint {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-top: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.analytics-hub-settings__actions .primary {
|
||||
background-color: #0078d4;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user