Download admin.html from medo3423e/undefined: direct link, hf CLI and curl.
- Browser
- Download file 26.9 kB
-
https://huggingface.co/spaces/medo3423e/undefined/resolve/main/admin.html
- Command line
-
hf download hf://spaces/medo3423e/undefined/admin.html
-
curl -L -o admin.html https://huggingface.co/spaces/medo3423e/undefined/resolve/main/admin.html
26.9 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>SweetOasis Admin</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-app-compat.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-auth-compat.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore-compat.js"></script> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap'); | |
| body { | |
| font-family: 'Poppins', sans-serif; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100"> | |
| <!-- Admin Navigation --> | |
| <nav class="bg-white shadow-sm"> | |
| <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> | |
| <div class="flex justify-between h-16 items-center"> | |
| <span class="text-xl font-bold text-pink-600">SweetOasis Admin</span> | |
| <button id="logoutBtn" class="text-gray-600 hover:text-pink-600 flex items-center"> | |
| <i data-feather="log-out" class="mr-1"></i> Logout | |
| </button> | |
| </div> | |
| </div> | |
| </nav> | |
| <!-- Admin Content --> | |
| <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8"> | |
| <div class="grid grid-cols-1 lg:grid-cols-4 gap-8"> | |
| <!-- Sidebar --> | |
| <div class="lg:col-span-1"> | |
| <div class="bg-white rounded-lg shadow p-6 sticky top-8"> | |
| <h2 class="text-xl font-bold mb-4">Admin Panel</h2> | |
| <nav class="space-y-2"> | |
| <a href="#" id="productsTab" class="block px-4 py-2 rounded-lg bg-pink-100 text-pink-600 font-medium"> | |
| <i data-feather="shopping-bag" class="inline mr-2"></i> Products | |
| </a> | |
| <a href="#" id="ordersTab" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-gray-100"> | |
| <i data-feather="package" class="inline mr-2"></i> Orders | |
| </a> | |
| <a href="#" id="usersTab" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-gray-100"> | |
| <i data-feather="users" class="inline mr-2"></i> Users | |
| </a> | |
| </nav> | |
| </div> | |
| </div> | |
| <!-- Main Content --> | |
| <div class="lg:col-span-3"> | |
| <!-- Products Management --> | |
| <div id="productsSection"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h2 class="text-2xl font-bold">Products Management</h2> | |
| <button id="addProductBtn" class="bg-pink-500 hover:bg-pink-600 text-white px-4 py-2 rounded-lg font-medium flex items-center"> | |
| <i data-feather="plus" class="mr-1"></i> Add Product | |
| </button> | |
| </div> | |
| <div class="bg-white rounded-lg shadow overflow-hidden"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Image</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="productsTable" class="bg-white divide-y divide-gray-200"> | |
| <!-- Products will be loaded here --> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| <!-- Orders Management --> | |
| <div id="ordersSection" class="hidden"> | |
| <h2 class="text-2xl font-bold mb-6">Orders Management</h2> | |
| <div class="bg-white rounded-lg shadow"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Order ID</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Customer</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="ordersTable" class="bg-white divide-y divide-gray-200"> | |
| <!-- Orders will be loaded here --> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| <!-- Users Management --> | |
| <div id="usersSection" class="hidden"> | |
| <h2 class="text-2xl font-bold mb-6">Users Management</h2> | |
| <div class="bg-white rounded-lg shadow"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="usersTable" class="bg-white divide-y divide-gray-200"> | |
| <!-- Users will be loaded here --> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| <!-- Add/Edit Product Modal --> | |
| <div id="productModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4"> | |
| <div class="bg-white rounded-lg shadow-xl w-full max-w-md"> | |
| <div class="p-6"> | |
| <h3 class="text-xl font-bold mb-4" id="modalTitle">Add New Product</h3> | |
| <form id="productForm"> | |
| <input type="hidden" id="productId"> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Product Name</label> | |
| <input type="text" id="productName" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Description</label> | |
| <textarea id="productDescription" rows="3" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300"></textarea> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Price ($)</label> | |
| <input type="number" id="productPrice" step="0.01" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Image URL</label> | |
| <input type="url" id="productImage" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required> | |
| </div> | |
| <div class="flex items-center mb-4"> | |
| <input type="checkbox" id="productIsNew" class="mr-2"> | |
| <label class="text-gray-700">Mark as New</label> | |
| </div> | |
| <div class="flex justify-end space-x-3"> | |
| <button type="button" id="cancelProductBtn" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-100">Cancel</button> | |
| <button type="submit" id="saveProductBtn" class="px-4 py-2 bg-pink-500 text-white rounded-lg hover:bg-pink-600">Save</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Add/Edit User Modal --> | |
| <div id="userModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4"> | |
| <div class="bg-white rounded-lg shadow-xl w-full max-w-md"> | |
| <div class="p-6"> | |
| <h3 class="text-xl font-bold mb-4" id="userModalTitle">Add New User</h3> | |
| <form id="userForm"> | |
| <input type="hidden" id="userId"> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Email</label> | |
| <input type="email" id="userEmail" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Name</label> | |
| <input type="text" id="userName" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Password</label> | |
| <input type="password" id="userPassword" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300"> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Role</label> | |
| <select id="userRole" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300"> | |
| <option value="user">User</option> | |
| <option value="admin">Admin</option> | |
| </select> | |
| </div> | |
| <div class="flex justify-end space-x-3"> | |
| <button type="button" id="cancelUserBtn" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-100">Cancel</button> | |
| <button type="submit" id="saveUserBtn" class="px-4 py-2 bg-pink-500 text-white rounded-lg hover:bg-pink-600">Save</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Firebase configuration - REPLACE WITH YOUR ACTUAL CONFIG | |
| const firebaseConfig = { | |
| apiKey: "AIzaSyCZqw9_svj6Qc9op6U6MqCLuuhbR-BTZm0", | |
| authDomain: "kkkk-aa173.firebaseapp.com", | |
| projectId: "kkkk-aa173", | |
| storageBucket: "kkkk-aa173.firebasestorage.app", | |
| messagingSenderId: "751348817218", | |
| appId: "1:751348817218:web:108d2b506f524332af7cdb", | |
| measurementId: "G-GYV2NVT3H6" | |
| }; | |
| // Initialize Firebase | |
| firebase.initializeApp(firebaseConfig); | |
| const auth = firebase.auth(); | |
| const db = firebase.firestore(); | |
| // DOM Elements | |
| const productsSection = document.getElementById('productsSection'); | |
| const ordersSection = document.getElementById('ordersSection'); | |
| const usersSection = document.getElementById('usersSection'); | |
| const productsTab = document.getElementById('productsTab'); | |
| const ordersTab = document.getElementById('ordersTab'); | |
| const usersTab = document.getElementById('usersTab'); | |
| const productsTable = document.getElementById('productsTable'); | |
| const ordersTable = document.getElementById('ordersTable'); | |
| const usersTable = document.getElementById('usersTable'); | |
| const addProductBtn = document.getElementById('addProductBtn'); | |
| const logoutBtn = document.getElementById('logoutBtn'); | |
| const productModal = document.getElementById('productModal'); | |
| const productForm = document.getElementById('productForm'); | |
| const modalTitle = document.getElementById('modalTitle'); | |
| const productId = document.getElementById('productId'); | |
| const productName = document.getElementById('productName'); | |
| const productDescription = document.getElementById('productDescription'); | |
| const productPrice = document.getElementById('productPrice'); | |
| const productImage = document.getElementById('productImage'); | |
| const productIsNew = document.getElementById('productIsNew'); | |
| const saveProductBtn = document.getElementById('saveProductBtn'); | |
| const cancelProductBtn = document.getElementById('cancelProductBtn'); | |
| const userModal = document.getElementById('userModal'); | |
| const userForm = document.getElementById('userForm'); | |
| const userModalTitle = document.getElementById('userModalTitle'); | |
| const userId = document.getElementById('userId'); | |
| const userEmail = document.getElementById('userEmail'); | |
| const userName = document.getElementById('userName'); | |
| const userPassword = document.getElementById('userPassword'); | |
| const userRole = document.getElementById('userRole'); | |
| const saveUserBtn = document.getElementById('saveUserBtn'); | |
| const cancelUserBtn = document.getElementById('cancelUserBtn'); | |
| // Check auth state and load data | |
| auth.onAuthStateChanged(user => { | |
| if (user) { | |
| db.collection('users').doc(user.uid).get().then(doc => { | |
| if (doc.exists) { | |
| const userData = doc.data(); | |
| if (userData.role === 'admin') { | |
| loadProducts(); | |
| } else { | |
| window.location.href = 'index.html'; | |
| } | |
| } else { | |
| // If user doc doesn't exist, check if it's the first user | |
| db.collection('users').get().then(snapshot => { | |
| if (snapshot.empty) { | |
| // First user - automatically make admin | |
| db.collection('users').doc(user.uid).set({ | |
| displayName: user.displayName, | |
| email: user.email, | |
| role: 'admin', | |
| createdAt: firebase.firestore.FieldValue.serverTimestamp() | |
| }).then(() => loadProducts()); | |
| } else { | |
| window.location.href = 'index.html'; | |
| } | |
| }); | |
| } | |
| }); | |
| } else { | |
| window.location.href = 'index.html'; | |
| } | |
| }); | |
| // Load products | |
| function loadProducts() { | |
| db.collection('products').get().then(querySnapshot => { | |
| productsTable.innerHTML = ''; | |
| querySnapshot.forEach(doc => { | |
| const product = doc.data(); | |
| productsTable.innerHTML += ` | |
| <tr> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <img src="${product.image}" alt="${product.name}" class="h-10 w-10 rounded-full object-cover"> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="text-sm font-medium text-gray-900">${product.name}</div> | |
| ${product.description ? `<div class="text-sm text-gray-500">${product.description}</div>` : ''} | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="text-sm text-pink-600 font-bold">$${product.price.toFixed(2)}</div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 space-x-2"> | |
| <button onclick="editProduct('${doc.id}')" class="text-blue-500 hover:text-blue-700"> | |
| <i data-feather="edit" class="w-4 h-4"></i> | |
| </button> | |
| <button onclick="deleteProduct('${doc.id}')" class="text-red-500 hover:text-red-700"> | |
| <i data-feather="trash-2" class="w-4 h-4"></i> | |
| </button> | |
| </td> | |
| </tr> | |
| `; | |
| }); | |
| feather.replace(); | |
| }); | |
| } | |
| // Load users | |
| function loadUsers() { | |
| db.collection('users').get().then(querySnapshot => { | |
| usersTable.innerHTML = ''; | |
| querySnapshot.forEach(doc => { | |
| const user = doc.data(); | |
| usersTable.innerHTML += ` | |
| <tr> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="text-sm font-medium text-gray-900">${user.email}</div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="text-sm text-gray-900">${user.displayName || '-'}</div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <span class="px-2 py-1 text-xs rounded-full ${user.role === 'admin' ? 'bg-pink-100 text-pink-800' : 'bg-gray-100 text-gray-800'}"> | |
| ${user.role || 'user'} | |
| </span> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 space-x-2"> | |
| <button onclick="editUser('${doc.id}')" class="text-blue-500 hover:text-blue-700"> | |
| <i data-feather="edit" class="w-4 h-4"></i> | |
| </button> | |
| <button onclick="deleteUser('${doc.id}')" class="text-red-500 hover:text-red-700"> | |
| <i data-feather="trash-2" class="w-4 h-4"></i> | |
| </button> | |
| </td> | |
| </tr> | |
| `; | |
| }); | |
| feather.replace(); | |
| }); | |
| } | |
| // Open add product modal | |
| addProductBtn.addEventListener('click', () => { | |
| modalTitle.textContent = 'Add New Product'; | |
| productForm.reset(); | |
| productId.value = ''; | |
| productModal.classList.remove('hidden'); | |
| }); | |
| // Cancel product edit/add | |
| cancelProductBtn.addEventListener('click', () => { | |
| productModal.classList.add('hidden'); | |
| }); | |
| // Save product | |
| productForm.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| const productData = { | |
| name: productName.value, | |
| description: productDescription.value, | |
| price: parseFloat(productPrice.value), | |
| image: productImage.value, | |
| isNew: productIsNew.checked, | |
| createdAt: firebase.firestore.FieldValue.serverTimestamp() | |
| }; | |
| if (productId.value) { | |
| // Update existing product | |
| db.collection('products').doc(productId.value).update(productData) | |
| .then(() => { | |
| productModal.classList.add('hidden'); | |
| loadProducts(); | |
| }); | |
| } else { | |
| // Add new product | |
| db.collection('products').add(productData) | |
| .then(() => { | |
| productModal.classList.add('hidden'); | |
| loadProducts(); | |
| }); | |
| } | |
| }); | |
| // Edit product | |
| window.editProduct = (id) => { | |
| db.collection('products').doc(id).get().then(doc => { | |
| if (doc.exists) { | |
| const product = doc.data(); | |
| modalTitle.textContent = 'Edit Product'; | |
| productId.value = doc.id; | |
| productName.value = product.name; | |
| productDescription.value = product.description || ''; | |
| productPrice.value = product.price; | |
| productImage.value = product.image; | |
| productIsNew.checked = product.isNew || false; | |
| productModal.classList.remove('hidden'); | |
| } | |
| }); | |
| }; | |
| // Delete product | |
| window.deleteProduct = (id) => { | |
| if (confirm('Are you sure you want to delete this product?')) { | |
| db.collection('products').doc(id).delete() | |
| .then(() => { | |
| loadProducts(); | |
| }); | |
| } | |
| }; | |
| // Edit user | |
| window.editUser = (id) => { | |
| db.collection('users').doc(id).get().then(doc => { | |
| if (doc.exists) { | |
| const user = doc.data(); | |
| userModalTitle.textContent = 'Edit User'; | |
| userId.value = doc.id; | |
| userEmail.value = user.email; | |
| userName.value = user.displayName || ''; | |
| userRole.value = user.role || 'user'; | |
| userModal.classList.remove('hidden'); | |
| } | |
| }); | |
| }; | |
| // Delete user | |
| window.deleteUser = (id) => { | |
| if (confirm('Are you sure you want to delete this user?')) { | |
| db.collection('users').doc(id).delete() | |
| .then(() => { | |
| loadUsers(); | |
| }); | |
| } | |
| }; | |
| // Save user | |
| userForm.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const userData = { | |
| email: userEmail.value, | |
| displayName: userName.value, | |
| role: userRole.value | |
| }; | |
| try { | |
| if (userId.value) { | |
| // Update existing user | |
| await db.collection('users').doc(userId.value).update(userData); | |
| } else { | |
| // Create new user | |
| const { user } = await auth.createUserWithEmailAndPassword(userEmail.value, userPassword.value); | |
| await user.updateProfile({ | |
| displayName: userName.value | |
| }); | |
| await db.collection('users').doc(user.uid).set({ | |
| ...userData, | |
| uid: user.uid | |
| }); | |
| } | |
| userModal.classList.add('hidden'); | |
| loadUsers(); | |
| } catch (error) { | |
| alert(error.message); | |
| } | |
| }); | |
| // Cancel user edit/add | |
| cancelUserBtn.addEventListener('click', () => { | |
| userModal.classList.add('hidden'); | |
| }); | |
| // Switch between tabs | |
| productsTab.addEventListener('click', (e) => { | |
| e.preventDefault(); | |
| productsSection.classList.remove('hidden'); | |
| ordersSection.classList.add('hidden'); | |
| usersSection.classList.add('hidden'); | |
| productsTab.classList.add('bg-pink-100', 'text-pink-600'); | |
| productsTab.classList.remove('text-gray-600', 'hover:bg-gray-100'); | |
| ordersTab.classList.remove('bg-pink-100', 'text-pink-600'); | |
| ordersTab.classList.add('text-gray-600', 'hover:bg-gray-100'); | |
| usersTab.classList.remove('bg-pink-100', 'text-pink-600'); | |
| usersTab.classList.add('text-gray-600', 'hover:bg-gray-100'); | |
| }); | |
| ordersTab.addEventListener('click', (e) => { | |
| e.preventDefault(); | |
| ordersSection.classList.remove('hidden'); | |
| productsSection.classList.add('hidden'); | |
| usersSection.classList.add('hidden'); | |
| ordersTab.classList.add('bg-pink-100', 'text-pink-600'); | |
| ordersTab.classList.remove('text-gray-600', 'hover:bg-gray-100'); | |
| productsTab.classList.remove('bg-pink-100', 'text-pink-600'); | |
| productsTab.classList.add('text-gray-600', 'hover:bg-gray-100'); | |
| usersTab.classList.remove('bg-pink-100', 'text-pink-600'); | |
| usersTab.classList.add('text-gray-600', 'hover:bg-gray-100'); | |
| }); | |
| usersTab.addEventListener('click', (e) => { | |
| e.preventDefault(); | |
| usersSection.classList.remove('hidden'); | |
| productsSection.classList.add('hidden'); | |
| ordersSection.classList.add('hidden'); | |
| usersTab.classList.add('bg-pink-100', 'text-pink-600'); | |
| usersTab.classList.remove('text-gray-600', 'hover:bg-gray-100'); | |
| productsTab.classList.remove('bg-pink-100', 'text-pink-600'); | |
| productsTab.classList.add('text-gray-600', 'hover:bg-gray-100'); | |
| ordersTab.classList.remove('bg-pink-100', 'text-pink-600'); | |
| ordersTab.classList.add('text-gray-600', 'hover:bg-gray-100'); | |
| loadUsers(); | |
| }); | |
| // Logout | |
| logoutBtn.addEventListener('click', () => { | |
| auth.signOut(); | |
| }); | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', () => { | |
| feather.replace(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |