Since UsersController
was refactored to a resource yesterday, I started on the TimelogController
today. TimelogController
has a really messy list of actions:
- Two reporting methods (
#report
and#details
) -
#edit
handles 4 actions forTimeEntries
: form for new record, form for an existing record, saving a new record, and updating an existing record. - No
#index
or listing action. The#details
report kinda fulfills this purpose.
So the first thing I’m going to do is to use extract class to pull out the #report
action. This will make it easier to see what’s going on in this controller.
Before
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class TimelogController [:edit, :destroy] before_filter :find_optional_project, :only => [:report, :details] before_filter :load_available_criterias, :only => [:report] def report # ... end private def find_optional_project # ... end # Retrieves the date range based on predefined ranges or specific from/to param dates def retrieve_date_range # ... end def load_available_criterias # ... end def time_report_joins # ... end end |
After
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class TimelogController [:edit, :destroy] before_filter :find_optional_project, :only => [:details] # ... private def find_optional_project # ... end # Retrieves the date range based on predefined ranges or specific from/to param dates def retrieve_date_range # ... end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
class TimeEntryReportsController < ApplicationController menu_item :issues before_filter :find_optional_project before_filter :load_available_criterias helper :sort include SortHelper helper :issues helper :timelog include TimelogHelper helper :custom_fields include CustomFieldsHelper def report # ... end private # TODO: duplicated in TimelogController def find_optional_project # ... end # Retrieves the date range based on predefined ranges or specific from/to param dates # TODO: duplicated in TimelogController def retrieve_date_range # ... end def load_available_criterias # ... end def time_report_joins # ... end end |
Extracting the TimeEntryReportsController
wasn’t too easy. It uses a few utility methods in the controller which I also had to move or duplicate in TimeEntryReportsController
. Once I finish refactoring the rest of Redmine’s Controllers, I’ll be able to come back to this one and refactor it’s method bodies. But first I want to finish refactoring TimelogController
to a resource controller.