-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.js
183 lines (156 loc) · 5.6 KB
/
dashboard.js
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
document.addEventListener("DOMContentLoaded", function() {
var sidebarLinks = document.querySelectorAll('.sidebar a');
var contentContainers = document.querySelectorAll('.content-container');
sidebarLinks.forEach(function(link) {
link.addEventListener('click', function(event) {
event.preventDefault();
var targetId = this.getAttribute('data-target');
contentContainers.forEach(function(container) {
container.classList.remove('active');
});
document.getElementById(targetId).classList.add('active');
});
});
});
//get_tasks.php
window.onload = function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("tasks-container").innerHTML = this.responseText;
}
};
xhttp.open("GET", "get_tasks.php", true);
xhttp.send();
};
function fetchTasks() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("tasks-container").innerHTML = this.responseText;
}
};
xhttp.open("GET", "get_tasks.php", true);
xhttp.send();
}
function markAsComplete(taskId) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert("Task marked as complete!");
fetchTasks();
}
};
xhttp.open("POST", "mark_as_complete.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("id=" + taskId);
}
//fetch_tasks.php
document.addEventListener('DOMContentLoaded', function() {
fetchTasks();
});
function fetchTasks() {
fetch('fetch_tasks.php')
.then(response => response.json())
.then(data => {
displayTasks(data.assigned_to_me, 'tasks-assigned-to-me');
displayTasks(data.assigned_by_me, 'tasks-assigned-by-me');
})
.catch(error => console.error('Error fetching tasks:', error));
}
function displayTasks(tasks, containerId) {
const container = document.getElementById(containerId);
container.innerHTML = '';
if (tasks.length > 0) {
tasks.forEach(task => {
const taskElement = document.createElement('div');
taskElement.classList.add('task');
taskElement.innerHTML = `
<strong>Task ID:</strong> ${task.id}<br>
<strong>Assigner:</strong> ${task.assigner_name}<br>
<strong>Assignee:</strong> ${task.assignee_name}<br>
<strong>Description:</strong> ${task.task_description}<br>
<strong>Given At:</strong> ${task.task_given_at}<br>
<strong>Completed At:</strong> ${task.task_completed_at ? task.task_completed_at : '<p>Not completed yet</p>'}
`;
console.log(`Task ID ${task.id}: task_completed_at = ${task.task_completed_at}`);
container.appendChild(taskElement);
});
} else {
container.innerHTML = '<p>No tasks available.</p>';
}
}
//groupwork
document.addEventListener("DOMContentLoaded", function() {
fetchTasksGroupWork();
});
function fetchTasksGroupWork() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("tasks-containeri").innerHTML = this.responseText;
}
};
xhttp.open("GET", "get_taski.php", true);
xhttp.send();
}
function markAsCompleteGroupWork(taskId) {
console.log("Task ID:", taskId);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
fetchTasksGroupWork();
}
};
xhttp.open("POST", "mark_as_completei.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("id=" + taskId);
}
//Group History
document.addEventListener("DOMContentLoaded", function() {
fetchTasksAssignedByMe();
fetchTasksAssignedToMe();
});
function fetchTasksAssignedByMe() {
$.ajax({
url: "tasks_assigned_by_me.php",
method: "GET",
success: function(data) {
$("#assignedByMe").html(data);
checkTaskCompletionStatus();
},
error: function(xhr, status, error) {
console.error("Error fetching tasks assigned by me:", error);
}
});
}
function fetchTasksAssignedToMe() {
$.ajax({
url: "tasks_assigned_to_me.php",
method: "GET",
success: function(data) {
$("#assignedToMe").html(data);
checkTaskCompletionStatus();
},
error: function(xhr, status, error) {
console.error("Error fetching tasks assigned to me:", error);
}
});
}
function checkTaskCompletionStatus() {
$(".task").each(function() {
var allCompleted = true;
$(this).find("p").each(function() {
if ($(this).text().includes("Not completed")) {
allCompleted = false;
return false;
}
});
if (allCompleted) {
$(this).css("border-color", "green");
} else {
$(this).css("border-color", "red");
}
});
}