E1728. Remove useless partials from grades view and move view logic to grades helper.rb: Difference between revisions
Line 214: | Line 214: | ||
@title | @title | ||
end | end | ||
</pre> | |||
The following lines of code in the _participant.html.erb file were also replaced to use the above properties created | |||
;Original | |||
<pre> | |||
<% if !@rscore_review.nil? && @rscore_review.my_avg %> | |||
</pre> | |||
;Replacement | |||
<pre> | |||
<% if !rscore_review.nil? && rscore_review.my_avg %> | |||
</pre> | </pre> | ||
==Test Plans== | ==Test Plans== |
Revision as of 22:05, 21 March 2017
Introduction
This wiki provides details on the refactoring tasks that were undertaken as part of the continuous improvement to the Expertiza project
Background
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.
The application provides a complete system through which students and instructors collaborate on the learning objects as well as submit, review and grade assignments for the courses.
Motivation
By participating in the overall refactoring effort as part of the continuous improvement of Expertiza, students get an opportunity to work on a open source software project. This helps them gain exposure on the technologies used in the project as well as much needed experience in collaborating with peers as part of the software development process.
Tasks
The tasks involved as part of this refactoring effort were geared towards cleaning up the grade view logic.
Initial Task List
The initial set of tasks were:
- For files: _scores_author_feedback.html.erb, _scores_metareview.html.erb, _scores_submitted_work.html.erb
- Move javascript code to assets
- For files: _scores_header.html.erb
- Move logical code (such as L43-96) to helper file and assign self-explanatory method name
- For files: _participant.html.erb, view_team.html.erb
- Move javascript code to assets
- Move logical code to helper file and assign self-explanatory method name
- Such as L8-22 in _participant.html.erb
- Create test file named grades_helper_spec.rb in spec/helpers
- Write test cases for all methods in grades_helper.rb
Revised Task List
On working with files _scores_author_feedback.html.erb, _scores_metareview.html.erb, _scores_submitted_work.html.erb, _scores_header.html.erb, the team came to find out that these files were not being used anymore in the application and the overall tasks were updated to the following:
- Remove useless partials from grades view, such as _scores_author_feedback.html.erb, _scores_metareview.html.erb, _scores_submitted_work.html.erb, _scores_header.html.erb, etc.
- For files _participant.html.erb, view_team.html.erb to grades_helper.rb
- Move javascript code to assets
- Move logical code to helper file and assign self-explanatory method name such as L8-22 in _participant.html.erb
- Create test file named grades_helper_spec.rb in spec/helpers
- Write test cases for all methods in grades_helper.rb by using factories
Refactoring Tasks
Remove useless partials from grades view, such as _scores_author_feedback.html.erb, _scores_metareview.html.erb, _scores_submitted_work.html.erb, _scores_header.html.erb, etc.
The named files were removed from the project and the deletions were committed to the repository
For files _participant.html.erb, view_team.html.erb to grades_helper.rb
Move javascript code to assets
A new file was created and added to the project: app/assets/javascripts/grades/view_team.js
For the view_team.html.erb file, the javascript code was moved to view_team.js
$=jQuery; $(function () { $("[data-toggle='tooltip']").tooltip(); $("#scoresTable").tablesorter(); }); var lesser = false; // Function to sort the columns based on the total review score function col_sort(m) { lesser = !lesser // Swaps two columns of the table jQuery.moveColumn = function (table, from, to) { var rows = jQuery('tr', table); var hidden_child_row = table.find('tr.tablesorter-childRow'); hidden_child_row.each(function () { inner_table = jQuery(this).find('table.tbl_questlist') hidden_table = inner_table.eq(0).find('tr') hidden_table.eq(from - 1).detach().insertBefore(hidden_table.eq(to - 1)); if (from - to > 1) { hidden_table.eq(to - 1).detach().insertAfter((hidden_table.eq(from - 2))); } }); var cols; rows.each(function () { cols = jQuery(this).children('th, td'); cols.eq(from).detach().insertBefore(cols.eq(to)); if (from - to > 1) { cols.eq(to).detach().insertAfter((cols.eq(from - 1))); } }); } // Gets all the table with the class "tbl_heat" var tables = $("table.tbl_heat"); // Get all the rows with the class accordion-toggle var tbr = tables.eq(m).find('tr.accordion-toggle'); // Get the cells from the last row of the table var columns = tbr.eq(tbr.length - 1).find('td'); // Init an array to hold the review total var sum_array = []; // iterate through the rows and calculate the total of each review for (var l = 2; l < columns.length - 2; l++) { var total = 0; for (var n = 0; n < tbr.length; n++) { var row_slice = tbr.eq(n).find('td'); if (parseInt(row_slice[l].innerHTML) > 0) { total = total + parseInt(row_slice[l].innerHTML) } } sum_array.push(total) } // The sorting algorithm for (var i = 3; i < columns.length - 2; i++) { var j = i; while (j > 2 && compare(sum_array[j - 2], sum_array[j - 3], lesser)) { var tmp tmp = sum_array[j - 3] sum_array[j - 3] = sum_array[j - 2] sum_array[j - 2] = tmp jQuery.moveColumn($("table.tbl_heat").eq(m), j, j - 1); // This part is repeated since the table is updated tables = $("table.tbl_heat") tbr = tables.eq(m).find('tr.accordion-toggle'); columns = tbr.eq(tbr.length - 1).find('td') j = j - 1; } } } // Function to return boolean based on lesser or greater operator function compare(a, b, less) { if (less) { return a < b } else { return a > b } }
Move logical code to helper file and assign self-explanatory method name such as L8-22 in _participant.html.erb
The following lines of code were removed
<% participant = pscore[:participant] if pscore[:review] @rscore_review=Rscore.new(pscore,:review) end if pscore[:metareview] @rscore_metareview=Rscore.new(pscore,:metareview) end if pscore[:feedback] @rscore_feedback=Rscore.new(pscore,:feedback) end if pscore[:teammate] @rscore_teammate=Rscore.new(pscore,:teammate) end %>
and converted to properties in the GradesHelper module defined in the app/helpers/grades_helper.rb file
def participant @participant = Participant.find(params[:id]) end def rscore_review @participant = Participant.find(params[:id]) @pscore = @participant.scores(@questions) if @pscore[:review] @rscore_review=Rscore.new(@pscore,:review) end @rscore_review end def rscore_metareview @participant = Participant.find(params[:id]) @pscore = @participant.scores(@questions) if @pscore[:metareview] @rscore_metareview=Rscore.new(@pscore,:metareview) end @rscore_metareview end def rscore_feedback @participant = Participant.find(params[:id]) @pscore = @participant.scores(@questions) if @pscore[:feedback] @rscore_feedback=Rscore.new(@pscore,:feedback) end @rscore_feedback end def rscore_teammate @participant = Participant.find(params[:id]) @pscore = @participant.scores(@questions) if @pscore[:teammate] @rscore_teammate=Rscore.new(@pscore,:teammate) end @rscore_teammate end def p_total_score @participant = Participant.find(params[:id]) @pscore = @participant.scores(@questions) if @participant.grade @total_score = participant.grade else @total_score = @pscore[:total_score] end @total_score end def p_title @participant = Participant.find(params[:id]) if @participant.grade @title = "A score in blue indicates that the value was overwritten by the instructor or teaching assistant." else @title = nil end @title end
The following lines of code in the _participant.html.erb file were also replaced to use the above properties created
- Original
<% if !@rscore_review.nil? && @rscore_review.my_avg %>
- Replacement
<% if !rscore_review.nil? && rscore_review.my_avg %>