-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
148 lines (131 loc) · 3.96 KB
/
index.html
File metadata and controls
148 lines (131 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Task Manager</title>
<script src="https://kit.fontawesome.com/77c4032121.js" crossorigin="anonymous"></script>
<style>
body { font-family: Arial; padding: 20px; }
.task { padding: 8px; margin: 5px 0; border: 1px solid #ffffff; border-radius: 5px; }
.completed { text-decoration: line-through; color: green; }
.by-user { font-size: 0.8em; color: rgb(0, 0, 0); }
</style>
<style>
body {
font-family: Arial, sans-serif;
background: #343232;
margin: 0;
padding: 20px;
}
.panel {
background: rgb(144, 142, 142);
border-radius: 10px;
box-shadow: 0 0 10px rgba(228, 221, 221, 0.1);
padding: 20px;
max-width: 800px;
margin: auto;
}
h2 {
margin-top: 0;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ffffff;
}
.section {
margin-top: 30px;
}
.img
{
display: block;
margin: auto;
}
</style>
</head>
<body>
<img src="img/1000000483-removebg-preview.png" width="15%" class="img">
<div class="panel">
<h2>Admin Panel</h2>
<h2>📋 Task Dashboard</h2>
<div>
<h3>Add Task</h3>
<input id="taskInput" placeholder="New task..." />
<button onclick="addTask()">➕ Add Task</button>
<hr>
</div>
<h3>Tasks</h3>
<div id="taskList"></div>
</div>
<script>
const currentUser = localStorage.getItem("username");
const isAdmin = currentUser === "admin";
// Fetch tasks from the server
async function fetchTasks() {
const res = await fetch('http://localhost:3000/tasks');
const tasks = await res.json();
renderTasks(tasks);
}
// Add a task
async function addTask() {
const text = document.getElementById("taskInput").value.trim();
if (!text || !currentUser) {
alert("Missing task text or not logged in");
return;
}
await fetch('http://localhost:3000/tasks', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, username: currentUser })
});
document.getElementById("taskInput").value = "";
fetchTasks();
}
// Mark task as done
async function markDone(index) {
await fetch(`http://localhost:3000/tasks/${index}`, { method: 'PUT' });
fetchTasks();
}
// Delete a task (admin only)
async function deleteTask(index) {
await fetch(`http://localhost:3000/tasks/${index}`, { method: 'DELETE' });
fetchTasks();
}
// Render tasks on the page
function renderTasks(tasks) {
const list = document.getElementById("taskList");
list.innerHTML = "";
tasks.forEach((task, i) => {
const div = document.createElement("div");
div.className = "task" + (task.done ? " completed" : "");
div.innerHTML = `
<div>${task.text}</div>
<div class="by-user">by ${task.username}</div>
${!task.done ? `<button onclick="markDone(${i})">✅ Done</button>` : ""}
${isAdmin ? `<button onclick="deleteTask(${i})">❌ Delete</button>` : ""}
`;
list.appendChild(div);
});
}
// Fetch tasks when the page loads
window.onload = fetchTasks;
</script>
<script>
if (localStorage.getItem("loggedIn") !== "true") {
window.location.href = "login.html";
}
</script>
<script>
function logout() {
localStorage.removeItem("loggedIn");
window.location.href = "login.html";
}
</script>
<p style="text-align: right;"><a href="#" onclick="logout()" style="color: #fff; text-decoration: none;"><i class="fa-solid fa-power-off" ></i> Logout</a></p>
</body>
</html>