CSC/ECE 517 Fall 2021 - E2138. Auto-generate submission directory names based on assignment: Difference between revisions
(edited Project implementation section) |
m (minor formatting changes) |
||
Line 3: | Line 3: | ||
__TOC__ | __TOC__ | ||
=Overview= | = Overview = | ||
==About Expertiza== | == About Expertiza == | ||
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages. | [http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages. | ||
==Issues for this project== | == Issues for this project == | ||
When instructors give an assignment a name, submission directories should be auto-generated based on the assignment name, and also be unique. A number of issues existed when a previous team worked on this assignment (E2054), including | When instructors give an assignment a name, submission directories should be auto-generated based on the assignment name, and also be unique. A number of issues existed when a previous team worked on this assignment (E2054), including | ||
Line 18: | Line 18: | ||
* Issue #5: On changing the name of an assignment while creating it, the code shouldn't throw a NoMethodError. | * Issue #5: On changing the name of an assignment while creating it, the code shouldn't throw a NoMethodError. | ||
= Project implementation = | |||
= | == Submitted work and demonstration of project == | ||
* [http://152.7.98.88:8080/ Link to deployed code on NCSU VCL] | * [http://152.7.98.88:8080/ Link to deployed code on NCSU VCL] | ||
* [https://github.com/SN-18/expertiza Link to our Github repository] | * [https://github.com/SN-18/expertiza Link to our Github repository] | ||
Line 32: | Line 32: | ||
== Changes made to code == | == Changes made to code == | ||
===views=== | === views === | ||
The following code was added to <b>app/views/assignments/edit/_general.html.erb</b>. The purpose is to generate submission directory name from the assignment name and substitute the spacebar with underscore. | The following code was added to <b>app/views/assignments/edit/_general.html.erb</b>. The purpose is to generate submission directory name from the assignment name and substitute the spacebar with underscore. | ||
Line 51: | Line 51: | ||
</pre> | </pre> | ||
===models=== | === models === | ||
The following code was added to <b>app/models/assignment.rb</b>'s Assignment class, to add validation for assignment name and directory. | The following code was added to <b>app/models/assignment.rb</b>'s Assignment class, to add validation for assignment name and directory. | ||
<pre> | <pre> | ||
Line 58: | Line 58: | ||
</pre> | </pre> | ||
===controllers=== | === controllers === | ||
The following code was modified in <b>app/controllers/assignments_controller.rb</b>'s create method, adding checks for assignment name and directory when creating assignment. | The following code was modified in <b>app/controllers/assignments_controller.rb</b>'s create method, adding checks for assignment name and directory when creating assignment. | ||
Revision as of 00:36, 20 October 2021
This wiki page describes the changes made under E2138, in order to auto-generate submission directory names based on assignment names for Fall 2021, CSC/ECE 517.
Overview
About Expertiza
Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.
Issues for this project
When instructors give an assignment a name, submission directories should be auto-generated based on the assignment name, and also be unique. A number of issues existed when a previous team worked on this assignment (E2054), including
- Issue #1: The directory name should be auto-generated from the assignment name.
- Issue #2: It should be done by changing spaces in the names to underscores. E.g., the directory for Program 1 is by default "Program_1".
- Issue #3: A check should be added to prevent two assignments in the same course from having the same name.
- Issue #4: Verify or add if not present - a check to stop two assignments from sharing the same directory.
- Issue #5: On changing the name of an assignment while creating it, the code shouldn't throw a NoMethodError.
Project implementation
Submitted work and demonstration of project
Files involved
- app/views/assignments/edit/_general.html.erb - added function that auto generate directory name, and substitute its spacebar with underscore.
- app/models/assignment.rb - added presence and uniqueness validation to assignment.
- app/controllers/assignments_controller.rb - modify create method to check for existing assignment name & directory.
Changes made to code
views
The following code was added to app/views/assignments/edit/_general.html.erb. The purpose is to generate submission directory name from the assignment name and substitute the spacebar with underscore.
<script> ... $(function() { $("#assignment_form_assignment_name").change(function() { filename = $( "#assignment_form_assignment_name" ).val().replace(/ /g,"_").replace(/[/\\?%*:|"<>/$&!#%^@]/g, '');; $('#assignment_form_assignment_directory_path').val(filename); }); }); function autogenerate_submission(){ assignment_form.assignment.directory_path = assignment_form.assignment.name; } </script>
models
The following code was added to app/models/assignment.rb's Assignment class, to add validation for assignment name and directory.
validates :directory_path, presence: true # E2138 Validation for unique submission directory validates :directory_path, uniqueness: {scope: :course_id}
controllers
The following code was modified in app/controllers/assignments_controller.rb's create method, adding checks for assignment name and directory when creating assignment.
Before
def create @assignment_form = AssignmentForm.new(assignment_form_params) if params[:button] if @assignment_form.save @assignment_form.create_assignment_node exist_assignment = Assignment.find_by(id: @assignment_form.assignment.id) assignment_form_params[:assignment][:id] = exist_assignment.id.to_s if assignment_form_params[:assignment][:directory_path].blank? assignment_form_params[:assignment][:directory_path] = "assignment_#{assignment_form_params[:assignment][:id]}" end ques_array = assignment_form_params[:assignment_questionnaire] due_array = assignment_form_params[:due_date] ques_array.each do |cur_questionnaire| cur_questionnaire[:assignment_id] = exist_assignment.id.to_s end due_array.each do |cur_due| cur_due[:parent_id] = exist_assignment.id.to_s end assignment_form_params[:assignment_questionnaire] = ques_array assignment_form_params[:due_date] = due_array @assignment_form.update(assignment_form_params, current_user) aid = Assignment.find_by(id: @assignment_form.assignment.id).id ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}" redirect_to edit_assignment_path aid undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ") return else flash.now[:error] = "Failed to create assignment" render 'new' end else render 'new' undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ") end end
After
def create @assignment_form = AssignmentForm.new(assignment_form_params) if params[:button] # E2138 issue #3 find_existing_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id) dir_path = assignment_form_params[:assignment][:directory_path] find_existing_directory = Assignment.find_by(directory_path: dir_path, course_id: @assignment_form.assignment.course_id) if !find_existing_assignment and !find_existing_directory and @assignment_form.save #No existing names/directories @assignment_form.create_assignment_node current_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id) assignment_form_params[:assignment][:id] = current_assignment.id.to_s ques_array = assignment_form_params[:assignment_questionnaire] due_array = assignment_form_params[:due_date] ques_array.each do |cur_questionnaire| cur_questionnaire[:assignment_id] = current_assignment.id.to_s end due_array.each do |cur_due| cur_due[:parent_id] = current_assignment.id.to_s end assignment_form_params[:assignment_questionnaire] = ques_array assignment_form_params[:due_date] = due_array @assignment_form.update(assignment_form_params, current_user) aid = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id).id ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}" redirect_to edit_assignment_path aid undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ") return else flash[:error] = "Failed to create assignment." if find_existing_assignment flash[:error] << "<br> " + @assignment_form.assignment.name + " already exists as an assignment name" end if find_existing_directory flash[:error] << "<br> " + dir_path + " already exists as a submission directory name" end redirect_to "/assignments/new?private=1" end else render 'new' undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ") end end
Test Plan
Manual UI Testing
RSpec Testing
Team Information
Mentor: Nicholas Himes (nnhimes)
Henry Chen (hchen34)
Saurabh Nanda (snanda2)
Snehapriyaa Mathiyalaghan (smathiy)