Skip to content

Commit 50ff515

Browse files
author
Finnian Anderson
committed
Made. It. Work.
It works!
1 parent 9331093 commit 50ff515

3 files changed

Lines changed: 59 additions & 18 deletions

File tree

app.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ app.post("/CIEsubject", function(req, res) {
272272
});
273273

274274
app.post("/dashboard", function(req, res) {
275+
console.log("App.JS".title + ": " + "let's go!".success);
275276
try {
276277
var email = req.body.email;
277278
var password = req.body.password;
@@ -291,26 +292,26 @@ app.post("/dashboard", function(req, res) {
291292
researchModule.researchTopic(searchFields, function(usefulSentences) {
292293
console.log("Researched")
293294
questionModule.question(usefulSentences, function(toStore) {
295+
console.log(toStore);
296+
297+
toStore = JSON.parse(toStore);
294298
if (!toStore) {
295299
res.send(toStore)
296300
} else {
297301
// we have some duplicate keywords in the data so we need to remove them
298-
var newToStore = [];
302+
var newToStore = [[]];
299303
var keywords = [];
300304

301-
302-
console.log(toStore);
303305
for (var i = 0; i < toStore[0].length - 1; i++) {
304306
console.log(toStore[0][i]);
305307
if (keywords.indexOf(toStore[0][i][0]) == -1) {
306-
console.log("new");
307308
keywords.push(toStore[0][i][0]);
308-
newToStore.push(toStore[0][i]);
309+
newToStore[0].push(toStore[0][i]);
309310
}
310311
else {
311-
console.log("New");
312312
}
313313
}
314+
newToStore.push(toStore[1]);
314315
fs.writeFile("files/" + subject + ".sentenceData", newToStore, function(err) {
315316
//if (err) throw err;
316317
res.send(newToStore);

pages/syllabus-choice.html

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@
4848
<!-- /.container-fluid -->
4949
</nav>
5050
<div class="container">
51-
<div class="row" id="needs_margin_top">
52-
<div class="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12" id="bodycontent" style="border-radius: 10px;">
51+
<div class="row" id="answer_div">
52+
<div class="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12 bodycontent" style="border-radius: 10px;">
53+
</div>
54+
</div>
55+
<div class="row" id="course_selection">
56+
<div class="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12 bodycontent" style="border-radius: 10px;">
5357
<div class="row">
5458
<div class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2">
5559
<h1>Course selection</h1>
@@ -85,9 +89,9 @@ <h1>Course selection</h1>
8589
</div>
8690
</div>
8791
<footer class="footer">
88-
<div class="container">
89-
<p class="text-muted text-center"><small>&copy; 2015 SubjectRefresh.info | All Rights Reserved<br>By using this site, you agree to our use of cookies.</small></p>
90-
</div>
92+
<div class="container">
93+
<p class="text-muted text-center"><small>&copy; 2015 SubjectRefresh.info | All Rights Reserved<br>By using this site, you agree to our use of cookies.</small></p>
94+
</div>
9195
</footer>
9296
</body>
9397
<script type="text/javascript">
@@ -96,6 +100,9 @@ <h1>Course selection</h1>
96100
}
97101

98102
function updateSubjects() {
103+
$("#selectSubject").find('option').remove();
104+
$("#selectSyllabus").find('option').remove();
105+
99106
var examBoardBuffer = document.getElementById("selectBoard");
100107
var examBoard = examBoardBuffer.options[examBoardBuffer.selectedIndex].value;
101108
$.post(examBoard).success(function(data) {
@@ -114,6 +121,8 @@ <h1>Course selection</h1>
114121
}
115122

116123
function updateSyllabus(i_n) {
124+
$("#selectSyllabus").find('option').remove();
125+
117126
var examBoardBuffer = document.getElementById("selectBoard");
118127
var examBoard = examBoardBuffer.options[examBoardBuffer.selectedIndex].value;
119128
$.post(examBoard + "Subject", {
@@ -131,10 +140,29 @@ <h1>Course selection</h1>
131140
});
132141
}
133142

134-
var data = [];
143+
var not_duplicated = [];
144+
var answers = [];
145+
146+
function shuffle(array) {
147+
var currentIndex = array.length, temporaryValue, randomIndex ;
148+
149+
// While there remain elements to shuffle...
150+
while (0 !== currentIndex) {
151+
152+
// Pick a remaining element...
153+
randomIndex = Math.floor(Math.random() * currentIndex);
154+
currentIndex -= 1;
155+
156+
// And swap it with the current element.
157+
temporaryValue = array[currentIndex];
158+
array[currentIndex] = array[randomIndex];
159+
array[randomIndex] = temporaryValue;
160+
}
161+
162+
return array;
163+
}
135164

136165
function goGetQuestion(i_n) {
137-
console.log("Submitting...");
138166
var examBoardBuffer = document.getElementById("selectBoard");
139167
var examBoard = examBoardBuffer.options[examBoardBuffer.selectedIndex].value;
140168

@@ -159,11 +187,22 @@ <h1>Course selection</h1>
159187
"syllabus": syllabus,
160188
"url": i_n
161189
}).success(function(newData) {
162-
data = newData;
163-
console.log(data);
164-
for (var i = 0; i < 5; i++){
165-
console.log(data[0][i]);
190+
for (i = 0; i < newData[0].length-1; i++) {
191+
if (newData[0][i][0].split(' ').length == 1) {
192+
not_duplicated.push(newData[0][i][0]);
193+
}
194+
}
195+
for (var i = 1; i < 5; i++) {
196+
var answer = newData[0][i][0];
197+
if (not_duplicated.indexOf(answer) > -1){
198+
answers.push(answer);
199+
var replace_with_this = "<input class='form-control' answer='" + answer + "' type='text' size='" + (answer.length + 2) + "' style='display:inline-block;'>"
200+
console.log("Replacing answer " + answer + " with " + replace_with_this);
201+
newData[1] = newData[1].replace(answer, replace_with_this);
202+
}
166203
}
204+
//answers = shuffle(answers); // not sure if this works or not
205+
$("#answer_div").find(".bodycontent").html(answers.join(", ") + "<hr>" + newData[1]);
167206
});
168207
}
169208

@@ -184,4 +223,5 @@ <h1>Course selection</h1>
184223
return false;
185224
});
186225
</script>
226+
187227
</html>

public/common/css/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ html, * {
112112
border-bottom-left-radius: 10px;
113113
}
114114

115-
#bodycontent {
115+
#bodycontent, .bodycontent {
116116
/* margin-left:auto;
117117
margin-right:auto;
118118
width:500px;

0 commit comments

Comments
 (0)