CSC/ECE 517 Fall 2016/E1673. Refactor question type.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 20: Line 20:
  def view_completed_question(count, answer)
  def view_completed_question(count, answer)
     if self.type == 'TextField' and self.break_before == true
     if self.type == 'TextField' and self.break_before == true
       html = '<b>' + count.to_s + ". " + self.txt + "</b>"
       html = view_helper_true(count, answer)
      html += '&nbsp;&nbsp;&nbsp;&nbsp;'
      html += answer.comments
       html += '<BR/><BR/>' if Question.exists?(answer.question_id + 1) && Question.find(answer.question_id + 1).break_before == true
       html += '<BR/><BR/>' if Question.exists?(answer.question_id + 1) && Question.find(answer.question_id + 1).break_before == true
     else
     else
       html = view_helper(answer)
       html = view_helper_false(answer)
     end
     end
     safe_join([" ".html_safe, " ".html_safe], html.html_safe)
     safe_join([" ".html_safe, " ".html_safe], html.html_safe)
   end
   end
def view_helper(answer)
    html = self.text
    html += answer.comments
    html += '<BR/><BR/>'
    html
end


===text_response.rb===
===text_response.rb===
: It makes codes more readable. We also choose safe_join instead of html_safe to prevent security risks. However, we must use html_safe to keep the character encoding.
: It makes codes more readable. We also choose safe_join instead of html_safe to prevent security risks. However, we must use html_safe to keep the character encoding.
  def edit(_count)
  def edit(_count)
     html = edit_1 + edit_2 + edit_3 + edit_4
     html = edit_link + edit_question_lable
    html += edit_question_textarea + edit_question_textarea_size
     safe_join(["<tr>".html_safe, "</tr>".html_safe], html.html_safe)
     safe_join(["<tr>".html_safe, "</tr>".html_safe], html.html_safe)
end
  end

Revision as of 23:41, 28 October 2016

Background

Expertiza is an open source software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages. It has following features:

  • Enables students working together in a class and a topic
  • Enables studnets to do peer review and improve both him/her and others' learn experience

Reason for Refractor

The purpose of this work is to rewrite the code of seven file for several reason listed below.

  • Line is too long
  • Some code found in other location and should put them in the parent class
  • Method has too many lines
  • Some of the code will cause security risk
  • Using the old style validations
  • Using a lower efficent way to do the loop

Code Changes

text_field.rb

Although it increase the number of classes, the length of function decrease and it's easy to read than before
def view_completed_question(count, answer)
   if self.type == 'TextField' and self.break_before == true
     html = view_helper_true(count, answer)
     html += '

' if Question.exists?(answer.question_id + 1) && Question.find(answer.question_id + 1).break_before == true else html = view_helper_false(answer) end safe_join([" ".html_safe, " ".html_safe], html.html_safe) end

text_response.rb

It makes codes more readable. We also choose safe_join instead of html_safe to prevent security risks. However, we must use html_safe to keep the character encoding.
def edit(_count)
   html = edit_link + edit_question_lable
   html += edit_question_textarea + edit_question_textarea_size

safe_join(["".html_safe, "".html_safe], html.html_safe) end