Deploy from Lumerel

This commit is contained in:
Lumerel Deploy
2026-02-16 23:52:50 +00:00
commit 9308dc945f
20 changed files with 1334 additions and 0 deletions

142
public/dashboard.html Normal file
View File

@@ -0,0 +1,142 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TaskIt! - Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
background-color: #f4f6f9;
font-family: 'Inter', sans-serif;
}
.dashboard-container {
max-width: 1200px;
margin: 2rem auto;
}
.project-card {
border-radius: 15px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
transition: transform 0.3s ease;
}
.project-card:hover {
transform: translateY(-10px);
}
.task-status {
font-size: 0.8rem;
padding: 0.2rem 0.5rem;
border-radius: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="#">TaskIt!</a>
<button class="btn btn-outline-danger" id="logoutBtn">Logout</button>
</div>
</nav>
<div class="dashboard-container">
<div class="row">
<div class="col-md-4">
<div class="card project-card mb-4">
<div class="card-body">
<h5 class="card-title">Create New Project</h5>
<form id="newProjectForm">
<div class="mb-3">
<input type="text" class="form-control" placeholder="Project Name" required>
</div>
<div class="mb-3">
<textarea class="form-control" placeholder="Project Description" rows="3" required></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Create Project</button>
</form>
</div>
</div>
</div>
<div class="col-md-8" id="projectList">
<!-- Projects will be dynamically loaded here -->
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Check Authentication
async function checkAuth() {
const response = await fetch('/api/projects', {
method: 'GET',
credentials: 'include'
});
if (response.status === 401) {
window.location.href = '/index.html';
}
}
// Logout Handler
document.getElementById('logoutBtn').addEventListener('click', async () => {
try {
const response = await fetch('/api/logout', { method: 'POST' });
const result = await response.json();
if (result.success) {
window.location.href = '/index.html';
}
} catch (error) {
console.error('Logout error:', error);
}
});
// Load Projects
async function loadProjects() {
const projectList = document.getElementById('projectList');
try {
const response = await fetch('/api/projects');
const projects = await response.json();
projectList.innerHTML = projects.map(project => `
<div class="card project-card mb-3">
<div class="card-body">
<h5 class="card-title">${project.name}</h5>
<p class="card-text">${project.description}</p>
<a href="/project.html?id=${project.id}" class="btn btn-outline-primary">View Tasks</a>
</div>
</div>
`).join('');
} catch (error) {
console.error('Projects load error:', error);
}
}
// Create New Project
document.getElementById('newProjectForm').addEventListener('submit', async function(e) {
e.preventDefault();
const name = this.querySelector('input[type="text"]').value;
const description = this.querySelector('textarea').value;
try {
const response = await fetch('/api/projects', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, description })
});
const result = await response.json();
if (result) {
loadProjects();
this.reset();
}
} catch (error) {
console.error('Project creation error:', error);
}
});
// Initial Load
checkAuth();
loadProjects();
</script>
</body>
</html>

132
public/index.html Normal file
View File

@@ -0,0 +1,132 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TaskIt! - Project Management</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
background-color: #f4f6f9;
font-family: 'Inter', sans-serif;
}
.auth-container {
max-width: 400px;
margin: 5rem auto;
background-color: white;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
padding: 2rem;
}
.dashboard-card {
border-radius: 15px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
transition: transform 0.3s ease;
}
.dashboard-card:hover {
transform: translateY(-10px);
}
</style>
</head>
<body>
<div id="app" class="container-fluid">
<!-- Login Screen -->
<div id="loginScreen" class="auth-container text-center">
<h2 class="mb-4">TaskIt!</h2>
<form id="loginForm">
<div class="mb-3">
<input type="email" class="form-control" placeholder="Email" required>
</div>
<div class="mb-3">
<input type="password" class="form-control" placeholder="Password" required>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
<p class="mt-3">Don't have an account? <a href="#" id="showRegister">Register</a></p>
</form>
</div>
<!-- Registration Screen -->
<div id="registerScreen" class="auth-container text-center" style="display:none;">
<h2 class="mb-4">Create Account</h2>
<form id="registerForm">
<div class="mb-3">
<input type="text" class="form-control" placeholder="Full Name" required>
</div>
<div class="mb-3">
<input type="email" class="form-control" placeholder="Email" required>
</div>
<div class="mb-3">
<input type="password" class="form-control" placeholder="Password" required>
</div>
<button type="submit" class="btn btn-success w-100">Register</button>
<p class="mt-3">Already have an account? <a href="#" id="showLogin">Login</a></p>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Simple Auth UI Toggle
document.getElementById('showRegister').addEventListener('click', function(e) {
e.preventDefault();
document.getElementById('loginScreen').style.display = 'none';
document.getElementById('registerScreen').style.display = 'block';
});
document.getElementById('showLogin').addEventListener('click', function(e) {
e.preventDefault();
document.getElementById('registerScreen').style.display = 'none';
document.getElementById('loginScreen').style.display = 'block';
});
// Authentication Handlers
document.getElementById('loginForm').addEventListener('submit', async function(e) {
e.preventDefault();
const email = this.querySelector('input[type="email"]').value;
const password = this.querySelector('input[type="password"]').value;
try {
const response = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password })
});
const result = await response.json();
if (result.success) {
window.location.href = '/dashboard.html';
} else {
alert(result.error);
}
} catch (error) {
console.error('Login error:', error);
}
});
document.getElementById('registerForm').addEventListener('submit', async function(e) {
e.preventDefault();
const name = this.querySelector('input[type="text"]').value;
const email = this.querySelector('input[type="email"]').value;
const password = this.querySelector('input[type="password"]').value;
try {
const response = await fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, email, password })
});
const result = await response.json();
if (result.success) {
window.location.href = '/dashboard.html';
} else {
alert(result.error);
}
} catch (error) {
console.error('Registration error:', error);
}
});
</script>
</body>
</html>

176
public/index.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../db.php';
use App\Controllers\AuthController;
use App\Controllers\ProjectController;
use App\Controllers\TaskController;
// Simple routing
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$method = $_SERVER['REQUEST_METHOD'];
// Serve HTML files for non-API routes
if (!str_starts_with($requestUri, '/api/')) {
switch ($requestUri) {
case '/':
case '/index.html':
readfile(__DIR__ . '/index.html');
exit;
case '/dashboard.html':
readfile(__DIR__ . '/dashboard.html');
exit;
case '/project.html':
readfile(__DIR__ . '/project.html');
exit;
default:
// Try to serve static file if it exists
$filePath = __DIR__ . $requestUri;
if (file_exists($filePath) && is_file($filePath)) {
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
$mimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
];
if (isset($mimeTypes[$extension])) {
header('Content-Type: ' . $mimeTypes[$extension]);
}
readfile($filePath);
exit;
}
}
}
// Headers for JSON responses
header('Content-Type: application/json');
try {
switch (true) {
case $requestUri === '/api/register' && $method === 'POST':
$data = json_decode(file_get_contents('php://input'), true);
$authController = new AuthController();
echo json_encode($authController->register(
$data['name'],
$data['email'],
$data['password']
));
break;
case $requestUri === '/api/login' && $method === 'POST':
$data = json_decode(file_get_contents('php://input'), true);
$authController = new AuthController();
echo json_encode($authController->login(
$data['email'],
$data['password']
));
break;
case $requestUri === '/api/logout' && $method === 'POST':
$authController = new AuthController();
echo json_encode($authController->logout());
break;
case $requestUri === '/api/projects' && $method === 'GET':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$projectController = new ProjectController();
echo json_encode($projectController->getUserProjects());
break;
case $requestUri === '/api/projects' && $method === 'POST':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$projectController = new ProjectController();
echo json_encode($projectController->createProject(
$data['name'],
$data['description']
));
break;
case preg_match('/^\/api\/projects\/(\d+)$/', $requestUri, $matches) && $method === 'GET':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$projectController = new ProjectController();
echo json_encode($projectController->getProjectDetails($matches[1]));
break;
case $requestUri === '/api/tasks' && $method === 'POST':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$taskController = new TaskController();
echo json_encode($taskController->createTask(
$data['name'],
$data['description'],
$data['project_id'],
$data['status'] ?? 'created'
));
break;
case preg_match('/^\/api\/tasks\/(\d+)\/status$/', $requestUri, $matches) && $method === 'PUT':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$taskController = new TaskController();
echo json_encode($taskController->updateTaskStatus(
$matches[1],
$data['status']
));
break;
case preg_match('/^\/api\/tasks\/(\d+)$/', $requestUri, $matches) && $method === 'GET':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$taskController = new TaskController();
echo json_encode($taskController->getTask($matches[1]));
break;
case preg_match('/^\/api\/tasks\/(\d+)$/', $requestUri, $matches) && $method === 'PUT':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$taskController = new TaskController();
echo json_encode($taskController->updateTask(
$matches[1],
$data['name'],
$data['description']
));
break;
default:
http_response_code(404);
echo json_encode(['error' => 'Not Found']);
break;
}
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}

View File

@@ -0,0 +1,185 @@
<?php
require_once __DIR__ . '/../db.php';
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Migration Status - TaskIt!</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 1000px;
margin: 40px auto;
padding: 20px;
background: #f5f5f5;
}
h1 {
color: #333;
border-bottom: 3px solid #4CAF50;
padding-bottom: 10px;
}
.status {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.success { color: #4CAF50; font-weight: bold; }
.error { color: #f44336; font-weight: bold; }
table {
width: 100%;
border-collapse: collapse;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #4CAF50;
color: white;
font-weight: 600;
}
tr:hover {
background: #f5f5f5;
}
.available {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-top: 20px;
}
.available h2 {
color: #333;
margin-top: 0;
}
.available ul {
list-style: none;
padding: 0;
}
.available li {
padding: 8px;
margin: 4px 0;
background: #f9f9f9;
border-left: 3px solid #2196F3;
padding-left: 12px;
}
.available li.ran {
border-left-color: #4CAF50;
opacity: 0.6;
}
.available li.pending {
border-left-color: #ff9800;
font-weight: bold;
}
code {
background: #f4f4f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
</style>
</head>
<body>
<h1>🔍 Migration Status</h1>
<div class="status">
<?php
try {
// Check if migrations table exists
$tables = $pdo->query("SHOW TABLES LIKE 'migrations'")->fetchAll();
if (empty($tables)) {
echo '<p class="error">❌ Migrations table does not exist yet!</p>';
echo '<p>This means <code>migrate.php</code> has not run successfully.</p>';
} else {
echo '<p class="success">✅ Migrations table exists</p>';
// Get all ran migrations
$ranMigrations = $pdo->query("SELECT * FROM migrations ORDER BY ran_at DESC")->fetchAll();
if (empty($ranMigrations)) {
echo '<p class="error">⚠️ No migrations have been run yet!</p>';
} else {
echo '<p class="success">✅ ' . count($ranMigrations) . ' migration(s) have been run</p>';
}
}
} catch (PDOException $e) {
echo '<p class="error">❌ Database Error: ' . htmlspecialchars($e->getMessage()) . '</p>';
}
?>
</div>
<?php if (!empty($ranMigrations)): ?>
<h2>Migrations Run</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Migration</th>
<th>Run At</th>
</tr>
</thead>
<tbody>
<?php foreach ($ranMigrations as $migration): ?>
<tr>
<td><?= htmlspecialchars($migration['id']) ?></td>
<td><code><?= htmlspecialchars($migration['migration']) ?></code></td>
<td><?= htmlspecialchars($migration['ran_at']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="available">
<h2>Available Migration Files</h2>
<?php
$migrationsDir = __DIR__ . '/../migrations';
if (is_dir($migrationsDir)) {
$files = scandir($migrationsDir);
$migrationFiles = array_filter($files, function($file) {
return pathinfo($file, PATHINFO_EXTENSION) === 'php';
});
sort($migrationFiles);
$ranNames = !empty($ranMigrations) ? array_column($ranMigrations, 'migration') : [];
if (empty($migrationFiles)) {
echo '<p class="error">No migration files found in /migrations directory</p>';
} else {
echo '<ul>';
foreach ($migrationFiles as $file) {
$isRan = in_array($file, $ranNames);
$class = $isRan ? 'ran' : 'pending';
$status = $isRan ? '✅' : '⏳';
echo '<li class="' . $class . '">' . $status . ' <code>' . htmlspecialchars($file) . '</code></li>';
}
echo '</ul>';
}
} else {
echo '<p class="error">Migrations directory not found</p>';
}
?>
</div>
<div class="status" style="margin-top: 20px;">
<h3>Database Connection Info</h3>
<p><strong>Host:</strong> <?= htmlspecialchars(getenv('DB_HOST') ?: 'Not set') ?></p>
<p><strong>Port:</strong> <?= htmlspecialchars(getenv('DB_PORT') ?: 'Not set') ?></p>
<p><strong>Database:</strong> <?= htmlspecialchars(getenv('DB_DATABASE') ?: 'Not set') ?></p>
<p><strong>Username:</strong> <?= htmlspecialchars(getenv('DB_USERNAME') ?: 'Not set') ?></p>
<p><strong>Password:</strong> <?= getenv('DB_PASSWORD') ? '✅ Set' : '❌ Not set' ?></p>
</div>
</body>
</html>

296
public/project.html Normal file
View File

@@ -0,0 +1,296 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TaskIt! - Project Details</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
background-color: #f4f6f9;
font-family: 'Inter', sans-serif;
}
.project-container {
max-width: 1200px;
margin: 2rem auto;
}
.task-card {
border-radius: 15px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
transition: transform 0.3s ease;
}
.task-card:hover {
transform: translateY(-5px);
}
.status-badge {
padding: 0.5rem 1rem;
border-radius: 8px;
font-weight: 600;
font-size: 0.85rem;
text-transform: capitalize;
}
.status-created { background-color: #e9ecef; color: #6c757d; }
.status-in_progress { background-color: #ffc107; color: white; }
.status-testing { background-color: #17a2b8; color: white; }
.status-complete { background-color: #28a745; color: white; }
.status-approved { background-color: #007bff; color: white; }
.btn-icon {
padding: 0.375rem 0.75rem;
margin-left: 0.5rem;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="/dashboard.html">TaskIt!</a>
<button class="btn btn-outline-danger" id="logoutBtn">Logout</button>
</div>
</nav>
<div class="project-container">
<div class="row">
<div class="col-md-4">
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title" id="formTitle">Create New Task</h5>
<form id="taskForm">
<input type="hidden" id="taskId" value="">
<div class="mb-3">
<input type="text" id="taskName" class="form-control" placeholder="Task Name" required>
</div>
<div class="mb-3">
<textarea id="taskDescription" class="form-control" placeholder="Task Description" rows="3" required></textarea>
</div>
<div class="mb-3">
<select id="taskStatus" class="form-control" required>
<option value="created">Created</option>
<option value="in_progress">In Progress</option>
<option value="testing">Testing</option>
<option value="complete">Complete</option>
<option value="approved">Approved</option>
</select>
</div>
<button type="submit" class="btn btn-primary w-100" id="submitBtn">Create Task</button>
<button type="button" class="btn btn-secondary w-100 mt-2" id="cancelBtn" style="display: none;">Cancel</button>
</form>
</div>
</div>
</div>
<div class="col-md-8">
<div id="projectHeader" class="mb-4">
<h2 id="projectName"></h2>
<p id="projectDescription"></p>
</div>
<div id="taskList">
<!-- Tasks will be dynamically loaded here -->
</div>
</div>
</div>
</div>
<!-- Edit Task Modal -->
<div class="modal fade" id="editTaskModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Task</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="editTaskForm">
<input type="hidden" id="editTaskId">
<div class="mb-3">
<label class="form-label">Task Name</label>
<input type="text" id="editTaskName" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Description</label>
<textarea id="editTaskDescription" class="form-control" rows="3" required></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="saveTaskBtn">Save Changes</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
const urlParams = new URLSearchParams(window.location.search);
const projectId = urlParams.get('id');
let editModal;
// Initialize modal
document.addEventListener('DOMContentLoaded', function() {
editModal = new bootstrap.Modal(document.getElementById('editTaskModal'));
});
// Logout Handler
document.getElementById('logoutBtn').addEventListener('click', async () => {
try {
const response = await fetch('/api/logout', { method: 'POST' });
const result = await response.json();
if (result.success) {
window.location.href = '/index.html';
}
} catch (error) {
console.error('Logout error:', error);
}
});
// Load Project Details
async function loadProjectDetails() {
try {
const response = await fetch(`/api/projects/${projectId}`);
const data = await response.json();
document.getElementById('projectName').textContent = data.project.name;
document.getElementById('projectDescription').textContent = data.project.description;
const taskList = document.getElementById('taskList');
taskList.innerHTML = data.tasks.map(task => `
<div class="card task-card mb-3">
<div class="card-body">
<div class="d-flex justify-content-between align-items-start">
<div class="flex-grow-1">
<h5 class="card-title">${task.name}</h5>
<p class="card-text">${task.description}</p>
</div>
<div class="d-flex align-items-center">
<select class="form-select form-select-sm status-select" data-task-id="${task.id}" style="width: auto; min-width: 150px;">
<option value="created" ${task.status === 'created' ? 'selected' : ''}>Created</option>
<option value="in_progress" ${task.status === 'in_progress' ? 'selected' : ''}>In Progress</option>
<option value="testing" ${task.status === 'testing' ? 'selected' : ''}>Testing</option>
<option value="complete" ${task.status === 'complete' ? 'selected' : ''}>Complete</option>
<option value="approved" ${task.status === 'approved' ? 'selected' : ''}>Approved</option>
</select>
<button class="btn btn-sm btn-outline-primary btn-icon edit-task-btn" data-task-id="${task.id}" title="Edit Task">
<i class="bi bi-pencil"></i>
</button>
</div>
</div>
</div>
</div>
`).join('');
// Add event listeners to status selects
document.querySelectorAll('.status-select').forEach(select => {
select.addEventListener('change', async function() {
const taskId = this.dataset.taskId;
const newStatus = this.value;
await updateTaskStatus(taskId, newStatus);
});
});
// Add event listeners to edit buttons
document.querySelectorAll('.edit-task-btn').forEach(btn => {
btn.addEventListener('click', function() {
const taskId = this.dataset.taskId;
openEditModal(taskId);
});
});
} catch (error) {
console.error('Project details load error:', error);
}
}
// Update Task Status
async function updateTaskStatus(taskId, status) {
try {
const response = await fetch(`/api/tasks/${taskId}/status`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ status })
});
const result = await response.json();
if (result) {
// Show success feedback (optional)
console.log('Status updated successfully');
}
} catch (error) {
console.error('Status update error:', error);
alert('Failed to update task status');
}
}
// Open Edit Modal
async function openEditModal(taskId) {
try {
const response = await fetch(`/api/tasks/${taskId}`);
const task = await response.json();
document.getElementById('editTaskId').value = task.id;
document.getElementById('editTaskName').value = task.name;
document.getElementById('editTaskDescription').value = task.description;
editModal.show();
} catch (error) {
console.error('Load task error:', error);
}
}
// Save Task Edit
document.getElementById('saveTaskBtn').addEventListener('click', async function() {
const taskId = document.getElementById('editTaskId').value;
const name = document.getElementById('editTaskName').value;
const description = document.getElementById('editTaskDescription').value;
try {
const response = await fetch(`/api/tasks/${taskId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, description })
});
const result = await response.json();
if (result) {
editModal.hide();
loadProjectDetails();
}
} catch (error) {
console.error('Task update error:', error);
alert('Failed to update task');
}
});
// Create New Task
document.getElementById('taskForm').addEventListener('submit', async function(e) {
e.preventDefault();
const name = document.getElementById('taskName').value;
const description = document.getElementById('taskDescription').value;
const status = document.getElementById('taskStatus').value;
try {
const response = await fetch('/api/tasks', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name,
description,
project_id: projectId,
status
})
});
const result = await response.json();
if (result) {
loadProjectDetails();
this.reset();
}
} catch (error) {
console.error('Task creation error:', error);
}
});
// Initial Load
loadProjectDetails();
</script>
</body>
</html>