diff --git a/client/index.html b/client/index.html index fa54957..4489c1e 100644 --- a/client/index.html +++ b/client/index.html @@ -46,7 +46,7 @@ diff --git a/client/js/api.js b/client/js/api.js index 7c8cf6d..0b3c2a5 100644 --- a/client/js/api.js +++ b/client/js/api.js @@ -11,9 +11,11 @@ class ApiClient { } getHeaders(includeContentType = true) { - const headers = { - 'X-API-Key': this.apiKey - }; + const headers = {}; + + if (this.apiKey) { + headers['X-API-Key'] = this.apiKey; + } if (includeContentType) { headers['Content-Type'] = 'application/json'; @@ -25,8 +27,8 @@ class ApiClient { async makeRequest(method, endpoint, data = null, isFormData = false) { this.updateConfig(); - if (!this.baseUrl || !this.apiKey) { - throw new Error('API not configured. Please set API base URL and key.'); + if (!this.baseUrl) { + throw new Error('API not configured. Please set API base URL.'); } const url = `${this.baseUrl}/api/v1${endpoint}`; diff --git a/client/js/app.js b/client/js/app.js index 3231d7e..3c80470 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -9,6 +9,7 @@ const app = { // Initialize the application document.addEventListener('DOMContentLoaded', () => { + console.log('App.js DOMContentLoaded fired'); console.log('SeReact Frontend v' + app.version + ' - Initializing...'); // Initialize configuration @@ -184,7 +185,7 @@ function handleRouteChange() { const route = hash || 'home'; // Validate route - const validRoutes = ['home', 'config', 'images', 'search', 'teams', 'users', 'api-keys']; + const validRoutes = ['home', 'config', 'images', 'search', 'teams', 'users', 'apiKeys']; if (validRoutes.includes(route)) { showPage(route); @@ -248,7 +249,7 @@ function setupKeyboardShortcuts() { // Number shortcuts for navigation if (e.key >= '1' && e.key <= '6' && !e.ctrlKey && !e.metaKey && !e.altKey) { - const pages = ['home', 'images', 'search', 'teams', 'users', 'api-keys']; + const pages = ['home', 'images', 'search', 'teams', 'users', 'apiKeys']; const pageIndex = parseInt(e.key) - 1; if (pages[pageIndex]) { e.preventDefault(); @@ -279,7 +280,7 @@ function refreshCurrentPageData() { case 'users': loadUsers(); break; - case 'api-keys': + case 'apiKeys': loadApiKeys(); break; } diff --git a/client/js/config.js b/client/js/config.js index 9a76762..9aafb06 100644 --- a/client/js/config.js +++ b/client/js/config.js @@ -3,6 +3,11 @@ class Config { constructor() { this.apiBaseUrl = localStorage.getItem('apiBaseUrl') || 'http://localhost:8000'; this.apiKey = localStorage.getItem('apiKey') || ''; + + // Set default configuration if not already set + if (!localStorage.getItem('apiBaseUrl')) { + this.setApiBaseUrl('http://localhost:8000'); + } } setApiBaseUrl(url) { @@ -24,7 +29,7 @@ class Config { } isConfigured() { - return this.apiBaseUrl && this.apiKey; + return this.apiBaseUrl; // Only require base URL, make API key optional for now } clear() { @@ -82,11 +87,6 @@ async function testConnection() { return; } - if (!apiKey) { - showAlert('API Key is required', 'danger'); - return; - } - const testButton = document.querySelector('button[onclick="testConnection()"]'); const originalText = testButton.innerHTML; testButton.innerHTML = ' Testing...'; @@ -105,28 +105,34 @@ async function testConnection() { throw new Error(`Health check failed with status ${healthResponse.status}`); } - // Test API authentication - const authResponse = await fetch(`${apiBaseUrl}/api/v1/teams`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'X-API-Key': apiKey + // Test API authentication only if API key is provided + if (apiKey) { + const authResponse = await fetch(`${apiBaseUrl}/api/v1/teams`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': apiKey + } + }); + + if (authResponse.status === 401) { + throw new Error('Authentication failed - Invalid API key'); + } else if (authResponse.status === 403) { + throw new Error('Access forbidden - API key lacks permissions'); + } else if (!authResponse.ok) { + throw new Error(`API request failed with status ${authResponse.status}`); } - }); - - if (authResponse.status === 401) { - throw new Error('Authentication failed - Invalid API key'); - } else if (authResponse.status === 403) { - throw new Error('Access forbidden - API key lacks permissions'); - } else if (!authResponse.ok) { - throw new Error(`API request failed with status ${authResponse.status}`); + + showAlert('API connection successful! Backend is up and running with authentication.', 'success'); + } else { + showAlert('API connection successful! Backend is up and running (no authentication tested).', 'success'); } - - showAlert('API connection successful! Backend is up and running.', 'success'); // Save the working configuration config.setApiBaseUrl(apiBaseUrl); - config.setApiKey(apiKey); + if (apiKey) { + config.setApiKey(apiKey); + } // Update form values document.getElementById('apiBaseUrl').value = apiBaseUrl; diff --git a/client/js/teams.js b/client/js/teams.js index 157ae2e..9d09025 100644 --- a/client/js/teams.js +++ b/client/js/teams.js @@ -2,6 +2,11 @@ // Load teams async function loadTeams() { + console.log('loadTeams called'); + console.log('Config check:', config.isConfigured()); + console.log('API Base URL:', config.getApiBaseUrl()); + console.log('API Key:', config.getApiKey() ? 'Set' : 'Not set'); + if (!config.isConfigured()) { showAlert('Please configure your API settings first.', 'warning'); return; @@ -11,11 +16,15 @@ async function loadTeams() { container.innerHTML = '
Loading teams...
'; try { + console.log('Making API request to get teams...'); const response = await apiClient.getTeams(); + console.log('API response:', response); // Handle structured response - extract teams array from response object const teams = response.teams || response; + console.log('Teams data:', teams); displayTeams(teams); } catch (error) { + console.error('Error loading teams:', error); handleApiError(error, 'loading teams'); container.innerHTML = '
Failed to load teams
'; } diff --git a/client/js/ui.js b/client/js/ui.js index 1a4b80a..19b6264 100644 --- a/client/js/ui.js +++ b/client/js/ui.js @@ -2,14 +2,18 @@ // Page navigation function showPage(pageId) { + console.log('showPage called with pageId:', pageId); + // Hide all pages const pages = document.querySelectorAll('.page'); + console.log('Found pages:', pages.length); pages.forEach(page => { page.style.display = 'none'; }); // Show the selected page const targetPage = document.getElementById(pageId + 'Page'); + console.log('Target page element:', targetPage); if (targetPage) { targetPage.style.display = 'block'; @@ -20,7 +24,10 @@ function showPage(pageId) { updateNavActiveState(pageId); // Load page data if needed + console.log('Loading page data for:', pageId); loadPageData(pageId); + } else { + console.error('Target page not found:', pageId + 'Page'); } } @@ -38,25 +45,34 @@ function updateNavActiveState(activePageId) { // Load page-specific data function loadPageData(pageId) { + console.log('loadPageData called with pageId:', pageId); switch (pageId) { case 'config': + console.log('Loading config page'); initializeConfigForm(); break; case 'images': + console.log('Loading images page'); loadImages(); break; case 'teams': + console.log('Loading teams page'); loadTeams(); break; case 'users': + console.log('Loading users page'); loadUsers(); break; - case 'api-keys': + case 'apiKeys': + console.log('Loading apiKeys page'); loadApiKeys(); break; case 'search': + console.log('Loading search page'); initializeSearchForm(); break; + default: + console.log('No specific loader for page:', pageId); } } @@ -266,6 +282,8 @@ window.addEventListener('hashchange', () => { // Initialize page on load document.addEventListener('DOMContentLoaded', () => { + console.log('UI.js DOMContentLoaded fired'); + // Initialize tooltips and popovers initializeTooltips(); initializePopovers(); @@ -276,5 +294,25 @@ document.addEventListener('DOMContentLoaded', () => { // Show initial page const hash = window.location.hash.substring(1); const initialPage = hash || 'home'; + console.log('Initial page:', initialPage); showPage(initialPage); -}); \ No newline at end of file +}); + +// Test function for debugging +function testPageNavigation() { + console.log('Testing page navigation...'); + console.log('Available pages:', document.querySelectorAll('.page').length); + + const pages = ['home', 'config', 'teams', 'users']; + pages.forEach(pageId => { + const pageElement = document.getElementById(pageId + 'Page'); + console.log(`Page ${pageId}:`, pageElement ? 'Found' : 'NOT FOUND'); + }); + + // Test showing teams page + console.log('Testing showPage("teams")...'); + showPage('teams'); +} + +// Make test function available globally +window.testPageNavigation = testPageNavigation; \ No newline at end of file diff --git a/client/js/users.js b/client/js/users.js index 550e043..96483b1 100644 --- a/client/js/users.js +++ b/client/js/users.js @@ -2,6 +2,11 @@ // Load users async function loadUsers() { + console.log('loadUsers called'); + console.log('Config check:', config.isConfigured()); + console.log('API Base URL:', config.getApiBaseUrl()); + console.log('API Key:', config.getApiKey() ? 'Set' : 'Not set'); + if (!config.isConfigured()) { showAlert('Please configure your API settings first.', 'warning'); return; @@ -11,11 +16,15 @@ async function loadUsers() { container.innerHTML = '
Loading users...
'; try { + console.log('Making API request to get users...'); const response = await apiClient.getUsers(); + console.log('API response:', response); // Handle structured response - extract users array from response object const users = response.users || response; + console.log('Users data:', users); displayUsers(users); } catch (error) { + console.error('Error loading users:', error); handleApiError(error, 'loading users'); container.innerHTML = '
Failed to load users
'; } diff --git a/client/serve.py b/client/serve.py index 129da71..6c276d2 100644 --- a/client/serve.py +++ b/client/serve.py @@ -11,7 +11,7 @@ import sys from pathlib import Path # Configuration -PORT = 8080 +PORT = 8081 HOST = 'localhost' class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): diff --git a/client/test.html b/client/test.html new file mode 100644 index 0000000..a4bed01 --- /dev/null +++ b/client/test.html @@ -0,0 +1,92 @@ + + + + + + SeReact Test + + + +

SeReact Navigation Test

+ +
+ + + + + +
+ +
+

Home Page

+

This is the home page content.

+
+ +
+

Teams Page

+
Teams will load here...
+
+ +
+

Users Page

+
Users will load here...
+
+ +
+

Config Page

+

Configuration settings go here.

+
+ +
+ + + + + + + + + + \ No newline at end of file diff --git a/scripts/client.sh b/scripts/client.sh index a24fb53..90766f5 100644 --- a/scripts/client.sh +++ b/scripts/client.sh @@ -72,10 +72,7 @@ start_dev_server() { fi # Check if Python is available - if command -v python3 &> /dev/null; then - print_color $BLUE "🐍 Using Python development server" - python3 serve.py - elif command -v python &> /dev/null; then + if command -v python &> /dev/null; then print_color $BLUE "🐍 Using Python development server" python serve.py else