Skip to content

Commit

Permalink
merge Kyles changes
Browse files Browse the repository at this point in the history
  • Loading branch information
millro04 authored and bnmnetp committed Aug 16, 2016
1 parent 93b5ded commit 6b2de44
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
27 changes: 27 additions & 0 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,30 @@ def coursename():
row = db(db.courses.id == auth.user.course_id).select(db.courses.course_name, db.courses.base_course).first()
return json.dumps(row.course_name)


@auth.requires(lambda: verifyInstructorStatus(auth.user.course_name, auth.user), requires_login=True)
def indexrst():
try:
row = db(db.courses.id == auth.user.course_id).select(db.courses.course_name, db.courses.base_course).first()
course_name = row.course_name
file = open(os.path.join(os.path.split(os.path.dirname(__file__))[0], 'custom_courses/' + course_name + '/index.rst'))
filetxt = file.read()
except Exception as ex:
print(ex)
filetxt = "Sorry, no index.rst file could be found"
return json.dumps(filetxt)

@auth.requires(lambda: verifyInstructorStatus(auth.user.course_name, auth.user), requires_login=True)
def editindexrst():
try:
row = db(db.courses.id == auth.user.course_id).select(db.courses.course_name, db.courses.base_course).first()
course_name = row.course_name
newtext = request.vars['newtext']
file = open(os.path.join(os.path.split(os.path.dirname(__file__))[0], 'custom_courses/' + course_name + '/index.rst'),'w')
file.write(newtext)
file.close()
print(request.vars)
return 'ok'
except Exception as ex:
print(ex)

20 changes: 17 additions & 3 deletions static/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function gradeIndividualItem() {
}



function getRightSideGradingDiv(element, acid, studentId) {
if (!eBookConfig.gradingURL) {
alert("Can't grade without a URL");
Expand Down Expand Up @@ -786,7 +787,7 @@ function create_question(formdata) {
var template = formdata.template.value;
var name = formdata.qname.value;
var question = formdata.qcode.value;
question = question.replace(/(\n)+/g, '%0A');
question = question.replace(/(\r\n|\n|\r)/gm, '%0A');
var difficulty = formdata.difficulty;
for (var i = 0; i < difficulty.length; i++) {
if (difficulty[i].checked == true) {
Expand Down Expand Up @@ -1223,7 +1224,7 @@ function edit_question(form) {
}
}
var question_text = form.editRST.value;
question_text = question_text.replace(/(\n)+/g, '%0A'); //encodes all new line characters to preserve them in query string
question_text = question_text.replace(/(\r\n|\n|\r)/gm, '%0A'); //encodes all new line characters to preserve them in query string

var obj = new XMLHttpRequest();
obj.open('POST', '/runestone/admin/edit_question/?question=' + question_name + '&tags=' + tags + '&difficulty=' + difficulty + '&name=' + name + '&questiontext=' + question_text, true);
Expand Down Expand Up @@ -1305,4 +1306,17 @@ function changeDescription(form) {
}
}

}
}

function edit_indexrst(form) {
var newtext = form.editIndex.value;
newtext = newtext.replace(/(\r\n|\n|\r)/gm, '%0A'); //encodes all new line characters to preserve them in query string
var obj = new XMLHttpRequest();
obj.open('POST', '/runestone/admin/editindexrst?newtext=' + newtext, true);
obj.send(JSON.stringify({variable:'variable'}));
obj.onreadystatechange = function () {
if (obj.readyState == 4 && obj.status == 200) {
alert("Successfully edited index.rst");

}}
}
42 changes: 42 additions & 0 deletions views/admin/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ <h4 style="text-align: center" class="list-group-item-heading">Add TA</h4>
<a id="DeleteTab" data-toggle="tab" href="#Delete" class="list-group-item">
<h4 style="text-align: center" class="list-group-item-heading">Delete</h4>
</a>
<a id="changeIndexTab" data-toggle="tab" href="#changeIndex" class="list-group-item">
<h4 style="text-align: center" class="list-group-item-heading">Edit Index</h4>
</a>

<div style="margin-top: 125px; border-top: dashed">

Expand Down Expand Up @@ -229,6 +232,23 @@ <h3 style="text-align: center">This action CANNOT BE UNDONE</h3>
<h3 style="text-align: center">This will delete all sections under this course. Students will not be able to access course materials.</h3>
</div>
</div>

<div id="changeIndex" class="tab-pane fade">
<div class="col-md-3">
<form id="editIndexRST" action="">
<div class="form-group">
<label for="editIndex">Edit index.rst</label>
<textarea style="white-space: pre; overflow-x: auto;" id="editIndex" cols="100" name="editIndex" placeholder="" rows="20"></textarea>

</div>
<input type="button" class="btn btn-default" Value="Submit" data-dismiss="modal" onClick="edit_indexrst(this.form);">

</form>

</div>


</div>
</div>

<script>
Expand All @@ -243,6 +263,7 @@ <h3 style="text-align: center">This will delete all sections under this course.
$('#rebuildTab').css('background-color','transparent');
$('#AddInstructorTab').css('background-color','transparent');
$('#DeleteTab').css('background-color','transparent');
$('#changeIndexTab').css('background-color','transparent');

});

Expand All @@ -251,6 +272,7 @@ <h3 style="text-align: center">This will delete all sections under this course.
$('#sectionsTab').css('background-color','transparent');
$('#AddInstructorTab').css('background-color','transparent');
$('#DeleteTab').css('background-color','transparent');
$('#changeIndexTab').css('background-color','transparent');

});

Expand All @@ -259,6 +281,7 @@ <h3 style="text-align: center">This will delete all sections under this course.
$('#sectionsTab').css('background-color','transparent');
$('#rebuildTab').css('background-color','transparent');
$('#DeleteTab').css('background-color','transparent');
$('#changeIndexTab').css('background-color','transparent');

});

Expand All @@ -267,6 +290,25 @@ <h3 style="text-align: center">This will delete all sections under this course.
$('#sectionsTab').css('background-color','transparent');
$('#rebuildTab').css('background-color','transparent');
$('#AddInstructorTab').css('background-color','transparent');
$('#changeIndexTab').css('background-color','transparent');

});

$('#changeIndexTab').click(function(){
$('#changeIndexTab').css('background-color', 'gainsboro');
$('#sectionsTab').css('background-color','transparent');
$('#rebuildTab').css('background-color','transparent');
$('#AddInstructorTab').css('background-color','transparent');
$('#DeleteTab').css('background-color','transparent');
var obj = new XMLHttpRequest();
obj.open('GET','/runestone/admin/indexrst/', true);
obj.send(JSON.stringify({avariable: 'avariable'}));
obj.onreadystatechange = function() {
if (obj.readyState == 4 && obj.status == 200) {
filetext = JSON.parse(obj.responseText);
var textarea = document.getElementById('editIndex');
textarea.innerHTML = filetext;
}}

});

Expand Down

0 comments on commit 6b2de44

Please sign in to comment.