Skip to content

Commit

Permalink
table
Browse files Browse the repository at this point in the history
  • Loading branch information
hobrien17 committed Aug 19, 2018
2 parents ef38dc2 + d7590b3 commit 8964a8a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def availability():
return render_template("availability.html")


@app.route('/allocations')
@app.route('/allocations', methods=['POST'])
def allocations():
tutors = request.args.get('tutors')
return render_template("allocations.html", tutors=tutors)
print(request.form.get('tutors'))
#tutors = json.loads(request.form.get('tutors').replace("'", '"'))
return render_template("allocations.html", tutors=request.form.get('tutors'))


@app.route('/times')
Expand Down Expand Up @@ -74,7 +75,7 @@ def unauthorized_handle():
@app.route('/api/execute', methods=['POST'])
def execute_algorithm():
users = request.form.get('users').split("\n")
classes = json.loads(request.form['classes']) # {session name: [day, start, end]}
classes = json.loads(request.form['classes'].replace("'", '"')) # {session name: [day, start, end]}

availabilities = {}

Expand All @@ -92,8 +93,7 @@ def execute_algorithm():
app.logger.info("Classes 2: {}".format(classes))
results = backend.backend_run.run(availabilities, classes)


return redirect(url_for('/allocations', tutors=results))
return jsonify(results)


@app.route('/api/login', methods=['POST'])
Expand Down
28 changes: 28 additions & 0 deletions frontend/static/assets/js/frm.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,35 @@ function runall() {
url: "/api/execute",
data: {users: $("#message").val(), classes: JSON.stringify(results)},
success: function(retrieved) {

console.log(retrieved);

var res = "<table style=\"width:100%\"> \
<tr> \
<th>Tutor</th> \
<th>Session(s)</th> \
</tr> \
"
for(i = 0; i < retrieved.length; i++) {
r = retrieved[i];
email = r["email"];
alloc = r["allocation"];
res += "<tr> \
<td>" + email + "</td> \
<td>" + alloc + "</td> \
</tr> \
";
}
res += "</table>"
var div = document.getElementById("resultarea");
console.log(div);
div.insertAdjacentHTML('beforeend', res);

/*var form = $('<form action="/allocations" method="post">' +
'<input type="hidden" name="tutors" id="tutors" value="' + JSON.stringify(retrieved) + '" />' +
'</form>');
//$('body').append(form);
//form.submit();*/
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/templates/coordinator.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
<center><input value="Submit" id="runall" class="button big" type="button"></center>
</form>

<div id="resultarea">

</div>

</div>

<!-- Scripts -->
Expand Down

0 comments on commit 8964a8a

Please sign in to comment.