-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
216 lines (200 loc) · 7.82 KB
/
index.html
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Tasks</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #fff;
}
h1, h2 {
background: linear-gradient( #4285f4 var(--bard-color-brand-text-gradient-stop-1) 0, var(--bard-color-brand-text-gradient-stop-2) 9%, var(--bard-color-brand-text-gradient-stop-3) 20%, var(--bard-color-brand-text-gradient-stop-3) 24%, var(--bard-color-brand-text-gradient-stop-2) 35%, var(--bard-color-brand-text-gradient-stop-1) 44%, var(--bard-color-brand-text-gradient-stop-2) 50%, var(--bard-color-brand-text-gradient-stop-3) 56%, var(--gem-sys-color--surface) 75%, var(--gem-sys-color--surface) 100%); text-align: center;
}
.task-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
gap: 20px;
padding: 0;
list-style-type: none;
margin: 20px;
}
.task-list li {
background: #fff;
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
transition: box-shadow 0.3s;
}
.task-list li:hover {
box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.task-details {
display: grid;
grid-template-columns: auto 1fr;
gap: 10px;
margin-bottom: 10px;
}
.task-details span {
font-weight: bold;
color: #555;
}
form {
margin: 20px;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
label {
display: block;
margin: 10px 0 5px;
color: #555;
}
input, textarea {
width: calc(100% - 16px);
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 25px;
background-color: #2B616D;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #FA8D62;
color: #fff;
}
</style>
</head>
<body>
<h1>Student Tasks</h1>
<!-- Form to Create New Task -->
<h2>Create New Task</h2>
<form id="createTaskForm">
<label for="newCourseId">Course ID:</label>
<input type="text" id="newCourseId" required>
<label for="newTaskName">Task Name:</label>
<input type="text" id="newTaskName" required>
<label for="newDueDate">Due Date:</label>
<input type="date" id="newDueDate" required>
<label for="newDetails">Details:</label>
<textarea id="newDetails" required></textarea>
<button type="submit">Create Task</button>
</form>
<!-- Form to Update Existing Task -->
<h2>Update Task</h2>
<form id="updateTaskForm">
<label for="taskId">Task ID:</label>
<input type="text" id="taskId" required>
<label for="courseId">Course ID:</label>
<input type="text" id="courseId" required>
<label for="taskName">Task Name:</label>
<input type="text" id="taskName" required>
<label for="dueDate">Due Date:</label>
<input type="date" id="dueDate" required>
<label for="details">Details:</label>
<textarea id="details" required></textarea>
<button type="submit">Update Task</button>
</form>
<!-- List of Tasks -->
<h2>Task List</h2>
<ul class="task-list" id="taskList">
<!-- Tasks will be populated here -->
</ul>
<script>
// Fetch JSON data from the Express server
function fetchTasks() {
fetch('https://student-tasks-eta.vercel.app/')
.then(response => response.json())
.then(data => {
const taskList = document.getElementById('taskList');
taskList.innerHTML = '';
if (data.length === 0) {
taskList.innerHTML = '<li>No tasks found.</li>';
} else {
data.forEach(task => {
const listItem = document.createElement('li');
const taskDetails = `
<div class="task-details"><span>ID:</span><div>${task._id}</div></div>
<div class="task-details"><span>Course:</span><div>${task.courseId}</div></div>
<div class="task-details"><span>Task:</span><div>${task.taskName}</div></div>
<div class="task-details"><span>Due Date:</span><div>${new Date(task.dueDate).toLocaleDateString()}</div></div>
<div class="task-details"><span>Details:</span><div>${task.details}</div></div>
`;
listItem.innerHTML = taskDetails;
taskList.appendChild(listItem);
});
}
})
.catch(error => {
console.error('Error fetching tasks:', error);
const taskList = document.getElementById('taskList');
taskList.innerHTML = '<li>Failed to load tasks.</li>';
});
}
// Handle new task form submission
document.getElementById('createTaskForm').addEventListener('submit', (event) => {
event.preventDefault();
const courseId = document.getElementById('newCourseId').value;
const taskName = document.getElementById('newTaskName').value;
const dueDate = document.getElementById('newDueDate').value;
const details = document.getElementById('newDetails').value;
fetch('https://student-tasks-eta.vercel.app/tasks', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify([{ courseId, taskName, dueDate, details }])
})
.then(response => response.json())
.then(data => {
console.log('Task created:', data);
fetchTasks(); // Refresh the task list
document.getElementById('createTaskForm').reset(); // Reset the form
})
.catch(error => {
console.error('Error creating task:', error);
});
});
// Handle update task form submission
document.getElementById('updateTaskForm').addEventListener('submit', (event) => {
event.preventDefault();
const taskId = document.getElementById('taskId').value;
const courseId = document.getElementById('courseId').value;
const taskName = document.getElementById('taskName').value;
const dueDate = document.getElementById('dueDate').value;
const details = document.getElementById('details').value;
fetch(`https://student-tasks-eta.vercel.app/tasks/${taskId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ courseId, taskName, dueDate, details })
})
.then(response => response.json())
.then(data => {
console.log('Task updated:', data);
fetchTasks(); // Refresh the task list
document.getElementById('updateTaskForm').reset(); // Reset the form
})
.catch(error => {
console.error('Error updating task:', error);
});
});
// Initial fetch of tasks
fetchTasks();
</script>
</body>
</html>