Fix admin route access and backend configuration
- Added /admin redirect to login page in nginx config - Fixed backend server.js route ordering for proper admin handling - Updated authentication middleware and routes - Added user management routes - Configured PostgreSQL integration - Updated environment configuration
This commit is contained in:
45
Views/Admin/ChangePassword.cshtml
Executable file
45
Views/Admin/ChangePassword.cshtml
Executable file
@@ -0,0 +1,45 @@
|
||||
@{
|
||||
Layout = "~/Views/Shared/_AdminLayout.cshtml";
|
||||
ViewData["Title"] = "Change Password";
|
||||
}
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">Change Your Password</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (ViewBag.Error != null)
|
||||
{
|
||||
<div class="alert alert-danger">@ViewBag.Error</div>
|
||||
}
|
||||
|
||||
<form method="post" action="/admin/change-password">
|
||||
<div class="mb-3">
|
||||
<label for="currentPassword" class="form-label">Current Password</label>
|
||||
<input type="password" class="form-control" id="currentPassword" name="currentPassword" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="newPassword" class="form-label">New Password</label>
|
||||
<input type="password" class="form-control" id="newPassword" name="newPassword" required minlength="6">
|
||||
<small class="form-text text-muted">At least 6 characters</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="confirmPassword" class="form-label">Confirm New Password</label>
|
||||
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" required>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="/admin/dashboard" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Change Password</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
189
Views/Admin/Dashboard.cshtml
Executable file
189
Views/Admin/Dashboard.cshtml
Executable file
@@ -0,0 +1,189 @@
|
||||
@{
|
||||
ViewData["Title"] = "Dashboard";
|
||||
Layout = "_AdminLayout";
|
||||
}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/products" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body">
|
||||
<h6 class="text-muted">Total Products</h6>
|
||||
<h2 class="mb-0">@ViewBag.ProductCount</h2>
|
||||
<span class="stat-link">Manage →</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/portfolio/projects" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body">
|
||||
<h6 class="text-muted">Portfolio Projects</h6>
|
||||
<h2 class="mb-0">@ViewBag.ProjectCount</h2>
|
||||
<span class="stat-link">Manage →</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/blog" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body">
|
||||
<h6 class="text-muted">Blog Posts</h6>
|
||||
<h2 class="mb-0">@ViewBag.BlogCount</h2>
|
||||
<span class="stat-link">Manage →</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/pages" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body">
|
||||
<h6 class="text-muted">Custom Pages</h6>
|
||||
<h2 class="mb-0">@ViewBag.PageCount</h2>
|
||||
<span class="stat-link">Manage →</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/homepage" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body text-center">
|
||||
<i class="bi bi-house-fill" style="font-size: 2.5rem; color: #28a745;"></i>
|
||||
<h6 class="mt-3 mb-0">Homepage Editor</h6>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/products/create" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body text-center">
|
||||
<i class="bi bi-plus-circle" style="font-size: 2.5rem; color: #3498db;"></i>
|
||||
<h6 class="mt-3 mb-0">Add New Product</h6>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/blog/create" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body text-center">
|
||||
<i class="bi bi-plus-circle" style="font-size: 2.5rem; color: #3498db;"></i>
|
||||
<h6 class="mt-3 mb-0">Create Blog Post</h6>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a href="/admin/portfolio/projects/create" class="text-decoration-none">
|
||||
<div class="card dashboard-stat-card">
|
||||
<div class="card-body text-center">
|
||||
<i class="bi bi-plus-circle" style="font-size: 2.5rem; color: #3498db;"></i>
|
||||
<h6 class="mt-3 mb-0">Add Portfolio Project</h6>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-5">
|
||||
<div class="col-md-4">
|
||||
<div class="card system-info-card">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0"><i class="bi bi-info-circle-fill"></i> System Information</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<strong><i class="bi bi-globe"></i> Site Name:</strong><br>
|
||||
<span class="text-muted">@ViewBag.SiteName</span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong><i class="bi bi-database-fill"></i> Database:</strong><br>
|
||||
<span id="dbStatus" class="badge bg-secondary">
|
||||
<span class="spinner-border spinner-border-sm"></span> Checking...
|
||||
</span>
|
||||
<small id="dbInfo" class="d-block text-muted mt-1"></small>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong><i class="bi bi-person-circle"></i> Admin User:</strong><br>
|
||||
<span class="text-muted">@ViewBag.AdminEmail</span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong><i class="bi bi-clock-fill"></i> Server Time:</strong><br>
|
||||
<span id="serverTime" class="text-muted">@DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")</span>
|
||||
</div>
|
||||
<div>
|
||||
<strong><i class="bi bi-hdd-fill"></i> System:</strong><br>
|
||||
<span id="systemStatus" class="badge bg-success">
|
||||
<i class="bi bi-check-circle-fill"></i> Online
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
// Update server time every second
|
||||
function updateServerTime() {
|
||||
const timeEl = document.getElementById('serverTime');
|
||||
if (timeEl) {
|
||||
const now = new Date();
|
||||
timeEl.textContent = now.toLocaleString('en-US', {
|
||||
month: 'short',
|
||||
day: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Check database connection status
|
||||
async function checkDatabaseStatus() {
|
||||
const statusEl = document.getElementById('dbStatus');
|
||||
const infoEl = document.getElementById('dbInfo');
|
||||
|
||||
try {
|
||||
const response = await fetch('/admin/system-status');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.databaseConnected) {
|
||||
statusEl.className = 'badge bg-success';
|
||||
statusEl.innerHTML = '<i class="bi bi-check-circle-fill"></i> PostgreSQL Connected';
|
||||
infoEl.innerHTML = `Host: ${data.dbHost || 'localhost'} | Database: ${data.dbName || 'skyartshop'}`;
|
||||
} else {
|
||||
statusEl.className = 'badge bg-danger';
|
||||
statusEl.innerHTML = '<i class="bi bi-x-circle-fill"></i> Database Disconnected';
|
||||
infoEl.textContent = data.error || 'Connection failed';
|
||||
}
|
||||
} catch (error) {
|
||||
statusEl.className = 'badge bg-warning';
|
||||
statusEl.innerHTML = '<i class="bi bi-exclamation-triangle-fill"></i> Status Unknown';
|
||||
infoEl.textContent = 'Unable to check status';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize on page load
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
updateServerTime();
|
||||
checkDatabaseStatus();
|
||||
|
||||
// Update time every second
|
||||
setInterval(updateServerTime, 1000);
|
||||
|
||||
// Check database status every 10 seconds
|
||||
setInterval(checkDatabaseStatus, 10000);
|
||||
});
|
||||
</script>
|
||||
}
|
||||
430
Views/Admin/Login.cshtml
Executable file
430
Views/Admin/Login.cshtml
Executable file
@@ -0,0 +1,430 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-bs-theme="light">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="color-scheme" content="light">
|
||||
<title>SkyArt - @ViewData["Title"]</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" data-theme="light">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light !important;
|
||||
}
|
||||
|
||||
html {
|
||||
color-scheme: light !important;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow-x: hidden;
|
||||
background-color: #f8f9fa !important;
|
||||
color: #212529 !important;
|
||||
color-scheme: light !important;
|
||||
}
|
||||
|
||||
/* Force all Bootstrap components to light mode */
|
||||
* {
|
||||
color-scheme: light !important;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
background-color: #ffffff !important;
|
||||
color: #212529 !important;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: #ffffff !important;
|
||||
color: #212529 !important;
|
||||
}
|
||||
|
||||
.table {
|
||||
background-color: #ffffff !important;
|
||||
color: #212529 !important;
|
||||
}
|
||||
|
||||
input, textarea, select {
|
||||
background-color: #ffffff !important;
|
||||
color: #212529 !important;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
height: 100vh;
|
||||
background: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
|
||||
color: white;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 250px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar-track {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar-thumb {
|
||||
background: rgba(52, 152, 219, 0.6);
|
||||
border-radius: 10px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(52, 152, 219, 1);
|
||||
}
|
||||
|
||||
/* Firefox scrollbar */
|
||||
.sidebar {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: rgba(52, 152, 219, 0.6) rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.sidebar .brand {
|
||||
padding: 20px;
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: linear-gradient(180deg, #2c3e50 0%, #243442 100%);
|
||||
z-index: 10;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.sidebar nav {
|
||||
padding: 10px 0 30px 0;
|
||||
}
|
||||
|
||||
.sidebar hr {
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.sidebar .section-label {
|
||||
padding: 15px 20px 5px 20px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.sidebar .nav-link {
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
padding: 12px 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: all 0.3s ease;
|
||||
border-left: 3px solid transparent;
|
||||
text-decoration: none;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sidebar .nav-link:hover {
|
||||
background: rgba(52, 152, 219, 0.15);
|
||||
color: white;
|
||||
border-left-color: #3498db;
|
||||
padding-left: 25px;
|
||||
}
|
||||
|
||||
.sidebar .nav-link.active {
|
||||
background: rgba(52, 152, 219, 0.25);
|
||||
color: white;
|
||||
border-left-color: #3498db;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sidebar .nav-link.active::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 3px;
|
||||
background: #3498db;
|
||||
box-shadow: 0 0 10px #3498db;
|
||||
}
|
||||
|
||||
.sidebar .nav-link i {
|
||||
margin-right: 12px;
|
||||
width: 20px;
|
||||
font-size: 1.1rem;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar .nav-link:hover i {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
.main-content {
|
||||
margin-left: 250px;
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.top-bar {
|
||||
background: white;
|
||||
padding: 15px 30px;
|
||||
margin: -20px -20px 20px -20px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card {
|
||||
border: none;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.dashboard-stat-card {
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
border-left: 4px solid transparent;
|
||||
}
|
||||
|
||||
.dashboard-stat-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
||||
border-left-color: #3498db;
|
||||
}
|
||||
|
||||
.dashboard-stat-card h6 {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.dashboard-stat-card h2 {
|
||||
color: #2c3e50;
|
||||
font-weight: 700;
|
||||
font-size: 2.5rem;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.stat-link {
|
||||
color: #3498db;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.dashboard-stat-card:hover .stat-link {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.system-info-card {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.system-info-card .card-header {
|
||||
background: transparent;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.system-info-card .card-body p {
|
||||
color: rgba(255, 255, 255, 0.95);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.btn-group-sm .btn {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.alert {
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
/* Scroll indicator */
|
||||
.scroll-indicator {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 40px;
|
||||
background: linear-gradient(to top, #1a252f 0%, transparent 100%);
|
||||
pointer-events: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.scroll-indicator.hidden {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.scroll-indicator i {
|
||||
color: rgba(52, 152, 219, 0.8);
|
||||
font-size: 1.5rem;
|
||||
animation: bounce 2s infinite;
|
||||
}
|
||||
|
||||
@@keyframes bounce {
|
||||
0%, 20%, 50%, 80%, 100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
40% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
60% {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobile responsive */
|
||||
@@media (max-width: 768px) {
|
||||
.sidebar {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="sidebar">
|
||||
<div class="brand">
|
||||
<i class="bi bi-shop"></i> Sky Art Shop
|
||||
</div>
|
||||
<nav class="nav flex-column">
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Action"]?.ToString() == "Dashboard" ? "active" : "")"
|
||||
href="/admin/dashboard">
|
||||
<i class="bi bi-speedometer2"></i> Dashboard
|
||||
</a>
|
||||
|
||||
<div class="section-label">
|
||||
<i class="bi bi-folder"></i> CONTENT
|
||||
</div>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminPages" ? "active" : "")"
|
||||
href="/admin/pages">
|
||||
<i class="bi bi-file-earmark-text"></i> Pages
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminBlog" ? "active" : "")"
|
||||
href="/admin/blog">
|
||||
<i class="bi bi-journal-text"></i> Blog
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminPortfolio" ? "active" : "")"
|
||||
href="/admin/portfolio/categories">
|
||||
<i class="bi bi-images"></i> Portfolio
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminProducts" ? "active" : "")"
|
||||
href="/admin/products">
|
||||
<i class="bi bi-cart"></i> Products
|
||||
</a>
|
||||
|
||||
<div class="section-label">
|
||||
<i class="bi bi-gear"></i> SETTINGS
|
||||
</div>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminUsers" ? "active" : "")"
|
||||
href="/admin/users">
|
||||
<i class="bi bi-people"></i> User Management
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminHomepage" ? "active" : "")"
|
||||
href="/admin/homepage">
|
||||
<i class="bi bi-house-fill"></i> Homepage Editor
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminMenu" ? "active" : "")"
|
||||
href="/admin/menu">
|
||||
<i class="bi bi-list"></i> Navigation Menu
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminSettings" ? "active" : "")"
|
||||
href="/admin/settings">
|
||||
<i class="bi bi-gear"></i> Site Settings
|
||||
</a>
|
||||
<a class="nav-link @(ViewContext.RouteData.Values["Controller"]?.ToString() == "AdminUpload" ? "active" : "")"
|
||||
href="/admin/upload">
|
||||
<i class="bi bi-cloud-upload"></i> Media Upload
|
||||
</a>
|
||||
|
||||
<div class="section-label">
|
||||
<i class="bi bi-layout-sidebar"></i> SYSTEM
|
||||
</div>
|
||||
<a class="nav-link" href="/" target="_blank">
|
||||
<i class="bi bi-box-arrow-up-right"></i> View Site
|
||||
</a>
|
||||
<a class="nav-link" href="/admin/logout">
|
||||
<i class="bi bi-box-arrow-right"></i> Logout
|
||||
</a>
|
||||
</nav>
|
||||
<div class="scroll-indicator" id="scrollIndicator">
|
||||
<i class="bi bi-chevron-down"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="top-bar">
|
||||
<h4 class="mb-0">@ViewData["Title"]</h4>
|
||||
<div>
|
||||
<span class="text-muted">Welcome, Admin</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<partial name="_AdminAlerts" />
|
||||
|
||||
@RenderBody()
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/40.1.0/classic/ckeditor.js"></script>
|
||||
<script src="~/assets/js/admin.js"></script>
|
||||
|
||||
<script>
|
||||
// Sidebar scroll indicator
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const sidebar = document.querySelector('.sidebar');
|
||||
const scrollIndicator = document.getElementById('scrollIndicator');
|
||||
|
||||
if (sidebar && scrollIndicator) {
|
||||
function updateScrollIndicator() {
|
||||
const isAtBottom = sidebar.scrollHeight - sidebar.scrollTop <= sidebar.clientHeight + 10;
|
||||
if (isAtBottom) {
|
||||
scrollIndicator.classList.add('hidden');
|
||||
} else {
|
||||
scrollIndicator.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Check on scroll
|
||||
sidebar.addEventListener('scroll', updateScrollIndicator);
|
||||
|
||||
// Initial check
|
||||
updateScrollIndicator();
|
||||
|
||||
// Check after window resize
|
||||
window.addEventListener('resize', updateScrollIndicator);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
|
||||
</html>
|
||||
430
Views/Admin/Settings.cshtml
Executable file
430
Views/Admin/Settings.cshtml
Executable file
@@ -0,0 +1,430 @@
|
||||
<!-- Product Variant Manager Modal -->
|
||||
<div class="modal fade" id="variantManagerModal" tabindex="-1" aria-labelledby="variantManagerLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-primary text-white">
|
||||
<h5 class="modal-title" id="variantManagerLabel">
|
||||
<i class="bi bi-palette"></i> Manage Color Variants
|
||||
</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="alert alert-info">
|
||||
<i class="bi bi-info-circle"></i> <strong>How it works:</strong> Create color variants and assign specific images to each color. Customers will see the assigned images when they select a color on the product page.
|
||||
</div>
|
||||
|
||||
<!-- Variant List -->
|
||||
<div id="variantList" class="mb-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h6 class="mb-0">Color Variants (<span id="variantCount">0</span>)</h6>
|
||||
<button type="button" class="btn btn-sm btn-success" onclick="addNewVariant()">
|
||||
<i class="bi bi-plus-circle"></i> Add Color Variant
|
||||
</button>
|
||||
</div>
|
||||
<div id="variantsContainer">
|
||||
<!-- Variants will be added here -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add/Edit Variant Form -->
|
||||
<div id="variantForm" style="display: none;" class="border rounded p-3 bg-light">
|
||||
<h6 class="mb-3">
|
||||
<span id="formTitle">Add New Variant</span>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary float-end" onclick="cancelVariantForm()">
|
||||
<i class="bi bi-x"></i> Cancel
|
||||
</button>
|
||||
</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Color Name *</label>
|
||||
<input type="text" id="variantColorName" class="form-control" placeholder="e.g., Ocean Blue, Cherry Red">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Color Hex Code *</label>
|
||||
<div class="input-group">
|
||||
<input type="color" id="variantColorPicker" class="form-control form-control-color" value="#3498db">
|
||||
<input type="text" id="variantColorHex" class="form-control" value="#3498db" pattern="^#[0-9A-Fa-f]{6}$">
|
||||
</div>
|
||||
<small class="text-muted">Click the color box to open the color picker</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Stock Quantity</label>
|
||||
<input type="number" id="variantStock" class="form-control" value="0" min="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Price Adjustment</label>
|
||||
<input type="number" step="0.01" id="variantPriceAdjust" class="form-control" placeholder="0.00">
|
||||
<small class="text-muted">Optional: +/- from base price</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Variant SKU</label>
|
||||
<input type="text" id="variantSKU" class="form-control" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Assign Images to This Color *</label>
|
||||
<div class="d-flex gap-2 align-items-center mb-2">
|
||||
<button type="button" class="btn btn-sm btn-primary" onclick="selectVariantImages()">
|
||||
<i class="bi bi-images"></i> Select Images
|
||||
</button>
|
||||
<span class="text-muted" id="variantImageCount">No images selected</span>
|
||||
</div>
|
||||
<div id="variantImagePreview" class="d-flex flex-wrap gap-2">
|
||||
<!-- Selected images will appear here -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="variantAvailable" checked>
|
||||
<label class="form-check-label" for="variantAvailable">
|
||||
Available for purchase
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="button" class="btn btn-success" onclick="saveVariant()">
|
||||
<i class="bi bi-check-circle"></i> <span id="saveButtonText">Add Variant</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary" onclick="applyVariants()">
|
||||
<i class="bi bi-save"></i> Apply Changes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.variant-card {
|
||||
border: 2px solid #dee2e6;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
transition: all 0.3s;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.variant-card:hover {
|
||||
border-color: #3498db;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.variant-color-swatch {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid #ddd;
|
||||
display: inline-block;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.variant-image-thumb {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.predefined-color-btn {
|
||||
width: 35px;
|
||||
height: 35px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid #ddd;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
display: inline-block;
|
||||
margin: 3px;
|
||||
}
|
||||
|
||||
.predefined-color-btn:hover {
|
||||
transform: scale(1.15);
|
||||
border-color: #3498db;
|
||||
}
|
||||
|
||||
.predefined-color-btn.selected {
|
||||
border: 3px solid #3498db;
|
||||
box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
let productVariants = [];
|
||||
let currentEditIndex = -1;
|
||||
let currentVariantImages = [];
|
||||
let availableProductImages = [];
|
||||
|
||||
// Initialize variant manager with existing data
|
||||
function initVariantManager(existingVariants, productImages) {
|
||||
productVariants = existingVariants || [];
|
||||
availableProductImages = productImages || [];
|
||||
|
||||
// Store product images globally for image picker
|
||||
window.currentProductImages = productImages || [];
|
||||
|
||||
renderVariantList();
|
||||
}
|
||||
|
||||
// Render variant list
|
||||
function renderVariantList() {
|
||||
const container = document.getElementById('variantsContainer');
|
||||
document.getElementById('variantCount').textContent = productVariants.length;
|
||||
|
||||
if (productVariants.length === 0) {
|
||||
container.innerHTML = '<p class="text-muted text-center py-3">No color variants added yet. Click "Add Color Variant" to get started.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = productVariants.map((variant, index) => {
|
||||
const colorHex = variant.ColorHex || variant.colorHex || '#cccccc';
|
||||
const colorName = variant.ColorName || variant.colorName || 'Unknown';
|
||||
const images = variant.Images || variant.images || [];
|
||||
const stockQty = variant.StockQuantity ?? variant.stockQuantity ?? 0;
|
||||
const isAvailable = variant.IsAvailable ?? variant.isAvailable ?? true;
|
||||
|
||||
return `
|
||||
<div class="variant-card">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-auto">
|
||||
<div class="variant-color-swatch" style="background-color: ${colorHex};" title="${colorName}"></div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h6 class="mb-1">${colorName}</h6>
|
||||
<small class="text-muted">
|
||||
${images.length} images |
|
||||
Stock: ${stockQty} |
|
||||
${isAvailable ? '<span class="badge bg-success">Available</span>' : '<span class="badge bg-danger">Unavailable</span>'}
|
||||
</small>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<div class="d-flex flex-wrap gap-1">
|
||||
${images.slice(0, 3).map(img =>
|
||||
`<img src="${img}" class="variant-image-thumb" alt="${colorName}">`
|
||||
).join('')}
|
||||
${images.length > 3 ? `<span class="badge bg-secondary align-self-center">+${images.length - 3}</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button class="btn btn-sm btn-outline-primary" onclick="editVariant(${index})">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteVariant(${index})">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// Add new variant
|
||||
function addNewVariant() {
|
||||
currentEditIndex = -1;
|
||||
currentVariantImages = [];
|
||||
document.getElementById('formTitle').textContent = 'Add New Variant';
|
||||
document.getElementById('saveButtonText').textContent = 'Add Variant';
|
||||
|
||||
// Reset form
|
||||
document.getElementById('variantColorName').value = '';
|
||||
document.getElementById('variantColorPicker').value = '#3498db';
|
||||
document.getElementById('variantColorHex').value = '#3498db';
|
||||
document.getElementById('variantStock').value = '0';
|
||||
document.getElementById('variantPriceAdjust').value = '';
|
||||
document.getElementById('variantSKU').value = '';
|
||||
document.getElementById('variantAvailable').checked = true;
|
||||
document.getElementById('variantImagePreview').innerHTML = '';
|
||||
document.getElementById('variantImageCount').textContent = 'No images selected';
|
||||
|
||||
document.getElementById('variantForm').style.display = 'block';
|
||||
}
|
||||
|
||||
// Edit variant
|
||||
function editVariant(index) {
|
||||
currentEditIndex = index;
|
||||
const variant = productVariants[index];
|
||||
|
||||
// Handle both uppercase and lowercase property names
|
||||
const colorName = variant.ColorName || variant.colorName || '';
|
||||
const colorHex = variant.ColorHex || variant.colorHex || '#3498db';
|
||||
const images = variant.Images || variant.images || [];
|
||||
const stockQty = variant.StockQuantity ?? variant.stockQuantity ?? 0;
|
||||
const priceAdj = variant.PriceAdjustment ?? variant.priceAdjustment ?? null;
|
||||
const sku = variant.SKU || variant.sku || '';
|
||||
const isAvailable = variant.IsAvailable ?? variant.isAvailable ?? true;
|
||||
|
||||
currentVariantImages = [...images];
|
||||
|
||||
document.getElementById('formTitle').textContent = 'Edit Variant';
|
||||
document.getElementById('saveButtonText').textContent = 'Update Variant';
|
||||
|
||||
document.getElementById('variantColorName').value = colorName;
|
||||
document.getElementById('variantColorPicker').value = colorHex;
|
||||
document.getElementById('variantColorHex').value = colorHex;
|
||||
document.getElementById('variantStock').value = stockQty;
|
||||
document.getElementById('variantPriceAdjust').value = priceAdj || '';
|
||||
document.getElementById('variantSKU').value = sku;
|
||||
document.getElementById('variantAvailable').checked = isAvailable;
|
||||
|
||||
updateVariantImagePreview();
|
||||
document.getElementById('variantForm').style.display = 'block';
|
||||
|
||||
console.log('[Edit Variant] Loaded variant:', { colorName, colorHex, imageCount: images.length });
|
||||
}
|
||||
|
||||
// Delete variant
|
||||
function deleteVariant(index) {
|
||||
if (confirm('Are you sure you want to delete this color variant?')) {
|
||||
productVariants.splice(index, 1);
|
||||
renderVariantList();
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel form
|
||||
function cancelVariantForm() {
|
||||
document.getElementById('variantForm').style.display = 'none';
|
||||
currentEditIndex = -1;
|
||||
currentVariantImages = [];
|
||||
}
|
||||
|
||||
// Save variant
|
||||
function saveVariant() {
|
||||
const colorName = document.getElementById('variantColorName').value.trim();
|
||||
const colorHex = document.getElementById('variantColorHex').value.trim();
|
||||
|
||||
if (!colorName || !colorHex) {
|
||||
alert('Please enter a color name and select a color.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentVariantImages.length === 0) {
|
||||
alert('Please assign at least one image to this color variant.');
|
||||
return;
|
||||
}
|
||||
|
||||
const variant = {
|
||||
ColorName: colorName,
|
||||
ColorHex: colorHex,
|
||||
Images: [...currentVariantImages],
|
||||
StockQuantity: parseInt(document.getElementById('variantStock').value) || 0,
|
||||
PriceAdjustment: parseFloat(document.getElementById('variantPriceAdjust').value) || null,
|
||||
SKU: document.getElementById('variantSKU').value.trim() || '',
|
||||
IsAvailable: document.getElementById('variantAvailable').checked
|
||||
};
|
||||
|
||||
if (currentEditIndex >= 0) {
|
||||
productVariants[currentEditIndex] = variant;
|
||||
} else {
|
||||
productVariants.push(variant);
|
||||
}
|
||||
|
||||
renderVariantList();
|
||||
cancelVariantForm();
|
||||
}
|
||||
|
||||
// Select images for variant
|
||||
function selectVariantImages() {
|
||||
console.log('selectVariantImages called');
|
||||
|
||||
// Check if openImagePicker function exists
|
||||
if (typeof openImagePicker !== 'function') {
|
||||
console.error('openImagePicker function not found!');
|
||||
alert('Error: Image picker function not available. Please ensure the page has fully loaded.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Calling openImagePicker...');
|
||||
openImagePicker(function(selectedUrls) {
|
||||
console.log('Image picker callback received:', selectedUrls);
|
||||
currentVariantImages = selectedUrls;
|
||||
updateVariantImagePreview();
|
||||
}, 'multiple');
|
||||
}
|
||||
|
||||
// Update variant image preview
|
||||
function updateVariantImagePreview() {
|
||||
const preview = document.getElementById('variantImagePreview');
|
||||
const count = document.getElementById('variantImageCount');
|
||||
|
||||
if (currentVariantImages.length === 0) {
|
||||
preview.innerHTML = '';
|
||||
count.textContent = 'No images selected';
|
||||
return;
|
||||
}
|
||||
|
||||
count.textContent = `${currentVariantImages.length} image(s) selected`;
|
||||
preview.innerHTML = currentVariantImages.map((img, idx) => `
|
||||
<div class="position-relative">
|
||||
<img src="${img}" class="variant-image-thumb" alt="Variant image">
|
||||
<button type="button" class="btn btn-danger btn-sm position-absolute top-0 end-0"
|
||||
style="padding: 2px 6px; font-size: 0.7rem;"
|
||||
onclick="removeVariantImage(${idx})">
|
||||
<i class="bi bi-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// Remove variant image
|
||||
function removeVariantImage(index) {
|
||||
currentVariantImages.splice(index, 1);
|
||||
updateVariantImagePreview();
|
||||
}
|
||||
|
||||
// Sync color picker and hex input
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const colorPicker = document.getElementById('variantColorPicker');
|
||||
const colorHex = document.getElementById('variantColorHex');
|
||||
|
||||
if (colorPicker && colorHex) {
|
||||
colorPicker.addEventListener('input', function() {
|
||||
colorHex.value = this.value;
|
||||
});
|
||||
|
||||
colorHex.addEventListener('input', function() {
|
||||
if (/^#[0-9A-Fa-f]{6}$/.test(this.value)) {
|
||||
colorPicker.value = this.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Apply variants (to be called when modal is closed)
|
||||
function applyVariants() {
|
||||
// Store variants in hidden field
|
||||
document.getElementById('productVariantsData').value = JSON.stringify(productVariants);
|
||||
bootstrap.Modal.getInstance(document.getElementById('variantManagerModal')).hide();
|
||||
|
||||
// Update UI to show variant count
|
||||
updateVariantSummary();
|
||||
}
|
||||
|
||||
// Update variant summary on main form
|
||||
function updateVariantSummary() {
|
||||
const summary = document.getElementById('variantSummary');
|
||||
if (summary) {
|
||||
summary.innerHTML = productVariants.length > 0
|
||||
? `<span class="badge bg-success">${productVariants.length} color variants configured</span>`
|
||||
: '<span class="badge bg-secondary">No variants</span>';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
75
Views/Admin/Test.cshtml
Executable file
75
Views/Admin/Test.cshtml
Executable file
@@ -0,0 +1,75 @@
|
||||
@{
|
||||
ViewData["Title"] = "Backend Diagnostic Test";
|
||||
Layout = "_AdminLayout";
|
||||
}
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h2>Backend Navigation Diagnostic Test</h2>
|
||||
<p>Click the links below to test navigation:</p>
|
||||
|
||||
<div class="card mt-4">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h4>Test Links</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="list-group">
|
||||
<a href="/admin/pages" class="list-group-item list-group-item-action">
|
||||
<i class="bi bi-file-earmark-text"></i> Pages
|
||||
</a>
|
||||
<a href="/admin/products" class="list-group-item list-group-item-action">
|
||||
<i class="bi bi-cart"></i> Products
|
||||
</a>
|
||||
<a href="/admin/blog" class="list-group-item list-group-item-action">
|
||||
<i class="bi bi-journal-text"></i> Blog
|
||||
</a>
|
||||
<a href="/admin/portfolio/categories" class="list-group-item list-group-item-action">
|
||||
<i class="bi bi-images"></i> Portfolio
|
||||
</a>
|
||||
<a href="/admin/settings" class="list-group-item list-group-item-action">
|
||||
<i class="bi bi-gear"></i> Settings
|
||||
</a>
|
||||
<a href="/admin/users" class="list-group-item list-group-item-action">
|
||||
<i class="bi bi-people"></i> Users
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<h5>JavaScript Test</h5>
|
||||
<button class="btn btn-primary" onclick="alert('JavaScript is working!'); return false;">
|
||||
Test JavaScript
|
||||
</button>
|
||||
|
||||
<button class="btn btn-success" onclick="window.location.href='/admin/pages'">
|
||||
Navigate to Pages (JS)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-4">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h4>Browser Information</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p id="userAgent"></p>
|
||||
<p id="cookiesEnabled"></p>
|
||||
<p id="javaScriptEnabled">JavaScript: Enabled</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('userAgent').textContent = 'User Agent: ' + navigator.userAgent;
|
||||
document.getElementById('cookiesEnabled').textContent = 'Cookies: ' + (navigator.cookieEnabled ? 'Enabled' : 'Disabled');
|
||||
|
||||
// Test click events
|
||||
document.querySelectorAll('.list-group-item').forEach(function(item) {
|
||||
item.addEventListener('click', function(e) {
|
||||
console.log('Link clicked:', this.href);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user