sleekheader-supreme / admin.html
matheusbezerra1's picture
ok, how to access the admin page?
49dafe6 verified
Raw History Blame Contribute Delete
14.9 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard | Luxury Estates</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.tailwindcss.com"></script>
<script src="components/admin-header.js"></script>
</head>
<body class="bg-gray-100 min-h-screen">
<admin-header></admin-header>
<main class="max-w-7xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold text-gray-900 mb-8">Admin Dashboard</h1>
<div class="grid gap-8 md:grid-cols-3 mb-12">
<!-- Stats Cards -->
<div class="bg-white p-6 rounded-lg shadow">
<h3 class="text-lg font-medium text-gray-900">Total Properties</h3>
<p class="mt-2 text-3xl font-bold text-blue-600" id="totalProperties">0</p>
</div>
<div class="bg-white p-6 rounded-lg shadow">
<h3 class="text-lg font-medium text-gray-900">Total Users</h3>
<p class="mt-2 text-3xl font-bold text-blue-600" id="totalUsers">0</p>
</div>
<div class="bg-white p-6 rounded-lg shadow">
<h3 class="text-lg font-medium text-gray-900">Total Blog Posts</h3>
<p class="mt-2 text-3xl font-bold text-blue-600" id="totalBlogs">0</p>
</div>
</div>
<!-- Tabs -->
<div class="border-b border-gray-200 mb-8">
<nav class="-mb-px flex space-x-8">
<button id="propertiesTab" class="border-b-2 border-blue-500 text-blue-600 px-4 py-4 text-sm font-medium">Properties</button>
<button id="usersTab" class="border-b-2 border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 px-4 py-4 text-sm font-medium">Users</button>
<button id="blogsTab" class="border-b-2 border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 px-4 py-4 text-sm font-medium">Blog Posts</button>
</nav>
</div>
<!-- Content Sections -->
<div id="propertiesSection">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-gray-900">Manage Properties</h2>
<a href="/add-property.html" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700">
Add New Property
</a>
</div>
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Title</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Location</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="propertiesTableBody" class="bg-white divide-y divide-gray-200">
<!-- Properties will be loaded here via JavaScript -->
</tbody>
</table>
</div>
</div>
<div id="usersSection" class="hidden">
<h2 class="text-2xl font-bold text-gray-900 mb-6">Manage Users</h2>
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="usersTableBody" class="bg-white divide-y divide-gray-200">
<!-- Users will be loaded here via JavaScript -->
</tbody>
</table>
</div>
</div>
<div id="blogsSection" class="hidden">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-gray-900">Manage Blog Posts</h2>
<a href="/add-blog.html" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700">
Add New Post
</a>
</div>
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Title</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Author</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="blogsTableBody" class="bg-white divide-y divide-gray-200">
<!-- Blog posts will be loaded here via JavaScript -->
</tbody>
</table>
</div>
</div>
</main>
<script src="script.js"></script>
<script>
// Tab switching
document.getElementById('propertiesTab').addEventListener('click', () => {
document.getElementById('propertiesSection').classList.remove('hidden');
document.getElementById('usersSection').classList.add('hidden');
document.getElementById('blogsSection').classList.add('hidden');
updateActiveTab('propertiesTab');
});
document.getElementById('usersTab').addEventListener('click', () => {
document.getElementById('propertiesSection').classList.add('hidden');
document.getElementById('usersSection').classList.remove('hidden');
document.getElementById('blogsSection').classList.add('hidden');
updateActiveTab('usersTab');
});
document.getElementById('blogsTab').addEventListener('click', () => {
document.getElementById('propertiesSection').classList.add('hidden');
document.getElementById('usersSection').classList.add('hidden');
document.getElementById('blogsSection').classList.remove('hidden');
updateActiveTab('blogsTab');
});
function updateActiveTab(activeTabId) {
const tabs = ['propertiesTab', 'usersTab', 'blogsTab'];
tabs.forEach(tabId => {
const tab = document.getElementById(tabId);
if (tabId === activeTabId) {
tab.classList.add('border-blue-500', 'text-blue-600');
tab.classList.remove('border-transparent', 'text-gray-500', 'hover:text-gray-700', 'hover:border-gray-300');
} else {
tab.classList.remove('border-blue-500', 'text-blue-600');
tab.classList.add('border-transparent', 'text-gray-500', 'hover:text-gray-700', 'hover:border-gray-300');
}
});
}
// Load admin data
document.addEventListener('DOMContentLoaded', () => {
// Check authentication
const token = localStorage.getItem('authToken');
if (!token) {
window.location.href = '/login.html';
return;
}
// For demo purposes, allow access to admin page
loadAdminData();
});
async function loadAdminData() {
try {
// In a real app, these would be API calls
const properties = await fetchProperties();
const users = await fetchUsers();
const blogs = await fetchBlogs();
// Update stats
document.getElementById('totalProperties').textContent = properties.length;
document.getElementById('totalUsers').textContent = users.length;
document.getElementById('totalBlogs').textContent = blogs.length;
// Populate tables
populatePropertiesTable(properties);
populateUsersTable(users);
populateBlogsTable(blogs);
} catch (error) {
console.error('Error loading admin data:', error);
alert('Failed to load admin data. Please try again later.');
}
}
// Mock functions - replace with real API calls
async function fetchProperties() {
return [
{ id: 1, title: 'Seaside Modern Villa', location: 'Malibu, California', price: '$12,500,000' },
{ id: 2, title: 'Manhattan Penthouse', location: 'New York, NY', price: '$8,750,000' },
{ id: 3, title: 'English Country Estate', location: 'Cotswolds, UK', price: '£15,000,000' }
];
}
async function fetchUsers() {
return [
{ id: 1, name: 'Admin User', email: 'admin@luxuryestates.com', role: 'admin' },
{ id: 2, name: 'John Doe', email: 'john@example.com', role: 'user' },
{ id: 3, name: 'Jane Smith', email: 'jane@example.com', role: 'user' }
];
}
async function fetchBlogs() {
return [
{ id: 1, title: 'Luxury Market Trends 2023', author: 'Admin User', date: '2023-05-15' },
{ id: 2, title: 'Top 5 Luxury Destinations', author: 'Jane Smith', date: '2023-04-22' }
];
}
function populatePropertiesTable(properties) {
const tbody = document.getElementById('propertiesTableBody');
tbody.innerHTML = properties.map(property => `
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${property.title}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${property.location}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${property.price}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<a href="/edit-property.html?id=${property.id}" class="text-blue-600 hover:text-blue-900 mr-4">Edit</a>
<button class="text-red-600 hover:text-red-900" onclick="deleteProperty(${property.id})">Delete</button>
</td>
</tr>
`).join('');
}
function populateUsersTable(users) {
const tbody = document.getElementById('usersTableBody');
tbody.innerHTML = users.map(user => `
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${user.name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${user.email}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${user.role}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button class="text-blue-600 hover:text-blue-900 mr-4" onclick="editUser(${user.id})">Edit</button>
<button class="text-red-600 hover:text-red-900" onclick="deleteUser(${user.id})">Delete</button>
</td>
</tr>
`).join('');
}
function populateBlogsTable(blogs) {
const tbody = document.getElementById('blogsTableBody');
tbody.innerHTML = blogs.map(blog => `
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${blog.title}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${blog.author}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${blog.date}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<a href="/edit-blog.html?id=${blog.id}" class="text-blue-600 hover:text-blue-900 mr-4">Edit</a>
<button class="text-red-600 hover:text-red-900" onclick="deleteBlog(${blog.id})">Delete</button>
</td>
</tr>
`).join('');
}
// Action functions
function deleteProperty(id) {
if (confirm('Are you sure you want to delete this property?')) {
console.log('Deleting property', id);
// In a real app, this would call the API
alert('Property deleted successfully');
loadAdminData();
}
}
function editUser(id) {
console.log('Editing user', id);
// In a real app, this would open an edit modal or page
}
function deleteUser(id) {
if (confirm('Are you sure you want to delete this user?')) {
console.log('Deleting user', id);
// In a real app, this would call the API
alert('User deleted successfully');
loadAdminData();
}
}
function deleteBlog(id) {
if (confirm('Are you sure you want to delete this blog post?')) {
console.log('Deleting blog post', id);
// In a real app, this would call the API
alert('Blog post deleted successfully');
loadAdminData();
}
}
</script>
</body>
</html>