From 7358e1d0c949434a87b62946890680f70075c6fd Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Mon, 29 Oct 2012 20:13:22 +0000 Subject: [PATCH] [work-assignment] Views --- plugins/work_assignment/lib/work_assignment_plugin/helper.rb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- plugins/work_assignment/public/show_versions.js | 16 ++++++++++++++++ plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb | 2 +- plugins/work_assignment/views/content_viewer/work_assignment.html.erb | 4 +++- 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 plugins/work_assignment/public/show_versions.js diff --git a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb index 2c76821..f4d7177 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb @@ -1,5 +1,59 @@ module WorkAssignmentPlugin::Helper - def display_submissions(work_assignment) - "Displaying submissions..." + def display_submissions(work_assignment, user) + return if work_assignment.submissions.empty? + content_tag('table', + content_tag('tr', + content_tag('th', _('Author'), :style => 'width: 50%') + + content_tag('th', _('Submission date')) + + content_tag('th', _('Versions'), :style => 'text-align: center') + + content_tag('th', '') + ) + + work_assignment.children.map {|author_folder| display_author_folder(author_folder, user)}.join("\n") + ) end + + def display_author_folder(author_folder, user) + return if author_folder.children.empty? + content_tag('tr', + content_tag('td', link_to_last_submission(author_folder, user)) + + content_tag('td', time_format(author_folder.children.last.created_at)) + + content_tag('td', author_folder.children.count, :style => 'text-align: center') + + content_tag('td', content_tag('button', _('View all versions'), :class => 'view-author-versions', 'data-folder-id' => author_folder.id)) + ) + + author_folder.children.map {|submission| display_submission(submission, user)}.join("\n") + end + + def display_submission(submission, user) + content_tag('tr', + content_tag('td', link_to_submission(submission, user)) + + content_tag('td', time_format(submission.created_at), :colspan => 3), + :class => "submission-from-#{submission.parent.id}", + :style => 'display: none' + ) + end + + def link_to_submission(submission, user) + if WorkAssignmentPlugin.can_download_submission?(user, submission) + link_to(submission.name, submission.url) + else + submission.name + end + end + + + def link_to_last_submission(author_folder, user) + if WorkAssignmentPlugin.can_download_submission?(user, author_folder.children.last) + link_to(author_folder.name, author_folder.children.last.url) + else + author_folder.name + end + end + # FIXME Copied from custom-froms. Consider passing it to core... + def time_format(time) + minutes = (time.min == 0) ? '' : ':%M' + hour = (time.hour == 0 && minutes.blank?) ? '' : ' %H' + h = hour.blank? ? '' : 'h' + time.strftime("%Y-%m-%d#{hour+minutes+h}") + end + end diff --git a/plugins/work_assignment/public/show_versions.js b/plugins/work_assignment/public/show_versions.js new file mode 100644 index 0000000..feaf9c9 --- /dev/null +++ b/plugins/work_assignment/public/show_versions.js @@ -0,0 +1,16 @@ +jQuery(".view-author-versions").each(function(index, bt){ + jQuery(bt).button({ + icons: { + primary: "ui-icon-info" + }, + text: false + }); + bt.onclick = function(){ + var folderId = this.getAttribute("data-folder-id"); + var tr = jQuery(".submission-from-"+folderId); + if ( tr[0].style.display == "none" ) + tr.show(); + else + tr.hide(); + } +}); diff --git a/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb b/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb index 8f3b090..25f31a7 100644 --- a/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb +++ b/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb @@ -1,3 +1,3 @@ <%= render :partial => 'folder', :locals => {:f => f} %> -Extra content... +<%= f.check_box(:publish_submissions) %> diff --git a/plugins/work_assignment/views/content_viewer/work_assignment.html.erb b/plugins/work_assignment/views/content_viewer/work_assignment.html.erb index 09a8b79..6a22913 100644 --- a/plugins/work_assignment/views/content_viewer/work_assignment.html.erb +++ b/plugins/work_assignment/views/content_viewer/work_assignment.html.erb @@ -5,4 +5,6 @@
<% end %> -<%= display_submissions(@page) %> +<%= display_submissions(@page, user) %> + +<%= javascript_include_tag '../plugins/work_assignment/show_versions' %> -- libgit2 0.21.2