From b0348f2c5da83dca912de7edcfe5dd8b877b4471 Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Mon, 11 Nov 2013 11:48:10 -0300 Subject: [PATCH] Makes it possible for the admin to see pending submissions --- plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb | 8 ++++++++ plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb | 11 ++++++++++- plugins/custom_forms/views/custom_forms_plugin_myprofile/index.html.erb | 4 +++- plugins/custom_forms/views/custom_forms_plugin_myprofile/pending.html.erb | 27 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 plugins/custom_forms/views/custom_forms_plugin_myprofile/pending.html.erb 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 ba32b14..4aedeb3 100644 --- a/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb +++ b/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb @@ -93,6 +93,14 @@ class CustomFormsPluginMyprofileController < MyProfileController @form = @submission.form end + def pending + @form = CustomFormsPlugin::Form.find(params[:id]) + @pendings = CustomFormsPlugin::AdmissionSurvey.from(@form.profile).pending.select {|task| task.form_id == @form.id}.map {|a| {:profile => a.target, :time => a.created_at} } + + @sort_by = params[:sort_by] + @pendings = @pendings.sort_by { |s| s[:profile].name } if @sort_by == 'user' + end + private def normalize_positions(form) 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 9dfcb50..6a595bb 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 @@ -216,5 +216,14 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase assert_not_nil assigns(:sort_by) assert_select 'table.action-table', /Author\W*Time\W*bob[\W\dh]*john[\W\dh]*/ end -end + should 'list pending submissions for a form' do + person = fast_create(Person) + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :for_admission => true) + task = CustomFormsPlugin::AdmissionSurvey.create!(:form_id => form.id, :target => person, :requestor => profile) + + get :pending, :profile => profile.identifier, :id => form.id + + assert_tag :td, :content => person.name + end +end diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/index.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/index.html.erb index 9b5dea9..acca2aa 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/index.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/index.html.erb @@ -17,7 +17,9 @@ <%= access_text(form) %> <%= button_without_text :edit, _('Edit'), :action => 'edit', :id => form.id %> - <%= button_without_text :remove, _('Remove'), {:action => 'remove', :id => form.id}, :confirm => _('Are you sure you want to remove this form?') %> + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :id => form.id}, :confirm => _('Are you sure you want to remove this form?') %> + <%= button_without_text :search, _('Pending'), :action => 'pending', :id => form.id if form.for_admission %> + <% end %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/pending.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/pending.html.erb new file mode 100644 index 0000000..69f8f21 --- /dev/null +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/pending.html.erb @@ -0,0 +1,27 @@ +<% self.extend CustomFormsPlugin::Helper %> + +

<%= _('Pending submissions for %s') % @form.name %>

+ +<% if @pendings.empty? %> + <%= _('There are no pending submissions for this form.') %> +<% else %> +

+ <%= labelled_select(_('Sort by')+': ', :sort_by, :first, :last, @sort_by, [['time', _('Time')], ['user', _('User')]], :onchange => 'document.location.href = "?sort_by="+this.value') %> +

+ + + + + + <% @pendings.each do |pending| %> + + + + + <% end %> +
<%= _('User') %><%= _('Time') %>
<%= link_to(pending[:profile].name, {:controller => :profile, :profile => pending[:profile].identifier}) %><%= time_format(pending[:time]) %>
+<% end %> + +<% button_bar do %> + <%= button :back, _('Back to forms'), :action => 'index' %> +<% end %> -- libgit2 0.21.2