Skip to content

Commit e88391e

Browse files
committed
[#3952] Pre select all projects, users, and activities.
1 parent 7edde14 commit e88391e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

app/controllers/timesheet_controller.rb

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def index
2020
load_filters_from_session
2121
unless @timesheet
2222
@timesheet ||= Timesheet.new
23-
@timesheet.users = [] # Clear users so they aren't selected
2423
end
2524
@timesheet.allowed_projects = allowed_projects
2625

app/helpers/timesheet_helper.rb

+11-4
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,28 @@ def displayed_time_entries_for_issue(time_entries)
4646
end
4747

4848
def project_options(timesheet)
49-
options_from_collection_for_select(timesheet.allowed_projects,
49+
available_projects = timesheet.allowed_projects
50+
selected_projects = timesheet.projects.collect(&:id)
51+
selected_projects = available_projects.collect(&:id) if selected_projects.blank?
52+
53+
options_from_collection_for_select(available_projects,
5054
:id,
5155
:name,
52-
timesheet.projects.collect(&:id))
56+
selected_projects)
5357
end
5458

5559
def activity_options(timesheet, activities)
5660
options_from_collection_for_select(activities, :id, :name, timesheet.activities)
5761
end
5862

5963
def user_options(timesheet)
60-
options_from_collection_for_select(Timesheet.viewable_users.sort { |a,b| a.to_s.downcase <=> b.to_s.downcase },
64+
available_users = Timesheet.viewable_users.sort { |a,b| a.to_s.downcase <=> b.to_s.downcase }
65+
selected_users = timesheet.users
66+
67+
options_from_collection_for_select(available_users,
6168
:id,
6269
:name,
63-
timesheet.users)
70+
selected_users)
6471

6572
end
6673
end

0 commit comments

Comments
 (0)