Skip to content

Commit

Permalink
Added default file read code for all languages and option to enable i…
Browse files Browse the repository at this point in the history
…n studio
  • Loading branch information
RehanAziz authored and RehanAziz committed Apr 18, 2022
1 parent 310d909 commit 1076ce6
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions openassessment/templates/openassessmentblock/edit/oa_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ <h2 class="openassessment_alert_title">{% trans "Rubric Change Impacts Settings
{% trans "Indicates whether or not to show private test case results. This only shows if the case passed or failed, it does not show any values."%}
</p>
</li>
<li class="field comp-setting-entry">
<div class="wrapper-comp-setting">
<label for="openassessment_show_file_read_code_editor" class="setting-label">
{% trans "Show File Read Code"%}
</label>
<select id="openassessment_show_file_read_code_editor" class="input setting-input">
<option value="0">{% trans "False"%}</option>
<option value="1" {% if show_file_read_code %} selected="true" {% endif %}>
{% trans "True"%}
</option>
</select>
</div>
<p class="setting-help">
{% trans "Indicates whether or not to show file read code."%}
</p>
</li>
<li class="openassessment_date_editor field comp-setting-entry">
<div class="wrapper-comp-setting">
<label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ <h4 class="step__title">
<textarea
id="submission__answer__part__text__{{ xblock_id }}"
class="submission__answer__part__text__value"
show_file_read_code="{{show_file_read_code}}"
data-preview="submission"
aria-labelledby="submission__answer__part__text__title__{{ xblock_id }}"
aria-describedby="submission__answer__tip__{{ xblock_id }}"
Expand Down
6 changes: 6 additions & 0 deletions openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ class OpenAssessmentBlock(MessageMixin,
help="Indicates whether or not to show private test case results (passed or failed only, does not show values)."
)

show_file_read_code = Boolean(
default=False,
scope=Scope.content,
help="Indicates whether or not to show file read code."
)

@property
def labels(self):
return ",".join(self.label_list)
Expand Down
1 change: 1 addition & 0 deletions openassessment/xblock/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def labels_validator(value):
Required('title'): utf8_validator,
Required('labels'): All(utf8_validator, labels_validator),
Required('show_private_test_case_results'): bool,
Required('show_file_read_code'): bool,
Required('feedback_prompt'): utf8_validator,
Required('feedback_default_text'): utf8_validator,
Required('submission_start'): Any(datetime_validator, None),
Expand Down
64 changes: 64 additions & 0 deletions openassessment/xblock/static/js/src/lms/oa_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ OpenAssessment.ResponseView = function(element, server, fileUploader, baseView,
this.baseView = baseView;
this.savedResponse = [];
this.textResponse = 'required';
this.showFileUplaodCode = false;
this.fileUploadResponse = '';
this.files = null;
this.filesDescriptions = [];
Expand Down Expand Up @@ -109,6 +110,8 @@ OpenAssessment.ResponseView.prototype = {

var submit = $('.step--response__submit', this.element);
this.textResponse = $(submit).attr('text_response');
var editor_textarea = $('.response__submission .submission__answer__part__text__value', this.element);
this.showFileUplaodCode = $(editor_textarea).attr('show_file_read_code');
this.fileUploadResponse = $(submit).attr('file_upload_response');

// Install a click handler for submission
Expand Down Expand Up @@ -582,7 +585,68 @@ OpenAssessment.ResponseView.prototype = {
var language = this.getLanguage();
this.updateEditorMode(language);
this.handleResponseChanged();
let defaulCodes = {
"Python":"import sys\n" +
"\n" +
"lines = open(sys.argv[1], 'r').readlines()\n" +
"\n" +
"# Write your code here.",
"NodeJS":"const fs = require('fs');\n" +
"\n" +
"const args = process.argv.slice(2);\n" +
"const fileName = args[0];\n" +
"\n" +
"const content = fs.readFileSync(fileName).toString();\n" +
"const lines = content.split('\\n');\n" +
"\n" +
"// Write your code here.",
"Java":"import java.io.File;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.util.Scanner;\n" +
"\n" +
"\n" +
"public class Main {\n" +
" public static void main(String[] args) {\n" +
" try {\n" +
" File inputFile = new File(args[0]);\n" +
" Scanner inputReader = new Scanner(inputFile);\n" +
" while (inputReader.hasNextLine()) {\n" +
" String line = inputReader.nextLine();\n" +
"\n" +
" // Write your code here.\n" +
"\n" +
" }\n" +
" inputReader.close();\n" +
" } catch (FileNotFoundException e) {\n" +
" System.out.println(\"An error occurred.\");\n" +
" e.printStackTrace();\n" +
" }\n" +
" }\n" +
"}",
"C++":"#include <iostream>\n" +
"#include <fstream>\n" +
"\n" +
"using namespace std;\n" +
"\n" +
"\n" +
"int main(int argc, char *argv[]) {\n" +
" ifstream inputFile(argv[1]);\n" +
"\n" +
" string line = \"\";\n" +
" do {\n" +
" getline(inputFile, line);\n" +
"\n" +
" // Write your code here.\n" +
"\n" +
" } while(inputFile.good());\n" +
"\n" +
" return 0;\n" +
"}"
}

if(this.showFileUplaodCode === 'True' && (this.codeEditor.getValue() === '' || Object.values(defaulCodes).includes(this.codeEditor.getValue()))){
this.codeEditor.setValue(defaulCodes[language]);
}
},

/**
Expand Down
1 change: 1 addition & 0 deletions openassessment/xblock/static/js/src/oa_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ if (typeof OpenAssessment.Server === "undefined" || !OpenAssessment.Server) {
white_listed_file_types: options.fileTypeWhiteList,
allow_latex: options.latexEnabled,
show_private_test_case_results: options.showPrivateTestCaseResultsEnabled,
show_file_read_code: options.showFileReadCodeEnabled,
leaderboard_show: options.leaderboardNum
});
return $.Deferred(function(defer) {
Expand Down
1 change: 1 addition & 0 deletions openassessment/xblock/static/js/src/studio/oa_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ OpenAssessment.StudioView.prototype = {
fileTypeWhiteList: view.settingsView.fileTypeWhiteList(),
latexEnabled: view.settingsView.latexEnabled(),
showPrivateTestCaseResultsEnabled: view.settingsView.showPrivateTestCaseResultsEnabled(),
showFileReadCodeEnabled: view.settingsView.showFileReadCodeEnabled(),
leaderboardNum: view.settingsView.leaderboardNum(),
editorAssessmentsOrder: view.settingsView.editorAssessmentsOrder(),
}).done(
Expand Down
16 changes: 16 additions & 0 deletions openassessment/xblock/static/js/src/studio/oa_edit_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ OpenAssessment.EditSettingsView.prototype = {
return sel.val() === '1';
},

/**
Enable / disable rendering of read file code.
Args:
isEnabled(boolean, optional): if provided enable/disable rendering of read file code.
Returns:
boolean
**/
showFileReadCodeEnabled: function(isEnabled) {
var sel = $('#openassessment_show_file_read_code_editor', this.settingsElement);
if (isEnabled !== undefined) {
sel.val(Number(isEnabled));
}
return sel.val() === '1';
},

/**
Get or set the number of scores to show in the leaderboard.
If set to 0, the leaderboard will not be shown.
Expand Down
3 changes: 3 additions & 0 deletions openassessment/xblock/studio_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def editor_context(self):
'submission_start' (unicode), 'submission_due' (unicode),
'assessments' (dict), 'labels' (unicode),
'show_private_test_case_results' (boolean),
'show_file_read_code' (boolean),
"""
# In the authoring GUI, date and time fields should never be null.
Expand Down Expand Up @@ -155,6 +156,7 @@ def editor_context(self):
'white_listed_file_types': self.white_listed_file_types_string,
'allow_latex': self.allow_latex,
'show_private_test_case_results': self.show_private_test_case_results,
'show_file_read_code': self.show_file_read_code,
'leaderboard_show': self.leaderboard_show,
'editor_assessments_order': [
make_django_template_key(asmnt)
Expand Down Expand Up @@ -258,6 +260,7 @@ def update_editor_context(self, data, suffix=''): # pylint: disable=unused-argu
self.white_listed_file_types_string = None
self.allow_latex = bool(data['allow_latex'])
self.show_private_test_case_results = bool(data['show_private_test_case_results'])
self.show_file_read_code = bool(data['show_file_read_code'])
self.leaderboard_show = data['leaderboard_show']

return {'success': True, 'msg': self._(u'Successfully updated OpenAssessment XBlock')}
Expand Down
1 change: 1 addition & 0 deletions openassessment/xblock/submission_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ def submission_path_and_context(self):
'user_language': user_preferences['user_language'],
"xblock_id": self.get_xblock_id(),
"text_response": self.text_response,
"show_file_read_code": self.show_file_read_code,
"file_upload_response": self.file_upload_response,
"prompts_type": self.prompts_type,
}
Expand Down

0 comments on commit 1076ce6

Please sign in to comment.