diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/timelog_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/queries_helper.rb | 11 | ||||
-rw-r--r-- | app/models/issue_query.rb | 2 | ||||
-rw-r--r-- | app/models/query.rb | 12 | ||||
-rw-r--r-- | app/models/time_entry_query.rb | 2 | ||||
-rw-r--r-- | app/views/settings/_timelog.html.erb | 14 |
6 files changed, 30 insertions, 13 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index b45d3078f..6bd7ab387 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -272,6 +272,6 @@ private end def retrieve_time_entry_query - retrieve_query(TimeEntryQuery, false) + retrieve_query(TimeEntryQuery, false, :defaults => Setting.time_entry_list_defaults.symbolize_keys) end end diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 2f6c92e1a..5f2f53fc7 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -93,12 +93,13 @@ module QueriesHelper tags end - def available_totalable_columns_tags(query) + def available_totalable_columns_tags(query, options={}) + tag_name = (options[:name] || 't') + '[]' tags = ''.html_safe query.available_totalable_columns.each do |column| - tags << content_tag('label', check_box_tag('t[]', column.name.to_s, query.totalable_columns.include?(column), :id => nil) + " #{column.caption}", :class => 'inline') + tags << content_tag('label', check_box_tag(tag_name, column.name.to_s, query.totalable_columns.include?(column), :id => nil) + " #{column.caption}", :class => 'inline') end - tags << hidden_field_tag('t[]', '') + tags << hidden_field_tag(tag_name, '') tags end @@ -282,7 +283,7 @@ module QueriesHelper end # Retrieve query from session or build a new query - def retrieve_query(klass=IssueQuery, use_session=true) + def retrieve_query(klass=IssueQuery, use_session=true, options={}) session_key = klass.name.underscore.to_sym if params[:query_id].present? @@ -295,7 +296,7 @@ module QueriesHelper elsif api_request? || params[:set_filter] || !use_session || session[session_key].nil? || session[session_key][:project_id] != (@project ? @project.id : nil) # Give it a name, required to be valid @query = klass.new(:name => "_", :project => @project) - @query.build_from_params(params) + @query.build_from_params(params, options[:defaults]) session[session_key] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names, :totalable_names => @query.totalable_names, :sort => @query.sort_criteria.to_a} if use_session else # retrieve from session diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index dedbe8d0a..b002f909c 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -73,7 +73,7 @@ class IssueQuery < Query options[:draw_progress_line] = (arg == '1' ? '1' : nil) end - def build_from_params(params) + def build_from_params(params, defaults={}) super self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations]) self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line]) diff --git a/app/models/query.rb b/app/models/query.rb index c8c89860d..02e808eca 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -365,7 +365,7 @@ class Query < ActiveRecord::Base end # Builds the query from the given params - def build_from_params(params) + def build_from_params(params, defaults={}) if params[:fields] || params[:f] self.filters = {} add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) @@ -374,10 +374,12 @@ class Query < ActiveRecord::Base add_short_filter(field, params[field]) if params[field] end end - self.group_by = params[:group_by] || (params[:query] && params[:query][:group_by]) - self.column_names = params[:c] || (params[:query] && params[:query][:column_names]) - self.totalable_names = params[:t] || (params[:query] && params[:query][:totalable_names]) - self.sort_criteria = params[:sort] || (params[:query] && params[:query][:sort_criteria]) + + query_params = params[:query] || defaults || {} + self.group_by = params[:group_by] || query_params[:group_by] + self.column_names = params[:c] || query_params[:column_names] + self.totalable_names = params[:t] || query_params[:totalable_names] + self.sort_criteria = params[:sort] || query_params[:sort_criteria] self end diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index ee15699f4..43fdc8625 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -191,7 +191,7 @@ class TimeEntryQuery < Query end # Accepts :from/:to params as shortcut filters - def build_from_params(params) + def build_from_params(params, defaults={}) super if params[:from].present? && params[:to].present? add_filter('spent_on', '><', [params[:from], params[:to]]) diff --git a/app/views/settings/_timelog.html.erb b/app/views/settings/_timelog.html.erb index 4f922011b..c4453a616 100644 --- a/app/views/settings/_timelog.html.erb +++ b/app/views/settings/_timelog.html.erb @@ -6,5 +6,19 @@ </div> +<fieldset class="box"> + <legend><%= l(:setting_time_entry_list_defaults) %></legend> + + <% query = TimeEntryQuery.new(Setting.time_entry_list_defaults) %> + <%= render_query_columns_selection(query, + :name => 'settings[time_entry_list_defaults][column_names]') %> + + <p> + <label><%= l(:label_total_plural) %></label> + <%= available_totalable_columns_tags(query, + :name => 'settings[time_entry_list_defaults][totalable_names]') %> + </p> +</fieldset> + <%= submit_tag l(:button_save) %> <% end %> |