CSC/ECE 517 Spring 2020 - E2006. Refactor Tree Display Controller: Difference between revisions
Line 40: | Line 40: | ||
In the legacy code, 60 lines are dedicated to the 12 methods related to traversing the menu system. 11 of the methods call the '''goto_controller()''' method with different values, so we decided that those 11 methods could be condensed into single line methods with one overarching comment to describe them. | In the legacy code, 60 lines are dedicated to the 12 methods related to traversing the menu system. 11 of the methods call the '''goto_controller()''' method with different values, so we decided that those 11 methods could be condensed into single line methods with one overarching comment to describe them. | ||
===='''Original Implementation'''==== | |||
< | <pre style="color: red"> | ||
< | # refactored method to provide direct access to parameters | ||
def goto_controller(name_parameter) | |||
node_object = TreeFolder.find_by(name: name_parameter) | |||
session[:root] = FolderNode.find_by(node_object_id: node_object.id).id | |||
redirect_to controller: 'tree_display', action: 'list' | |||
end | |||
# direct access to questionnaires | |||
def goto_questionnaires | |||
goto_controller('Questionnaires') | |||
end | |||
# direct access to review rubrics | |||
def goto_review_rubrics | |||
goto_controller('Review') | |||
end | |||
# direct access to metareview rubrics | |||
def goto_metareview_rubrics | |||
goto_controller('Metareview') | |||
end | |||
# direct access to teammate review rubrics | |||
def goto_teammatereview_rubrics | |||
goto_controller('Teammate Review') | |||
end | |||
# direct access to author feedbacks | |||
def goto_author_feedbacks | |||
goto_controller('Author Feedback') | |||
end | |||
# direct access to global survey | |||
def goto_global_survey | |||
goto_controller('Global Survey') | |||
end | |||
# direct access to surveys | |||
def goto_surveys | |||
goto_controller('Assignment Survey') | |||
end | |||
# direct access to course surveys | |||
def goto_course_surveys | |||
goto_controller('Course Survey') | |||
end | |||
# direct access to courses | |||
def goto_courses | |||
goto_controller('Courses') | |||
end | |||
def goto_bookmarkrating_rubrics | |||
goto_controller('Bookmarkrating') | |||
end | |||
# direct access to assignments | |||
def goto_assignments | |||
goto_controller('Assignments') | |||
end | |||
</pre> | |||
===='''Proposed Implementation'''==== | |||
<pre style="color: green"> | |||
# The goto_ methods listed below are used to traverse the menu system. It is | # The goto_ methods listed below are used to traverse the menu system. It is | ||
# hard to tell exactly where they are called from, but at least some (if not all) | # hard to tell exactly where they are called from, but at least some (if not all) | ||
Line 63: | Line 125: | ||
def goto_bookmarkrating_rubrics; goto_controller('Bookmarkrating') end | def goto_bookmarkrating_rubrics; goto_controller('Bookmarkrating') end | ||
def goto_assignments; goto_controller('Assignments') end | def goto_assignments; goto_controller('Assignments') end | ||
</ | </pre> | ||
===Files modified=== | ===Files modified=== |
Revision as of 20:25, 22 March 2020
E2006. Refactor tree_display_controller.rb
About Expertiza
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.
Project Description
Problem Statement
E2006. Refactor tree_display_controller.rb
Background
The tree_display_controller is responsible for rendering hierarchical lists in the instructor user interface. Here is a sample instructor homepage:
You will see here that assignments are nested within courses. This means that the node for an assignment has a parent_id that points to a node for a course. Similarly, listings of questionnaires are hierarchical:
The various rubrics, as well as surveys, are types of questionnaires. So the parent_id of a particular rubric will be the type of rubric (e.g., teammate review) that it is.
The tree_display_controller is 379 lines long, and contains 45 methods. Many of those methods have similar names, yet there may be good reasons for having separate methods. Look over how these methods are used, and then decide. Then analyze the rest of the methods and try to find ways to save code and avoid DRY issues. Even if you cannot find a way to improve a method, you should be able to come up with a 1-line or 2-line comment explaining what that method does.
Issues
From the problem background, we have derived three main issues to focus on in the tree display controller:
- Remove unnecessary methods - Search the 45 methods defined in the controller to see where and why they are called. Remove outdated and unused methods, and see where it is fit to merge or replace methods.
- Save code and avoid DRY issues - In addition to removing unnecessary methods, code should be reduced wherever possible to make the controller smaller an easier to read.
- Improve understanding - For all necessary, complex methods in the controller, comments should be added to improve understanding of what methods do. This way, future reviewers won't have to search for implementations to understand the functionality when working on other issues.
Current Implementation
To be completed. (Repeat issues above and how they are currently being dealt with if they have a current solution).
Proposed Implementation
Collapse 'goto' methods
In the legacy code, 60 lines are dedicated to the 12 methods related to traversing the menu system. 11 of the methods call the goto_controller() method with different values, so we decided that those 11 methods could be condensed into single line methods with one overarching comment to describe them.
Original Implementation
# refactored method to provide direct access to parameters def goto_controller(name_parameter) node_object = TreeFolder.find_by(name: name_parameter) session[:root] = FolderNode.find_by(node_object_id: node_object.id).id redirect_to controller: 'tree_display', action: 'list' end # direct access to questionnaires def goto_questionnaires goto_controller('Questionnaires') end # direct access to review rubrics def goto_review_rubrics goto_controller('Review') end # direct access to metareview rubrics def goto_metareview_rubrics goto_controller('Metareview') end # direct access to teammate review rubrics def goto_teammatereview_rubrics goto_controller('Teammate Review') end # direct access to author feedbacks def goto_author_feedbacks goto_controller('Author Feedback') end # direct access to global survey def goto_global_survey goto_controller('Global Survey') end # direct access to surveys def goto_surveys goto_controller('Assignment Survey') end # direct access to course surveys def goto_course_surveys goto_controller('Course Survey') end # direct access to courses def goto_courses goto_controller('Courses') end def goto_bookmarkrating_rubrics goto_controller('Bookmarkrating') end # direct access to assignments def goto_assignments goto_controller('Assignments') end
Proposed Implementation
# The goto_ methods listed below are used to traverse the menu system. It is # hard to tell exactly where they are called from, but at least some (if not all) # are necessary. These functions may be better suited for another controller. def goto_controller(name_parameter) node_object = TreeFolder.find_by(name: name_parameter) session[:root] = FolderNode.find_by(node_object_id: node_object.id).id redirect_to controller: 'tree_display', action: 'list' end def goto_questionnaires; goto_controller('Questionnaires') end def goto_review_rubrics; goto_controller('Review') end def goto_metareview_rubrics; goto_controller('Metareview') end def goto_teammatereview_rubrics; goto_controller('Teammate Review') end def goto_author_feedbacks; goto_controller('Author Feedback') end def goto_global_survey; goto_controller('Global Survey') end def goto_surveys; goto_controller('Assignment Survey') end def goto_course_surveys; goto_controller('Course Survey') end def goto_courses; goto_controller('Courses') end def goto_bookmarkrating_rubrics; goto_controller('Bookmarkrating') end def goto_assignments; goto_controller('Assignments') end
Files modified
To be completed.
Test Plan
To be completed.
Code Coverage
To be completed.
Team Information
Brooks Anderson
Rick Holloway
PJ Loheide
Mentor: Dr. Edward Gehringer
References
To be completed.