Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KG - More Reports Refactors #98

Merged
merged 3 commits into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/participant_tracker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $ ->
$(document).on 'load-success.bs.table', 'table.participants', ->
tables_to_refresh = ['table.protocol_reports']

$.each $('table.participants td.participant_report a'), (index, value) ->
$.each $('table.participants td.participant_report button'), (index, value) ->
remote_document_generator value, tables_to_refresh

$(document).on 'change', '.participant_status', ->
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/protocols_show.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ ->
$(document).on 'load-success.bs.table', 'table.protocol', ->
tables_to_refresh = ['table.protocol_reports']

remote_document_generator 'a.study_schedule_report', tables_to_refresh
remote_document_generator 'button.study_schedule_report', tables_to_refresh

$(document).on 'click', 'a.attached_file', ->
update_view_on_download_new_report $(this), 'table.protocol_reports', 'Protocol'
84 changes: 47 additions & 37 deletions app/assets/javascripts/remote_document_handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ generate_document = (element, tables_to_refresh, event = null) ->
get_document_state = ->
document_id = $(element).data("document_id")

set_glyphicon_error = (element) ->
$(element).
addClass('btn-danger').
removeClass('btn-warning').
find('span.glyphicon').
addClass('glyphicon-alert').
removeClass('glyphicon-refresh spin')

$.ajax
type: 'GET'
url: "/documents/#{document_id}.json"
Expand All @@ -41,49 +33,43 @@ generate_document = (element, tables_to_refresh, event = null) ->
switch document_state
when 'Completed'
add_to_report_notification_count(data.document.documentable_type, 1)
set_glyphicon_finished(element)
add_dropdown_to_button(element)

set_glyphicon_finished element

dropdown_id_indicator = "document_menu_#{$(element).attr('id')}"
dropdown = $(["<ul class='dropdown-menu document-dropdown-menu' role='menu' id=#{dropdown_id_indicator}>",
"<li><a href='/documents/#{document_id}.html' target='blank' title='Download Report'>Download Report</a></li>"
"<li><a href='javascript:void(0)' title='Generate New Report'>Generate New Report</a></li>"
"</ul>"
].join(""))

$(element).attr('data-toggle', 'dropdown')
$(element).siblings('#'+dropdown_id_indicator).replaceWith(dropdown)

#Download Report
$("li a[title='Download Report']").off('click').on 'click', ->
ul = $(this).parents().eq(1)
button = $(ul).siblings('a.dropdown-toggle')
ul.toggle()
ul = $(this).parents('.document-dropdown-menu')
button = $(ul).siblings('.report-button')
$(ul).toggle()

document_id = button.data("document_id")

update_view_on_download_new_report $("a.attached_file[data-id=#{document_id}]") ,'table.protocol_reports', 'Protocol'
update_view_on_download_new_report $("a.attached_file[data-id=#{button.data('document_id')}]") ,'table.protocol_reports', 'Protocol'

#Generate New Report
$("li a[title='Generate New Report']").off('click').on 'click', ->
ul = $(this).parents().eq(1)
button = $(ul).siblings('a.dropdown-toggle')
ul.toggle()
ul = $(this).parents('.document-dropdown-menu')
button = $(ul).siblings('.report-button')
$(ul).toggle()

button.removeClass('btn-success')
$(button).children('.caret').remove()
set_glyphicon_loading button

generate_document button, tables_to_refresh

#Toggle Dropdown **Intentionally Not a Bootstrap Dropdown**
$(element).off('click').on 'click', ->
ul = $(this).siblings("ul.document-dropdown-menu")
active = false
if $(element).hasClass("btn-success")
ul = $(this).parents('document-dropdown-menu')
active = false

if $(ul).is(':visible')
active = true

if ul.attr("style") == "display: block;"
active = true
#Toggle all other open dropdown menus
$("ul.document-dropdown-menu").filter("visible").toggle()

$("ul.document-dropdown-menu[style='display: block;']").toggle()
if active == false
$(ul).toggle()

if active == false
$(this).siblings("ul.document-dropdown-menu").toggle()
when 'Error'
set_glyphicon_error element
else
Expand All @@ -94,15 +80,39 @@ generate_document = (element, tables_to_refresh, event = null) ->
set_glyphicon_loading = (element) ->
$(element).
addClass('btn-warning').
removeClass('btn-success').
removeClass('btn-default').
find('span.glyphicon').
addClass('glyphicon-refresh spin').
removeClass('glyphicon-equalizer')

set_glyphicon_error = (element) ->
$(element).
addClass('btn-danger').
removeClass('btn-warning').
find('span.glyphicon').
addClass('glyphicon-alert').
removeClass('glyphicon-refresh spin')

set_glyphicon_finished = (element) ->
$(element).
addClass('btn-success').
removeClass('btn-warning').
removeClass('btn-default').
find('span.glyphicon').
addClass('glyphicon-equalizer').
removeClass('glyphicon-refresh spin')

add_dropdown_to_button = (element) ->
dropdown_id_indicator = "document_menu_#{$(element).attr('id')}"
dropdown = $(["<ul class='dropdown-menu document-dropdown-menu' role='menu' id=#{dropdown_id_indicator}>",
"<li><a href='/documents/#{document_id}.html' target='blank' title='Download Report'>Download Report</a></li>"
"<li><a href='javascript:void(0)' title='Generate New Report'>Generate New Report</a></li>"
"</ul>"
].join(""))

$(element).attr('data-toggle', 'dropdown')
$(element).siblings('#'+dropdown_id_indicator).replaceWith(dropdown)

caret = "<span class='caret'></span>"
$(element).append(caret)
4 changes: 2 additions & 2 deletions app/helpers/documents_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def attached_file_formatter(document)
content_tag(:a, class: 'attached_file', id: "file_#{document.id}", href: document_path(document), target: :blank, title: 'Download File', 'data-id' => document.id) do
content_tag(:span, '', class: 'glyphicon glyphicon-file')
end
when 'Pending'
when 'Processing'
content_tag(:span, '', class: 'glyphicon glyphicon-refresh spin', style: 'cursor:auto')
else
content_tag(:span, '', class: 'glyphicon glyphicon-alert danger', style: 'cursor:auto')
Expand All @@ -30,7 +30,7 @@ def edit_formatter(document)
end

def delete_formatter(document)
if document.completed?
if document.completed? || document.failed?
[
"<a class='remove remove-document' href='javascript:void(0)' title='Remove' data-document_id='#{document.id}' data-documentable_type='#{document.documentable_type}'>",
"<i class='glyphicon glyphicon-remove'></i>",
Expand Down
11 changes: 5 additions & 6 deletions app/helpers/participant_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ def notes_formatter participant
end

def participant_report_formatter participant
content_tag(:div, '', class: 'btn-group') do
content_tag(:a, class: 'btn btn-default dropdown-toggle btn-xs participant_report', id: "participant_report_#{participant.id.to_s}", href: 'javascript:void(0)', target: :blank, title: 'Participant Report', 'data-documentable_type' => 'Protocol', 'data-documentable_id' => participant.protocol.id, 'data-participant_id' => participant.id, 'data-title' => 'Participant Report', 'data-report_type' => 'participant_report', 'aria-expanded' => 'false') do
content_tag(:span, '', class: 'glyphicon glyphicon-equalizer')
end +
content_tag(:ul, '', class: 'dropdown-menu document-dropdown-menu menu-participant', role: 'menu', id: "document_menu_participant_report_#{participant.id.to_s}")
end
protocol = participant.protocol
icon_span = raw content_tag(:span, '', class: "glyphicon glyphicon-equalizer")
button = raw content_tag(:button, raw(icon_span), type: 'button', class: 'btn btn-default btn-xs report-button participant_report dropdown-toggle', id: "participant_report_#{participant.id.to_s}", 'aria-expanded' => 'false', title: 'Participant Report', 'data-title' => 'Participant Report', 'data-report_type' => 'participant_report', 'data-documentable_id' => protocol.id, 'data-documentable_type' => 'Protocol', 'data-participant_id' => participant.id)
ul = raw content_tag(:ul, '', class: 'document-dropdown-menu', id: "document_menu_participant_report_#{participant.id.to_s}", role: 'menu')
html = raw content_tag(:div, button + ul, class: 'btn-group')
end
end
10 changes: 4 additions & 6 deletions app/helpers/protocol_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ def formatted_requester protocol
end

def formatted_study_schedule_report protocol
content_tag(:div, '', class: 'btn-group') do
content_tag(:a, href: 'javascript:void(0)', target: :blank, class: 'btn btn-default dropdown-toggle btn-xs study_schedule_report', id: "study_schedule_report_#{protocol.id.to_s}", title: 'Study Schedule Report', 'data-title' => 'Study Schedule Report', 'data-report_type' => 'study_schedule_report', 'data-documentable_id' => protocol.id, 'data-documentable_type' => 'Protocol', 'aria-expanded' => 'false') do
content_tag(:span, '', class: "glyphicon glyphicon-equalizer")
end +
content_tag(:ul, '', class: 'dropdown-menu document-dropdown-menu menu-study-schedule', role: 'menu', id: "document_menu_study_schedule_report_#{protocol.id.to_s}")
end
icon_span = raw content_tag(:span, '', class: "glyphicon glyphicon-equalizer")
button = raw content_tag(:button, raw(icon_span), type: 'button', class: 'btn btn-default btn-xs report-button study_schedule_report dropdown-toggle', id: "study_schedule_report_#{protocol.id.to_s}", 'aria-expanded' => 'false', title: 'Study Schedule Report', 'data-title' => 'Study Schedule Report', 'data-report_type' => 'study_schedule_report', 'data-documentable_id' => protocol.id, 'data-documentable_type' => 'Protocol', 'data-protocol_id' => protocol.id)
ul = raw content_tag(:ul, '', class: 'document-dropdown-menu', id: "document_menu_study_schedule_report_#{protocol.id.to_s}", role: 'menu')
html = raw content_tag(:div, button + ul, class: 'btn-group')
end

def formatted_coordinators coordinators=Array.new
Expand Down
4 changes: 4 additions & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def completed?
state == 'Completed'
end

def failed?
state == 'Error'
end

def downloaded?
last_accessed_at
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/reports/create.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ if $("#modal_errors > .alert.alert-danger > p").length == 0
$("#participant_report_<%= @reports_params[:participant_id] %>").data("document_id", "<%= @document.id %>")
$("#participant_report_<%= @reports_params[:participant_id] %>").attr("document_id", "<%= @document.id %>")
<% elsif @document.documentable_type == 'Protocol' %>
$(".study_schedule_report").data("document_id", "<%= @document.id %>")
$(".study_schedule_report").attr("document_id", "<%= @document.id %>")
$("#study_schedule_report_<%= @reports_params[:protocol_id] %>").data("document_id", "<%= @document.id %>")
$("#study_schedule_report_<%= @reports_params[:protocol_id] %>").attr("document_id", "<%= @document.id %>")
<% end %>
<% end %>
window.document_id = <%= @document.id %>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ en:
documents:
documents: "Documents"
date: "Date Requested"
date_time_formatter_ruby: "%m/%d/%Y %r"
date_time_formatter_js: "MM/DD/YYYY hh:mm:ss A"
date_time_formatter_ruby: "%m/%d/%Y %H:%M:%S"
date_time_formatter_js: "MM/DD/YYYY HH:mm:ss"
title: "Title"
state: "Report Status"
file: "Attached File"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def given_i_am_viewing_the_documents_index_page
create(:participant, protocol: @protocol)

visit documents_path
wait_for_ajax
end

def given_i_click_the_create_report_button_of_type report_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ def given_i_have_created_a_protocol_based_document
visit protocol_path @protocol
wait_for_ajax

find("a#study_schedule_report_#{@protocol.id.to_s}").click
find("button#study_schedule_report_#{@protocol.id.to_s}").click
wait_for_ajax

@study_schedule_report_document_id = find("a#study_schedule_report_#{@protocol.id.to_s}")["document_id"]
@study_schedule_report_document_id = find("button#study_schedule_report_#{@protocol.id.to_s}")["document_id"]
end

def given_i_have_created_a_second_protocol_based_document
visit protocol_path @protocol
wait_for_ajax

find("a#study_schedule_report_#{@protocol.id.to_s}").click
find("button#study_schedule_report_#{@protocol.id.to_s}").click
wait_for_ajax

@study_schedule_report_document_id = find("a#study_schedule_report_#{@protocol.id.to_s}")["data-document_id"]
@study_schedule_report_document_id = find("button#study_schedule_report_#{@protocol.id.to_s}")["data-document_id"]
end

def when_i_visit_the_reports_tab
Expand All @@ -69,7 +69,7 @@ def when_i_visit_the_reports_tab
end

def when_i_click_the_created_document_icon
find("a#study_schedule_report_#{@protocol.id.to_s}").trigger('click')
find("button#study_schedule_report_#{@protocol.id.to_s}").trigger('click')
wait_for_ajax
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def when_i_create_an_identity_based_document
end

def when_i_create_a_protocol_based_document
find("a#study_schedule_report_#{@protocol.id.to_s}").click
find("button#study_schedule_report_#{@protocol.id.to_s}").click
wait_for_ajax
end

Expand Down