Skip to content

Commit 3e052f8

Browse files
Check requirments are fulfilled
1 parent 90015f2 commit 3e052f8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

app/javascript/packs/myjs.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,32 @@ function getPlans(){
102102
});
103103
}
104104

105+
function checkMissingReqs() {
106+
let requirements = plan.requirements;
107+
let planCourses = currPlan.courses;
108+
let reqsMissing = 0;
109+
for (req in requirements) {
110+
let reqType = requirements[req];
111+
for (courseIdx in reqType.courses) {
112+
let course = reqType.courses[courseIdx];
113+
let reqMet = false;
114+
for (id in planCourses) {
115+
if (id == course) {
116+
reqMet = true;
117+
}
118+
}
119+
if (!reqMet) {
120+
reqsMissing++;
121+
}
122+
}
123+
}
124+
if (reqsMissing == 0) {
125+
$("#requirments").html("Requirements Met!");
126+
} else {
127+
$("#requirments").html("Requirments missing: " + reqsMissing);
128+
}
129+
}
130+
105131
function courseInPlan(designator){
106132
let c = plan.courses[designator];
107133
return c !== undefined;
@@ -125,7 +151,8 @@ window.dragFromPlan = function(event){
125151
let desig = event.target.innerText.split(": ")[0];
126152
draggedCourse = plan.catalog.courses[desig];
127153
draggedReqOrigin = null;
128-
draggedPlanOrigin = event.target;
154+
draggedPlanOrigin = event.target;
155+
checkMissingReqs();
129156
}
130157

131158
window.hoverOverPlan = function(event){
@@ -183,6 +210,7 @@ window.dropOnPlan = function(event){
183210
$("#hrsCurrent").html("Current Hours: " + currPlan.hrsCurrent);
184211
$("#hrsFuture").html("Remaining Hours: " + currPlan.hrsFuture);
185212
$("#hrsTotal").html("Total Hours Planned: " + currPlan.hrsTotal);
213+
checkMissingReqs();
186214
draggedCourse = null;
187215
}
188216

app/views/plans/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<p id="hrsCurrent">Current Hours: </p>
5656
<p id="hrsFuture">Remaining Hours: </p>
5757
<p id="hrsTotal">Total Hours Planned: </p>
58+
<p id="requirments">Requirments </p>
5859
</div>
5960
</div>
6061

0 commit comments

Comments
 (0)