Spaces:
Running
Running
Generate two separate mobile-friendly HTML files for a job website using vanilla JavaScript and Firebase (Realtime Database + Authentication).
750c8a3 verified Download admin.html from rkrishukumar/jobhive-buzz: direct link, hf CLI and curl.
- Browser
- Download file 26 kB
-
https://huggingface.co/spaces/rkrishukumar/jobhive-buzz/resolve/main/admin.html
- Command line
-
hf download hf://spaces/rkrishukumar/jobhive-buzz/admin.html
-
curl -L -o admin.html https://huggingface.co/spaces/rkrishukumar/jobhive-buzz/resolve/main/admin.html
26 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>JobNest Admin</title> | |
| <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> | |
| <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> | |
| <style> | |
| .glassmorphism { | |
| background: rgba(255, 255, 255, 0.1); | |
| backdrop-filter: blur(10px); | |
| border: 1px solid rgba(255, 255, 255, 0.2); | |
| } | |
| .job-card:hover { | |
| transform: translateY(-5px); | |
| transition: all 0.3s ease; | |
| box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1); | |
| } | |
| @media (max-width: 768px) { | |
| .responsive-grid { | |
| grid-template-columns: 1fr; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gradient-to-br from-indigo-50 to-blue-100 min-h-screen"> | |
| <div id="app" class="container mx-auto px-4 py-8"> | |
| <!-- Login Section --> | |
| <div id="loginSection" class="max-w-md mx-auto mt-10 glassmorphism rounded-xl p-6 shadow-lg"> | |
| <h2 class="text-2xl font-bold text-center text-indigo-800 mb-6">Admin Portal</h2> | |
| <form id="loginForm" class="space-y-4"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Email</label> | |
| <input type="email" id="email" required | |
| class="w-full p-2 rounded-md border border-gray-300 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Password</label> | |
| <input type="password" id="password" required | |
| class="w-full p-2 rounded-md border border-gray-300 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <button type="submit" | |
| class="w-full py-2 px-4 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition"> | |
| Login | |
| </button> | |
| </form> | |
| </div> | |
| <!-- Admin Dashboard --> | |
| <div id="dashboardSection" class="hidden"> | |
| <div class="flex flex-col md:flex-row justify-between items-center mb-6"> | |
| <h1 class="text-2xl font-bold text-indigo-900">Dashboard</h1> | |
| <button id="logoutBtn" | |
| class="px-3 py-1.5 bg-red-500 text-white rounded-md hover:bg-red-600 transition flex items-center gap-1 mt-2 md:mt-0"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" /> | |
| </svg> | |
| Logout | |
| </button> | |
| </div> | |
| <!-- Stats Cards --> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> | |
| <div class="glassmorphism rounded-lg p-4 text-center"> | |
| <h3 class="text-md font-medium text-indigo-800">Total Jobs</h3> | |
| <p id="totalJobs" class="text-3xl font-bold text-indigo-600 mt-1">0</p> | |
| </div> | |
| <div class="glassmorphism rounded-lg p-4 text-center"> | |
| <h3 class="text-md font-medium text-indigo-800">Published</h3> | |
| <p id="publishedJobs" class="text-3xl font-bold text-indigo-600 mt-1">0</p> | |
| </div> | |
| <div class="glassmorphism rounded-lg p-4 text-center"> | |
| <h3 class="text-md font-medium text-indigo-800">Drafts</h3> | |
| <p id="draftJobs" class="text-3xl font-bold text-indigo-600 mt-1">0</p> | |
| </div> | |
| </div> | |
| <!-- Banner Management --> | |
| <div class="glassmorphism rounded-lg p-4 mb-6"> | |
| <h2 class="text-xl font-semibold text-indigo-800 mb-3">Banner Management</h2> | |
| <div class="space-y-3"> | |
| <input type="text" id="bannerTitle" placeholder="Banner Title" | |
| class="w-full p-2 rounded-md border border-gray-300"> | |
| <input type="url" id="bannerLink" placeholder="Banner Link (URL)" | |
| class="w-full p-2 rounded-md border border-gray-300"> | |
| <input type="file" id="bannerImage" accept="image/*" class="w-full"> | |
| <button id="saveBannerBtn" | |
| class="w-full py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition"> | |
| Save Banner | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Category Management --> | |
| <div class="glassmorphism rounded-lg p-4 mb-6"> | |
| <h2 class="text-xl font-semibold text-indigo-800 mb-3">Category Management</h2> | |
| <div class="space-y-3"> | |
| <input type="text" id="categoryName" placeholder="Category Name" | |
| class="w-full p-2 rounded-md border border-gray-300"> | |
| <input type="file" id="categoryImage" accept="image/*" class="w-full"> | |
| <button id="saveCategoryBtn" | |
| class="w-full py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition"> | |
| Save Category | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Job Management --> | |
| <div class="glassmorphism rounded-lg p-4"> | |
| <h2 class="text-xl font-semibold text-indigo-800 mb-3">Job Management</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div class="space-y-3"> | |
| <input type="text" id="jobTitle" placeholder="Job Title" | |
| class="w-full p-2 rounded-md border border-gray-300"> | |
| <select id="jobCategory" class="w-full p-2 rounded-md border border-gray-300"> | |
| <option value="" disabled selected>Select Category</option> | |
| </select> | |
| <textarea id="jobDescription" placeholder="Job Description" | |
| class="w-full p-2 rounded-md border border-gray-300 h-32"></textarea> | |
| <input type="url" id="jobLink" placeholder="Apply Link (URL)" | |
| class="w-full p-2 rounded-md border border-gray-300"> | |
| <input type="file" id="jobImage" accept="image/*" class="w-full"> | |
| <div class="flex gap-2"> | |
| <button id="saveJobBtn" | |
| class="flex-1 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition"> | |
| Publish Job | |
| </button> | |
| <button id="saveDraftBtn" | |
| class="flex-1 py-2 bg-gray-500 text-white rounded-md hover:bg-gray-600 transition"> | |
| Save Draft | |
| </button> | |
| </div> | |
| </div> | |
| <div> | |
| <div class="flex flex-col md:flex-row justify-between items-center mb-3"> | |
| <h3 class="text-lg font-medium text-indigo-800">All Jobs</h3> | |
| <input type="text" id="jobSearch" placeholder="Search jobs..." | |
| class="p-2 rounded-md border border-gray-300 w-full md:w-auto"> | |
| </div> | |
| <div id="jobsList" class="space-y-3 max-h-96 overflow-y-auto pr-2"></div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Firebase configuration | |
| const firebaseConfig = { | |
| apiKey: "AIzaSyDEXAMPLEEXAMPLEEXAMPLE", | |
| authDomain: "your-project.firebaseapp.com", | |
| databaseURL: "https://your-project.firebaseio.com", | |
| projectId: "your-project", | |
| storageBucket: "your-project.appspot.com", | |
| messagingSenderId: "1234567890", | |
| appId: "1:1234567890:web:abcdef1234567890" | |
| }; | |
| // Initialize Firebase | |
| firebase.initializeApp(firebaseConfig); | |
| const auth = firebase.auth(); | |
| const database = firebase.database(); | |
| // DOM Elements | |
| const loginSection = document.getElementById('loginSection'); | |
| const dashboardSection = document.getElementById('dashboardSection'); | |
| const loginForm = document.getElementById('loginForm'); | |
| const logoutBtn = document.getElementById('logoutBtn'); | |
| const jobCategorySelect = document.getElementById('jobCategory'); | |
| const jobsList = document.getElementById('jobsList'); | |
| const jobSearch = document.getElementById('jobSearch'); | |
| const totalJobsElement = document.getElementById('totalJobs'); | |
| const publishedJobsElement = document.getElementById('publishedJobs'); | |
| const draftJobsElement = document.getElementById('draftJobs'); | |
| // Login Functionality | |
| loginForm.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| const email = document.getElementById('email').value; | |
| const password = document.getElementById('password').value; | |
| auth.signInWithEmailAndPassword(email, password) | |
| .then(() => { | |
| loginSection.classList.add('hidden'); | |
| dashboardSection.classList.remove('hidden'); | |
| loadCategories(); | |
| loadJobs(); | |
| loadStats(); | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Login Successful', | |
| showConfirmButton: false, | |
| timer: 1500 | |
| }); | |
| }) | |
| .catch((error) => { | |
| Swal.fire({ | |
| icon: 'error', | |
| title: 'Login Failed', | |
| text: error.message | |
| }); | |
| }); | |
| }); | |
| // Logout Functionality | |
| logoutBtn.addEventListener('click', () => { | |
| auth.signOut().then(() => { | |
| dashboardSection.classList.add('hidden'); | |
| loginSection.classList.remove('hidden'); | |
| loginForm.reset(); | |
| }); | |
| }); | |
| // Check Auth State | |
| auth.onAuthStateChanged((user) => { | |
| if (user) { | |
| loginSection.classList.add('hidden'); | |
| dashboardSection.classList.remove('hidden'); | |
| loadCategories(); | |
| loadJobs(); | |
| loadStats(); | |
| } else { | |
| loginSection.classList.remove('hidden'); | |
| dashboardSection.classList.add('hidden'); | |
| } | |
| }); | |
| // Load Categories | |
| function loadCategories() { | |
| database.ref('categories').on('value', (snapshot) => { | |
| jobCategorySelect.innerHTML = '<option value="" disabled selected>Select Category</option>'; | |
| snapshot.forEach((childSnapshot) => { | |
| const category = childSnapshot.val(); | |
| const option = document.createElement('option'); | |
| option.value = childSnapshot.key; | |
| option.textContent = category.name; | |
| jobCategorySelect.appendChild(option); | |
| }); | |
| }); | |
| } | |
| // Load Jobs | |
| function loadJobs() { | |
| database.ref('jobs').on('value', (snapshot) => { | |
| jobsList.innerHTML = ''; | |
| snapshot.forEach((categorySnapshot) => { | |
| categorySnapshot.forEach((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| const jobElement = document.createElement('div'); | |
| jobElement.className = 'bg-white p-3 rounded-lg shadow job-card'; | |
| jobElement.innerHTML = ` | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <h4 class="font-bold">${job.title}</h4> | |
| <p class="text-sm text-gray-500">${job.category}</p> | |
| <p class="text-sm mt-1 text-gray-700">${job.description.substring(0, 80)}...</p> | |
| </div> | |
| <div class="flex gap-1"> | |
| <button class="edit-job p-1 bg-blue-500 text-white rounded" data-id="${jobSnapshot.key}" data-cat="${categorySnapshot.key}"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" /> | |
| </svg> | |
| </button> | |
| <button class="delete-job p-1 bg-red-500 text-white rounded" data-id="${jobSnapshot.key}" data-cat="${categorySnapshot.key}"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /> | |
| </svg> | |
| </button> | |
| </div> | |
| </div> | |
| <div class="mt-2 flex justify-between items-center"> | |
| <span class="text-xs px-1.5 py-0.5 rounded ${job.status === 'published' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800'}"> | |
| ${job.status} | |
| </span> | |
| <a href="${job.link}" target="_blank" class="text-blue-500 text-xs hover:underline">View</a> | |
| </div> | |
| `; | |
| jobsList.appendChild(jobElement); | |
| }); | |
| }); | |
| addJobEventListeners(); | |
| }); | |
| } | |
| // Add Job Event Listeners | |
| function addJobEventListeners() { | |
| document.querySelectorAll('.edit-job').forEach(btn => { | |
| btn.addEventListener('click', (e) => { | |
| const jobId = e.currentTarget.getAttribute('data-id'); | |
| const catId = e.currentTarget.getAttribute('data-cat'); | |
| editJob(jobId, catId); | |
| }); | |
| }); | |
| document.querySelectorAll('.delete-job').forEach(btn => { | |
| btn.addEventListener('click', (e) => { | |
| const jobId = e.currentTarget.getAttribute('data-id'); | |
| const catId = e.currentTarget.getAttribute('data-cat'); | |
| deleteJob(jobId, catId); | |
| }); | |
| }); | |
| } | |
| // Edit Job | |
| function editJob(jobId, catId) { | |
| database.ref(`jobs/${catId}/${jobId}`).once('value').then((snapshot) => { | |
| const job = snapshot.val(); | |
| document.getElementById('jobTitle').value = job.title; | |
| document.getElementById('jobDescription').value = job.description; | |
| document.getElementById('jobLink').value = job.link; | |
| const select = document.getElementById('jobCategory'); | |
| for (let i = 0; i < select.options.length; i++) { | |
| if (select.options[i].value === catId) { | |
| select.selectedIndex = i; | |
| break; | |
| } | |
| } | |
| const saveBtn = document.getElementById('saveJobBtn'); | |
| saveBtn.textContent = 'Update Job'; | |
| saveBtn.setAttribute('data-id', jobId); | |
| saveBtn.setAttribute('data-cat', catId); | |
| saveBtn.onclick = function() { | |
| updateJob(this.getAttribute('data-id'), this.getAttribute('data-cat')); | |
| }; | |
| }); | |
| } | |
| // Update Job | |
| function updateJob(jobId, catId) { | |
| const title = document.getElementById('jobTitle').value; | |
| const category = document.getElementById('jobCategory').value; | |
| const description = document.getElementById('jobDescription').value; | |
| const link = document.getElementById('jobLink').value; | |
| if (!title || !category || !description || !link) { | |
| Swal.fire({ | |
| icon: 'error', | |
| title: 'Error', | |
| text: 'All fields are required!' | |
| }); | |
| return; | |
| } | |
| const updates = { | |
| title, | |
| category, | |
| description, | |
| link, | |
| status: 'published', | |
| updatedAt: firebase.database.ServerValue.TIMESTAMP | |
| }; | |
| database.ref(`jobs/${catId}/${jobId}`).update(updates) | |
| .then(() => { | |
| resetJobForm(); | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Success', | |
| text: 'Job updated successfully!' | |
| }); | |
| }) | |
| .catch((error) => { | |
| Swal.fire({ | |
| icon: 'error', | |
| title: 'Error', | |
| text: error.message | |
| }); | |
| }); | |
| } | |
| // Delete Job | |
| function deleteJob(jobId, catId) { | |
| Swal.fire({ | |
| title: 'Are you sure?', | |
| text: "You won't be able to revert this!", | |
| icon: 'warning', | |
| showCancelButton: true, | |
| confirmButtonColor: '#3085d6', | |
| cancelButtonColor: '#d33', | |
| confirmButtonText: 'Yes, delete it!' | |
| }).then((result) => { | |
| if (result.isConfirmed) { | |
| database.ref(`jobs/${catId}/${jobId}`).remove() | |
| .then(() => { | |
| Swal.fire('Deleted!', 'Job has been deleted.', 'success'); | |
| }) | |
| .catch((error) => { | |
| Swal.fire('Error', error.message, 'error'); | |
| }); | |
| } | |
| }); | |
| } | |
| // Save Job | |
| document.getElementById('saveJobBtn').addEventListener('click', () => { | |
| const title = document.getElementById('jobTitle').value; | |
| const category = document.getElementById('jobCategory').value; | |
| const description = document.getElementById('jobDescription').value; | |
| const link = document.getElementById('jobLink').value; | |
| if (!title || !category || !description || !link) { | |
| Swal.fire('Error', 'All fields are required!', 'error'); | |
| return; | |
| } | |
| const newJob = { | |
| title, | |
| category, | |
| description, | |
| link, | |
| status: 'published', | |
| createdAt: firebase.database.ServerValue.TIMESTAMP, | |
| updatedAt: firebase.database.ServerValue.TIMESTAMP | |
| }; | |
| const newJobKey = database.ref().child('jobs').child(category).push().key; | |
| const updates = {}; | |
| updates[`/jobs/${category}/${newJobKey}`] = newJob; | |
| database.ref().update(updates) | |
| .then(() => { | |
| resetJobForm(); | |
| Swal.fire('Success', 'Job published successfully!', 'success'); | |
| }) | |
| .catch((error) => { | |
| Swal.fire('Error', error.message, 'error'); | |
| }); | |
| }); | |
| // Save as Draft | |
| document.getElementById('saveDraftBtn').addEventListener('click', () => { | |
| const title = document.getElementById('jobTitle').value; | |
| const category = document.getElementById('jobCategory').value; | |
| const description = document.getElementById('jobDescription').value; | |
| const link = document.getElementById('jobLink').value; | |
| if (!title || !category || !description || !link) { | |
| Swal.fire('Error', 'All fields are required!', 'error'); | |
| return; | |
| } | |
| const newJob = { | |
| title, | |
| category, | |
| description, | |
| link, | |
| status: 'draft', | |
| createdAt: firebase.database.ServerValue.TIMESTAMP, | |
| updatedAt: firebase.database.ServerValue.TIMESTAMP | |
| }; | |
| const newJobKey = database.ref().child('jobs').child(category).push().key; | |
| const updates = {}; | |
| updates[`/jobs/${category}/${newJobKey}`] = newJob; | |
| database.ref().update(updates) | |
| .then(() => { | |
| resetJobForm(); | |
| Swal.fire('Success', 'Job saved as draft!', 'success'); | |
| }) | |
| .catch((error) => { | |
| Swal.fire('Error', error.message, 'error'); | |
| }); | |
| }); | |
| // Save Category | |
| document.getElementById('saveCategoryBtn').addEventListener('click', () => { | |
| const name = document.getElementById('categoryName').value; | |
| if (!name) { | |
| Swal.fire('Error', 'Category name is required!', 'error'); | |
| return; | |
| } | |
| const newCategory = { | |
| name, | |
| createdAt: firebase.database.ServerValue.TIMESTAMP | |
| }; | |
| const newCategoryKey = database.ref().child('categories').push().key; | |
| const updates = {}; | |
| updates[`/categories/${newCategoryKey}`] = newCategory; | |
| database.ref().update(updates) | |
| .then(() => { | |
| document.getElementById('categoryName').value = ''; | |
| Swal.fire('Success', 'Category added successfully!', 'success'); | |
| }) | |
| .catch((error) => { | |
| Swal.fire('Error', error.message, 'error'); | |
| }); | |
| }); | |
| // Save Banner | |
| document.getElementById('saveBannerBtn').addEventListener('click', () => { | |
| const title = document.getElementById('bannerTitle').value; | |
| const link = document.getElementById('bannerLink').value; | |
| if (!title || !link) { | |
| Swal.fire('Error', 'Title and link are required!', 'error'); | |
| return; | |
| } | |
| const newBanner = { | |
| title, | |
| link, | |
| createdAt: firebase.database.ServerValue.TIMESTAMP | |
| }; | |
| const newBannerKey = database.ref().child('banners').push().key; | |
| const updates = {}; | |
| updates[`/banners/${newBannerKey}`] = newBanner; | |
| database.ref().update(updates) | |
| .then(() => { | |
| document.getElementById('bannerTitle').value = ''; | |
| document.getElementById('bannerLink').value = ''; | |
| Swal.fire('Success', 'Banner added successfully!', 'success'); | |
| }) | |
| .catch((error) => { | |
| Swal.fire('Error', error.message, 'error'); | |
| }); | |
| }); | |
| // Load Stats | |
| function loadStats() { | |
| database.ref('jobs').on('value', (snapshot) => { | |
| let total = 0; | |
| let published = 0; | |
| let draft = 0; | |
| snapshot.forEach((categorySnapshot) => { | |
| categorySnapshot.forEach((jobSnapshot) => { | |
| total++; | |
| if (jobSnapshot.val().status === 'published') { | |
| published++; | |
| } else { | |
| draft++; | |
| } | |
| }); | |
| }); | |
| totalJobsElement.textContent = total; | |
| publishedJobsElement.textContent = published; | |
| draftJobsElement.textContent = draft; | |
| }); | |
| } | |
| // Reset Job Form | |
| function resetJobForm() { | |
| document.getElementById('jobTitle').value = ''; | |
| document.getElementById('jobDescription').value = ''; | |
| document.getElementById('jobLink').value = ''; | |
| document.getElementById('jobImage').value = ''; | |
| const saveBtn = document.getElementById('saveJobBtn'); | |
| saveBtn.textContent = 'Publish Job'; | |
| saveBtn.onclick = function() { | |
| document.getElementById('saveJobBtn').click(); | |
| }; | |
| } | |
| </script> | |
| </body> | |
| </html> |