forked from navik11/SURP--2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
173 lines (161 loc) · 9.09 KB
/
script.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
// Function to get the current domain from URL parameters
function getCurrentDomain() {
const urlParams = new URLSearchParams(window.location.search);
const domain = urlParams.get('domain');
return domain ? domain.charAt(0).toUpperCase() + domain.slice(1) : null; // Capitalize the first letter if domain exists
}
// Fetch the projects JSON data
fetch('projects.json')
.then(response => response.json())
.then(projects => {
const projectCardsContainer = document.getElementById('project-cards');
const currentDomain = getCurrentDomain();
// Filter projects based on the current domain
const filteredProjects = projects.filter(project => project.Domain === currentDomain);
// Update the heading based on the current domain
const title = document.querySelector('.title');
title.textContent = `PROJECTS IN THE ${currentDomain.toUpperCase()} DEPARTMENT`;
filteredProjects.forEach((project, index) => {
// Calculate progress percentage
let appliedStudents = 0;
const maxStudents = project['Number of Students Required'];
let progress = (appliedStudents / maxStudents) * 100;
// Create tags string
const tags = project['Tags'] ? project['Tags'].map(tag => `<span class="badge bg-secondary me-1">${tag}</span>`).join('') : '';
// Create project card
const card = document.createElement('div');
card.className = 'col mb-4';
card.innerHTML = `
<div class="card h-100 shadow">
<h5 class="card-title text-center">${project["Project Title"]}</h5>
<div class="card-body">
<div class="card-text">
<h6>Professor: ${project["Name of Professor"]}</h6>
<h6>UID: ${project["Project UID"]}</h6>
</div>
<div class="progress mb-3">
<div class="progress-bar progress-bar-striped progress-bar-animated ${progress > 0 && progress <= 25 ? "" : progress > 25 && progress <= 50 ? "bg-info" : progress > 50 && progress <= 75 ? "bg-warning" : progress > 75 && progress < 100 ? "bg-danger" : "bg-success"}" role="progressbar" style="width: ${progress}%" aria-valuenow="${progress}" aria-valuemin="0" aria-valuemax="100">${appliedStudents}/${maxStudents}</div>
</div>
<button
type="button"
class="btn btn-primary btn-details mb-2"
data-bs-toggle="modal"
data-bs-target="#modal-${index}"
style="background-color: #004AAD; border-color: #004AAD">
Details
</button>
<span class="tags mb-2 mx-2">${tags}</span>
</div>
</div>
`;
projectCardsContainer.appendChild(card);
// Create project modal
const modal = document.createElement('div');
modal.className = 'modal fade';
modal.id = `modal-${index}`;
modal.setAttribute('data-bs-backdrop', 'static');
modal.setAttribute('data-bs-keyboard', 'false');
modal.setAttribute('tabindex', '-1');
modal.setAttribute('aria-labelledby', `modalLabel-${index}`);
modal.setAttribute('aria-hidden', 'true');
modal.innerHTML = `
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="modalLabel-${index}">${project['Project UID']}</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body table-responsive">
<table class="table table-bordered">
<tr>
<th>Description</th>
<td>${project['Project Description']}</td>
</tr>
<tr>
<th>Number of students</th>
<td>${project['Number of Students Required']}</td>
</tr>
<tr>
<th>Year of study</th>
<td>${project['Year of Study Criteria']}</td>
</tr>
<tr>
<th>CPI</th>
<td>${project['CPI Eligibility Criteria']}</td>
</tr>
<tr>
<th>Prerequisites</th>
<td>${project['Prerequisites']}</td>
</tr>
<tr>
<th>Duration</th>
<td>${project['Duration']}</td>
</tr>
<tr>
<th>Learning outcome</th>
<td>${project['Learning Outcome & Expectations from the students']}</td>
</tr>
<tr>
<th>Weekly time commitment</th>
<td>${project['Weekly Time Commitment']}</td>
</tr>
<tr>
<th>Assignment</th>
<td>${project['Assignment'] ? `<a href="${project['Assignment']}" target="_blank">Link</a>` : 'Not provided'}</td>
</tr>
<tr>
<th>Instructions for assignment</th>
<td>${project['Instructions for assignment'] || 'Not provided'}</td>
</tr>
<tr>
<th>Additional key points</th>
<td>${project['Additional key points'] || 'Not provided'}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button
type="button"
class="btn btn-primary btn-apply"
style="background-color: #004AAD; border-color: #004AAD">
Apply
</button>
</div>
</div>
</div>
`;
document.body.appendChild(modal);
const applyButton = modal.querySelector('.btn-apply');
applyButton.addEventListener('click', function () {
if (applyButton.classList.contains('applied')) {
appliedStudents--;
progress = (appliedStudents / maxStudents) * 100;
const progressBar = card.querySelector('.progress-bar');
progressBar.style.width = `${progress}%`;
progressBar.setAttribute('aria-valuenow', progress);
progressBar.textContent = `${appliedStudents}/${maxStudents}`;
applyButton.textContent = 'Apply';
applyButton.classList.remove('applied');
applyButton.classList.remove('btn-danger');
applyButton.classList.add('btn-primary');
applyButton.style.backgroundColor = '#004AAD';
applyButton.style.borderColor = '#004AAD';
} else {
appliedStudents++;
progress = (appliedStudents / maxStudents) * 100;
const progressBar = card.querySelector('.progress-bar');
progressBar.style.width = `${progress}%`;
progressBar.setAttribute('aria-valuenow', progress);
progressBar.textContent = `${appliedStudents}/${maxStudents}`;
applyButton.textContent = 'Cancel Application';
applyButton.classList.add('applied');
applyButton.classList.remove('btn-primary');
applyButton.classList.add('btn-danger');
applyButton.style.backgroundColor = '#FF0000';
applyButton.style.borderColor = '#FF0000';
}
});
});
})
.catch(error => console.error('Error fetching project data:', error));