Spaces:
Paused
Paused
Download admin.html from Ahmad140/ChatBotplus: direct link, hf CLI and curl.
- Browser
- Download file 25.5 kB
-
https://huggingface.co/spaces/Ahmad140/ChatBotplus/resolve/main/admin.html
- Command line
-
hf download hf://spaces/Ahmad140/ChatBotplus/admin.html
-
curl -L -o admin.html https://huggingface.co/spaces/Ahmad140/ChatBotplus/resolve/main/admin.html
25.5 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Elite Visuals – Admin Panel</title> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet"> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <script src="https://www.gstatic.com/firebasejs/9.22.1/firebase-app-compat.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/9.22.1/firebase-database-compat.js"></script> | |
| <style> | |
| * { margin: 0; padding: 0; box-sizing: border-box; } | |
| body { background: linear-gradient(135deg, #0a0a0f 0%, #12121a 100%); font-family: 'Inter', sans-serif; min-height: 100vh; padding: 30px; } | |
| .container { max-width: 1600px; margin: 0 auto; } | |
| h1 { color: white; margin-bottom: 10px; display: flex; align-items: center; gap: 15px; } | |
| h1 i { color: #25D366; } | |
| .subtitle { color: #8e8e9e; margin-bottom: 30px; } | |
| .tabs { display: flex; gap: 10px; margin-bottom: 20px; } | |
| .tab-btn { background: rgba(255,255,255,0.1); border: none; padding: 10px 20px; border-radius: 30px; color: white; cursor: pointer; transition: 0.2s; } | |
| .tab-btn.active { background: #25D366; color: black; } | |
| .tab-pane { display: none; } | |
| .tab-pane.active { display: block; } | |
| .stats { display: flex; gap: 20px; margin-bottom: 30px; flex-wrap: wrap; } | |
| .stat-card { background: rgba(255,255,255,0.1); backdrop-filter: blur(10px); border-radius: 20px; padding: 20px; min-width: 150px; text-align: center; } | |
| .stat-card h3 { color: #8e8e9e; font-size: 0.85rem; margin-bottom: 8px; } | |
| .stat-card .number { font-size: 2rem; font-weight: 700; color: #25D366; } | |
| .projects-table, .services-table { background: rgba(255,255,255,0.05); border-radius: 20px; overflow-x: auto; margin-top: 20px; } | |
| table { width: 100%; border-collapse: collapse; font-size: 0.8rem; } | |
| th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.1); color: #e0e0e0; vertical-align: top; } | |
| th { background: rgba(0,0,0,0.3); font-weight: 600; color: #25D366; position: sticky; top: 0; } | |
| .status-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.7rem; font-weight: 500; } | |
| .status-pending { background: #ffc107; color: #333; } | |
| .status-progress { background: #17a2b8; color: white; } | |
| .status-completed { background: #28a745; color: white; } | |
| .status-declined { background: #dc3545; color: white; } | |
| button, .btn { background: #25D366; border: none; padding: 6px 12px; border-radius: 8px; color: white; cursor: pointer; margin: 2px; font-size: 0.7rem; } | |
| .btn-danger { background: #dc3545; } | |
| .btn-warning { background: #ffc107; color: #333; } | |
| .btn-sm { padding: 4px 8px; font-size: 0.65rem; } | |
| .btn-info { background: #17a2b8; } | |
| input, textarea, select { background: #1e2a3a; border: 1px solid #2a2a35; border-radius: 8px; padding: 8px; color: white; margin: 5px 0; width: 100%; } | |
| .modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); justify-content: center; align-items: center; z-index: 1000; } | |
| .modal-content { background: #1e1e28; border-radius: 20px; padding: 20px; width: 650px; max-width: 90%; max-height: 80vh; overflow-y: auto; } | |
| .refresh-btn { background: #2a2a35; margin-bottom: 10px; padding: 8px 16px; } | |
| .flex-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } | |
| .detail-row { margin-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 6px; } | |
| .detail-label { font-weight: 600; color: #25D366; width: 140px; display: inline-block; vertical-align: top; } | |
| .detail-value { color: #ddd; word-break: break-word; display: inline-block; width: calc(100% - 150px); } | |
| .media-image { max-width: 200px; max-height: 200px; border-radius: 8px; margin-top: 8px; } | |
| .delete-all-btn { background: #dc3545; margin-left: 20px; padding: 8px 16px; } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1><i class="fas fa-crown"></i> Elite Visuals – Admin Panel</h1> | |
| <div class="flex-row" style="justify-content: space-between;"> | |
| <p class="subtitle">Manage projects, extra services, and client communications</p> | |
| <button id="deleteAllBtn" class="btn delete-all-btn"><i class="fas fa-trash-alt"></i> Delete All Data</button> | |
| </div> | |
| <div class="tabs"> | |
| <button class="tab-btn active" data-tab="projects">📋 Projects</button> | |
| <button class="tab-btn" data-tab="services">⚙️ Extra Services</button> | |
| </div> | |
| <!-- Projects Tab --> | |
| <div id="projectsTab" class="tab-pane active"> | |
| <div class="stats" id="statsContainer"> | |
| <div class="stat-card"><h3>Total Projects</h3><div class="number" id="totalProjects">0</div></div> | |
| <div class="stat-card"><h3>Pending</h3><div class="number" id="pendingCount">0</div></div> | |
| <div class="stat-card"><h3>In Progress</h3><div class="number" id="progressCount">0</div></div> | |
| <div class="stat-card"><h3>Completed</h3><div class="number" id="completedCount">0</div></div> | |
| <div class="stat-card"><h3>Declined</h3><div class="number" id="declinedCount">0</div></div> | |
| </div> | |
| <button class="refresh-btn" id="refreshProjectsBtn"><i class="fas fa-sync-alt"></i> Refresh Projects</button> | |
| <div class="projects-table"> | |
| <table id="projectsTable"> | |
| <thead> | |
| <tr> | |
| <th>Project ID</th><th>Domain</th><th>Pages</th><th>E-com</th><th>Chatbot</th><th>SEO</th> | |
| <th>Extras</th><th>📞 Mobile</th><th>✉️ Email</th> | |
| <th>Price</th><th>Timeline</th><th>Status</th><th>Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="projectsTableBody"><tr><td colspan="13" class="loading">Loading...<\/td><\/tr></tbody> | |
| </table> | |
| </div> | |
| </div> | |
| <!-- Services Tab --> | |
| <div id="servicesTab" class="tab-pane"> | |
| <div class="flex-row" style="margin-bottom: 20px;"> | |
| <button id="addServiceBtn" class="btn"><i class="fas fa-plus"></i> Add Single Service</button> | |
| <button id="bulkAddServiceBtn" class="btn"><i class="fas fa-layer-group"></i> Bulk Import Services</button> | |
| <button class="refresh-btn" id="refreshServicesBtn"><i class="fas fa-sync-alt"></i> Refresh Services</button> | |
| </div> | |
| <div class="services-table"> | |
| <table id="servicesTable"> | |
| <thead><tr><th>Key</th><th>Name</th><th>Price (PKR)</th><th>Timeline (days)</th><th>Actions</th></tr></thead> | |
| <tbody id="servicesTableBody"><td><td colspan="5" class="loading">Loading...<\/td><\/tr></tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Modals (same as before) --> | |
| <div id="detailsModal" class="modal"><div class="modal-content"><h3>📋 Project Full Details</h3><div id="detailsContent"></div><div class="detail-row"><span class="detail-label">Admin Message:</span> <textarea id="editAdminMessage" rows="2"></textarea></div><div class="flex-row"><button id="detailsSaveBtn" class="btn">Save Message</button><button id="detailsCloseBtn" class="btn-warning">Close</button></div></div></div> | |
| <div id="serviceModal" class="modal"><div class="modal-content"><h3 id="modalTitle">Add Service</h3><input type="text" id="serviceKey" style="display:none;"><input type="text" id="serviceName" placeholder="Service Name"><input type="number" id="servicePrice" placeholder="Price (PKR)"><input type="number" id="serviceTimeline" placeholder="Timeline (days)"><div class="flex-row"><button id="modalCancelBtn" class="btn-warning">Cancel</button><button id="modalSaveBtn" class="btn">Save</button></div></div></div> | |
| <div id="bulkModal" class="modal"><div class="modal-content"><h3>Bulk Import Services</h3><textarea id="bulkServicesInput" rows="8" placeholder="Name | Price | Timeline"></textarea><div class="flex-row"><button id="bulkCancelBtn" class="btn-warning">Cancel</button><button id="bulkImportBtn" class="btn">Import</button></div><div id="bulkResult"></div></div></div> | |
| <div id="declineModal" class="modal"><div class="modal-content"><h3>Decline Project</h3><textarea id="declineReason" rows="3"></textarea><div class="flex-row"><button id="declineCancelBtn" class="btn-warning">Cancel</button><button id="declineConfirmBtn" class="btn-danger">Confirm Decline</button></div></div></div> | |
| <div id="deleteConfirmModal" class="modal"><div class="modal-content"><h3>⚠️ Delete All Data</h3><p>This will permanently delete ALL projects. Are you sure?</p><div class="flex-row"><button id="deleteConfirmNo" class="btn-warning">Cancel</button><button id="deleteConfirmYes" class="btn-danger">Yes, Delete Everything</button></div></div></div> | |
| <script> | |
| const firebaseConfig = { | |
| apiKey: "AIzaSyDaZ-JNzw--zGqWN1wweC4csDAE_GKUklw", | |
| authDomain: "chat-bot-80c6e.firebaseapp.com", | |
| databaseURL: "https://chat-bot-80c6e-default-rtdb.firebaseio.com", | |
| projectId: "chat-bot-80c6e", | |
| storageBucket: "chat-bot-80c6e.firebasestorage.app", | |
| messagingSenderId: "363352177618", | |
| appId: "1:363352177618:web:4a75bd8c66e53f1b05a60b" | |
| }; | |
| firebase.initializeApp(firebaseConfig); | |
| const database = firebase.database(); | |
| let currentProjects = []; | |
| let currentServices = {}; | |
| let currentDetailsProjectId = null; | |
| // ---------- Projects ---------- | |
| async function loadProjects() { | |
| const tbody = document.getElementById('projectsTableBody'); | |
| tbody.innerHTML = '<tr><td colspan="13" class="loading">Loading...<\/td><\/tr>'; | |
| const snapshot = await database.ref('projects').once('value'); | |
| const data = snapshot.val(); | |
| currentProjects = data ? Object.values(data) : []; | |
| renderProjects(); | |
| updateStats(); | |
| } | |
| function renderProjects() { | |
| const tbody = document.getElementById('projectsTableBody'); | |
| if (!currentProjects.length) { tbody.innerHTML = '<tr><td colspan="13" class="loading">No projects found<\/td><\/tr>'; return; } | |
| tbody.innerHTML = ''; | |
| currentProjects.forEach(proj => { | |
| const req = proj.requirements || {}; | |
| const extras = (req.extra_features || []).join(', ') || 'None'; | |
| const statusClass = `status-${proj.status}`; | |
| const statusText = proj.status==='pending'?'⏳ Pending':(proj.status==='in-progress'?'🔄 In Progress':(proj.status==='completed'?'✅ Completed':'❌ Declined')); | |
| const mobile = req.mobile || '—'; | |
| const email = req.email || '—'; | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td><code>${proj.project_id}</code></td> | |
| <td>${req.domain ? '✅' : '❌'}</td> | |
| <td>${req.pages || 5}</td> | |
| <td>${req.ecommerce ? '✅' : '❌'}</td> | |
| <td>${req.chatbot ? '✅' : '❌'}</td> | |
| <td>${req.seo ? '✅' : '❌'}</td> | |
| <td><small>${extras}</small></td> | |
| <td>${mobile}</td><td>${email}</td> | |
| <td>PKR ${(proj.calculated_price||0).toLocaleString()}</td> | |
| <td>${proj.calculated_timeline||0} days</td> | |
| <td><span class="status-badge ${statusClass}">${statusText}</span></td> | |
| <td> | |
| <select onchange="updateStatusDirect('${proj.project_id}', this.value)"> | |
| <option ${proj.status==='pending'?'selected':''}>pending</option> | |
| <option ${proj.status==='in-progress'?'selected':''}>in-progress</option> | |
| <option ${proj.status==='completed'?'selected':''}>completed</option> | |
| <option ${proj.status==='declined'?'selected':''}>declined</option> | |
| </select> | |
| <button class="btn-sm" onclick="openDeclineModal('${proj.project_id}')">Decline</button> | |
| <button class="btn-sm btn-info" onclick="openDetailsModal('${proj.project_id}')">Details</button> | |
| </td> | |
| `; | |
| tbody.appendChild(row); | |
| }); | |
| } | |
| function updateStats() { | |
| const total = currentProjects.length; | |
| const pending = currentProjects.filter(p=>p.status==='pending').length; | |
| const progress = currentProjects.filter(p=>p.status==='in-progress').length; | |
| const completed = currentProjects.filter(p=>p.status==='completed').length; | |
| const declined = currentProjects.filter(p=>p.status==='declined').length; | |
| document.getElementById('totalProjects').innerText = total; | |
| document.getElementById('pendingCount').innerText = pending; | |
| document.getElementById('progressCount').innerText = progress; | |
| document.getElementById('completedCount').innerText = completed; | |
| document.getElementById('declinedCount').innerText = declined; | |
| } | |
| window.updateStatusDirect = async (id, status) => { | |
| await database.ref(`projects/${id}`).update({ status, updated_at: new Date().toISOString() }); | |
| loadProjects(); | |
| }; | |
| let declineId = null; | |
| window.openDeclineModal = (id) => { declineId = id; document.getElementById('declineModal').style.display='flex'; }; | |
| document.getElementById('declineCancelBtn').onclick = () => document.getElementById('declineModal').style.display='none'; | |
| document.getElementById('declineConfirmBtn').onclick = async () => { | |
| const reason = document.getElementById('declineReason').value; | |
| await database.ref(`projects/${declineId}`).update({ status:'declined', admin_message:reason, updated_at:new Date().toISOString() }); | |
| document.getElementById('declineModal').style.display='none'; | |
| loadProjects(); | |
| }; | |
| window.openDetailsModal = async (id) => { | |
| currentDetailsProjectId = id; | |
| const snap = await database.ref(`projects/${id}`).once('value'); | |
| const proj = snap.val(); | |
| if(!proj) return; | |
| const req = proj.requirements || {}; | |
| let html = ` | |
| <div class="detail-row"><span class="detail-label">Project ID:</span> <span class="detail-value">${proj.project_id}</span></div> | |
| <div class="detail-row"><span class="detail-label">Status:</span> <span class="detail-value">${proj.status}</span></div> | |
| <div class="detail-row"><span class="detail-label">Created:</span> <span class="detail-value">${new Date(proj.created_at).toLocaleString()}</span></div> | |
| <div class="detail-row"><span class="detail-label">Last Updated:</span> <span class="detail-value">${new Date(proj.updated_at).toLocaleString()}</span></div> | |
| <div class="detail-row"><span class="detail-label">Mobile:</span> <span class="detail-value">${req.mobile||'—'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Email:</span> <span class="detail-value">${req.email||'—'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Domain:</span> <span class="detail-value">${req.domain?'Yes (+PKR 5,000)':'No'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Pages:</span> <span class="detail-value">${req.pages||5}</span></div> | |
| <div class="detail-row"><span class="detail-label">E‑commerce:</span> <span class="detail-value">${req.ecommerce?'Yes (+PKR 50,000)':'No'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Chatbot:</span> <span class="detail-value">${req.chatbot?'Yes (+PKR 30,000)':'No'}</span></div> | |
| <div class="detail-row"><span class="detail-label">SEO:</span> <span class="detail-value">${req.seo?'Yes (+PKR 25,000)':'No'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Extra Features:</span> <span class="detail-value">${(req.extra_features||[]).join(', ')||'None'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Inventory:</span> <span class="detail-value">${req.inventory||'No'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Database:</span> <span class="detail-value">${req.data||'No'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Purpose:</span> <span class="detail-value">${req.purpose||'—'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Theme:</span> <span class="detail-value">${req.theme||'—'}</span></div> | |
| <div class="detail-row"><span class="detail-label">Content:</span> <span class="detail-value">${req.content||'—'}</span></div> | |
| `; | |
| if(req.media_text) html += `<div class="detail-row"><span class="detail-label">Client Notes:</span> <span class="detail-value">${req.media_text}</span></div>`; | |
| if(req.media_image) html += `<div class="detail-row"><span class="detail-label">Uploaded Image:</span> <span class="detail-value"><img src="${req.media_image}" class="media-image"></span></div>`; | |
| html += `<div class="detail-row"><span class="detail-label">Total Price:</span> <span class="detail-value">PKR ${(proj.calculated_price||0).toLocaleString()}</span></div> | |
| <div class="detail-row"><span class="detail-label">Total Timeline:</span> <span class="detail-value">${proj.calculated_timeline||0} days</span></div>`; | |
| document.getElementById('detailsContent').innerHTML = html; | |
| document.getElementById('editAdminMessage').value = proj.admin_message||''; | |
| document.getElementById('detailsModal').style.display='flex'; | |
| }; | |
| document.getElementById('detailsCloseBtn').onclick = () => document.getElementById('detailsModal').style.display='none'; | |
| document.getElementById('detailsSaveBtn').onclick = async () => { | |
| const msg = document.getElementById('editAdminMessage').value; | |
| await database.ref(`projects/${currentDetailsProjectId}`).update({ admin_message: msg, updated_at: new Date().toISOString() }); | |
| document.getElementById('detailsModal').style.display='none'; | |
| loadProjects(); | |
| }; | |
| // ---------- Extra Services ---------- | |
| async function loadServices() { | |
| const tbody = document.getElementById('servicesTableBody'); | |
| tbody.innerHTML = '<tr><td colspan="5" class="loading">Loading...<\/td><\/tr>'; | |
| const snap = await database.ref('extra_services').once('value'); | |
| currentServices = snap.val() || {}; | |
| renderServices(); | |
| } | |
| function renderServices() { | |
| const tbody = document.getElementById('servicesTableBody'); | |
| if (!Object.keys(currentServices).length) { tbody.innerHTML = '<tr><td colspan="5" class="loading">No extra services found<\/td><\/tr>'; return; } | |
| tbody.innerHTML = ''; | |
| for (const [k, svc] of Object.entries(currentServices)) { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td><code>${k}</code></td> | |
| <td>${svc.name}</td> | |
| <td>PKR ${svc.price?.toLocaleString()||0}</td> | |
| <td>${svc.timeline||0} days</td> | |
| <td> | |
| <button class="btn-sm" onclick="editService('${k}')">Edit</button> | |
| <button class="btn-sm btn-danger" onclick="deleteService('${k}')">Delete</button> | |
| </td> | |
| `; | |
| tbody.appendChild(row); | |
| } | |
| } | |
| window.editService = (k) => { | |
| const svc = currentServices[k]; | |
| document.getElementById('modalTitle').innerText = 'Edit Service'; | |
| document.getElementById('serviceKey').value = k; | |
| document.getElementById('serviceName').value = svc.name; | |
| document.getElementById('servicePrice').value = svc.price; | |
| document.getElementById('serviceTimeline').value = svc.timeline; | |
| document.getElementById('serviceModal').style.display='flex'; | |
| }; | |
| window.deleteService = async (k) => { | |
| if (confirm(`Delete service "${k}"?`)) { | |
| await database.ref(`extra_services/${k}`).remove(); | |
| loadServices(); | |
| } | |
| }; | |
| document.getElementById('addServiceBtn').onclick = () => { | |
| document.getElementById('modalTitle').innerText = 'Add Single Service'; | |
| document.getElementById('serviceKey').value = ''; | |
| document.getElementById('serviceName').value = ''; | |
| document.getElementById('servicePrice').value = ''; | |
| document.getElementById('serviceTimeline').value = ''; | |
| document.getElementById('serviceModal').style.display='flex'; | |
| }; | |
| document.getElementById('modalCancelBtn').onclick = () => document.getElementById('serviceModal').style.display='none'; | |
| document.getElementById('modalSaveBtn').onclick = async () => { | |
| let key = document.getElementById('serviceKey').value.trim(); | |
| let name = document.getElementById('serviceName').value.trim(); | |
| let price = parseInt(document.getElementById('servicePrice').value) || 0; | |
| let timeline = parseInt(document.getElementById('serviceTimeline').value) || 0; | |
| if (!name) { alert('Service name required'); return; } | |
| const finalKey = key || name.toLowerCase().replace(/ /g,'_'); | |
| await database.ref(`extra_services/${finalKey}`).set({ name, price, timeline, display: `${name} (+PKR ${price.toLocaleString()}, +${timeline} days)` }); | |
| document.getElementById('serviceModal').style.display='none'; | |
| loadServices(); | |
| }; | |
| // Bulk import | |
| document.getElementById('bulkAddServiceBtn').onclick = () => { | |
| document.getElementById('bulkServicesInput').value = ''; | |
| document.getElementById('bulkResult').innerHTML = ''; | |
| document.getElementById('bulkModal').style.display='flex'; | |
| }; | |
| document.getElementById('bulkCancelBtn').onclick = () => document.getElementById('bulkModal').style.display='none'; | |
| document.getElementById('bulkImportBtn').onclick = async () => { | |
| const lines = document.getElementById('bulkServicesInput').value.split(/\r?\n/); | |
| let success=0, fail=0; | |
| for (let line of lines) { | |
| line = line.trim(); | |
| if (!line) continue; | |
| const parts = line.split('|').map(p=>p.trim()); | |
| if (parts.length < 3) { fail++; continue; } | |
| const name = parts[0]; | |
| const price = parseInt(parts[1]); | |
| const timeline = parseInt(parts[2]); | |
| if (isNaN(price) || isNaN(timeline)) { fail++; continue; } | |
| const key = name.toLowerCase().replace(/ /g,'_'); | |
| try { | |
| await database.ref(`extra_services/${key}`).set({ name, price, timeline, display: `${name} (+PKR ${price.toLocaleString()}, +${timeline} days)` }); | |
| success++; | |
| } catch(e) { fail++; } | |
| } | |
| document.getElementById('bulkResult').innerHTML = `✅ Imported: ${success}, ❌ Failed: ${fail}`; | |
| if (success) loadServices(); | |
| setTimeout(()=>document.getElementById('bulkModal').style.display='none', 1500); | |
| }; | |
| // Delete all data - fixed fetch | |
| const deleteModal = document.getElementById('deleteConfirmModal'); | |
| document.getElementById('deleteAllBtn').onclick = () => deleteModal.style.display='flex'; | |
| document.getElementById('deleteConfirmNo').onclick = () => deleteModal.style.display='none'; | |
| document.getElementById('deleteConfirmYes').onclick = async () => { | |
| deleteModal.style.display='none'; | |
| if (confirm("⚠️ This will delete ALL projects. Are you absolutely sure?")) { | |
| try { | |
| const response = await fetch('/api/delete_all_projects?confirm=YES', { method: 'DELETE' }); | |
| if (!response.ok) { | |
| const errorText = await response.text(); | |
| throw new Error(`Server responded with ${response.status}: ${errorText}`); | |
| } | |
| const data = await response.json(); | |
| alert(data.message || "All projects deleted successfully"); | |
| loadProjects(); | |
| } catch (err) { | |
| console.error("Delete error:", err); | |
| alert("Error deleting projects: " + err.message + "\n\nPlease make sure you are accessing the admin panel via the same origin (e.g., https://your-space.hf.space/admin) and that the backend route exists."); | |
| } | |
| } | |
| }; | |
| // Refresh buttons | |
| document.getElementById('refreshProjectsBtn').addEventListener('click', loadProjects); | |
| document.getElementById('refreshServicesBtn').addEventListener('click', loadServices); | |
| // Tab switching | |
| document.querySelectorAll('.tab-btn').forEach(btn => { | |
| btn.addEventListener('click', () => { | |
| document.querySelectorAll('.tab-btn').forEach(b=>b.classList.remove('active')); | |
| btn.classList.add('active'); | |
| document.querySelectorAll('.tab-pane').forEach(p=>p.classList.remove('active')); | |
| document.getElementById(`${btn.dataset.tab}Tab`).classList.add('active'); | |
| if (btn.dataset.tab === 'services') loadServices(); | |
| }); | |
| }); | |
| loadProjects(); | |
| loadServices(); | |
| </script> | |
| </body> | |
| </html> |