diff --git a/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb b/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb index 21ca690..ba32b14 100644 --- a/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb +++ b/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb @@ -66,6 +66,10 @@ class CustomFormsPluginMyprofileController < MyProfileController def submissions @form = CustomFormsPlugin::Form.find(params[:id]) @submissions = @form.submissions + + @sort_by = params[:sort_by] + @submissions = @submissions.sort_by { |s| s.profile.present? ? s.profile.name : s.author_name } if @sort_by == 'author' + respond_to do |format| format.html format.csv do diff --git a/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb b/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb index f5b164f..0997ae7 100644 --- a/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb +++ b/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb @@ -179,5 +179,22 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase assert_equal 'Cool form', form.description assert_equal 'Source', field.name end + + should 'order submissions by name or time' do + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') + field = CustomFormsPlugin::TextField.create!(:name => "Title") + form.fields << field + sub1 = CustomFormsPlugin::Submission.create!(:author_name => "john", :author_email => 'john@example.com', :form => form) + bob = create_user('bob').person + sub2 = CustomFormsPlugin::Submission.create!(:profile => bob, :form => form) + + get :submissions, :profile => profile.identifier, :id => form.id, :sort_by => 'time' + assert_not_nil assigns(:sort_by) + assert_select 'table.action-table', /Author\W*Time\W*john[\W\dh]*bob[\W\dh]*/ + + get :submissions, :profile => profile.identifier, :id => form.id, :sort_by => 'author' + assert_not_nil assigns(:sort_by) + assert_select 'table.action-table', /Author\W*Time\W*bob[\W\dh]*john[\W\dh]*/ + end end diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb index 50ce9e5..be17179 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb @@ -9,6 +9,9 @@ <%= _('Download all form responses as') %>: <%= link_to '[CSV]', :format => 'csv' %>
++ <%= labelled_select(_('Sort by')+': ', :sort_by, :first, :last, @sort_by, [['time', _('Time')], ['author', _('Author')]], :onchange => 'document.location.href = "?sort_by="+this.value') %> +
<%= _('Author') %> | -- libgit2 0.21.2
---|