From 933c384e49a25a5cf006d70ae48aa53bcc925b8a Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 27 Sep 2025 08:49:28 +0000 Subject: [PATCH] feat: Implement Create Mission functionality - Add a database setup script to create the `missions` table. - Implement a modal form for creating new missions. - Add backend PHP logic to handle form submission and save missions to the database. - Display the list of missions dynamically from the database. --- assets/js/main.js | 13 ++-- db/setup.php | 33 +++++++++++ index.php | 148 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 154 insertions(+), 40 deletions(-) create mode 100644 db/setup.php diff --git a/assets/js/main.js b/assets/js/main.js index a6186fc..ad5cb41 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,9 +1,4 @@ - -document.addEventListener('DOMContentLoaded', function() { - const createMissionBtn = document.getElementById('createMissionBtn'); - if (createMissionBtn) { - createMissionBtn.addEventListener('click', function() { - alert('This feature is coming soon!'); - }); - } -}); +document.addEventListener('DOMContentLoaded', function () { + // You can add any interactive scripts here in the future. + // For example, handling view button clicks to show mission details. +}); \ No newline at end of file diff --git a/db/setup.php b/db/setup.php new file mode 100644 index 0000000..6bd2468 --- /dev/null +++ b/db/setup.php @@ -0,0 +1,33 @@ +exec($sql); + echo "Table 'missions' created successfully." . PHP_EOL; + + // Add some initial data for demonstration + $stmt = $pdo->query("SELECT COUNT(*) FROM missions"); + if ($stmt->fetchColumn() == 0) { + $pdo->exec(" + INSERT INTO missions (name, drone, status, mission_date) VALUES + ('Vineyard Survey', 'DJI Agras T30', 'Completed', '2025-09-25'), + ('Pest Control', 'XAG P40', 'In Progress', '2025-09-27'), + ('Crop Dusting', 'DJI Agras T30', 'Scheduled', '2025-09-29'); + "); + echo "Initial data inserted into 'missions' table." . PHP_EOL; + } + +} catch (PDOException $e) { + die("DB ERROR: " . $e->getMessage()); +} diff --git a/index.php b/index.php index b5e5a16..d0ad0cb 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,56 @@ +prepare($sql); + $stmt->execute([ + ':name' => $name, + ':drone' => $drone, + ':status' => $status, + ':mission_date' => $mission_date, + ]); + // Redirect to avoid form resubmission + header("Location: index.php"); + exit; + } catch (PDOException $e) { + // For a real app, you'd log this error + die("Error saving mission: " . $e->getMessage()); + } + } +} + +// Fetch all missions +try { + $pdo = db(); + $stmt = $pdo->query("SELECT id, name, drone, status, DATE_FORMAT(mission_date, '%Y-%m-%d') as mission_date FROM missions ORDER BY mission_date DESC"); + $missions = $stmt->fetchAll(); +} catch (PDOException $e) { + die("Error fetching missions: " . $e->getMessage()); +} + +function getStatusClass($status) { + switch (strtolower($status)) { + case 'completed': + return 'status-completed'; + case 'in progress': + return 'status-in-progress'; + case 'scheduled': + return 'status-pending'; + default: + return 'status-pending'; + } +} +?> @@ -32,10 +85,10 @@ -
+

Mission Dashboard

-
@@ -52,34 +105,21 @@ - - Vineyard Spraying - Block A - AG-Drone 01 - Completed - 2025-09-26 - - - - Row Monitoring - Section 3 - AG-Drone 02 - In Progress - 2025-09-27 - - - - Pest Analysis - North Field - AG-Drone 01 - Pending - 2025-09-28 - - - - Soil Sampling - West Ridge - AG-Drone 03 - Pending - 2025-09-29 - - + + + No missions found. Create one to get started! + + + + + + + + + + + + @@ -89,6 +129,52 @@

© AgroDrone Control. All Rights Reserved.

+ + + @@ -99,4 +185,4 @@ - \ No newline at end of file +