Skip to content

Commit

Permalink
Merge pull request #1966 from sparc-request/jm-epic-queue-protocol-me…
Browse files Browse the repository at this point in the history
…rge-pages

JM - (SPARCDashboard bootstrap 4) Epic Queue & Protocol Merge Pages
  • Loading branch information
jwiel86 committed Aug 21, 2019
2 parents 7a22358 + 6eba9fe commit b67bbc5
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 196 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@

//= require reporting


// require batch-select
// require bootstrap-table
// require bootstrap-table-export
Expand Down
15 changes: 0 additions & 15 deletions app/assets/javascripts/dashboard/epic_queues.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,11 @@ $(document).ready ->
$('.epic-queue-table').bootstrapTable()
$('.epic-queue-records-table').bootstrapTable()

$(document).on 'click', '.delete-epic-queue-button', ->
if confirm(I18n.t('epic_queues.confirm'))
eq_id = $(this).data('epic-queue-id')
$.ajax
type: 'DELETE'
url: "/dashboard/epic_queues/#{eq_id}.js"

$(document).on 'click-cell.bs.table', '.epic-queue-table, .epic-queue-records-table', (field, value, row, $element) ->
if value == 'protocol'
protocolId = $element.protocol_id
window.open("/dashboard/protocols/#{protocolId}")

$(document).on 'click', '.push-to-epic', (e) ->
e.preventDefault()
protocol_id = $(this).data('protocol-id')
eq_id = $(this).data('eq-id')
$.ajax
type: 'GET'
url: "/protocols/#{protocol_id}/push_to_epic.js?from_portal=true&&eq_id=#{eq_id}"

$(document).on 'click', '#epic-queue-panel .export button', ->
$(this).parent().removeClass('open')
window.location = '/dashboard/epic_queue_records.xlsx'
18 changes: 0 additions & 18 deletions app/assets/javascripts/dashboard/protocol_merges.js.coffee

This file was deleted.

174 changes: 98 additions & 76 deletions app/controllers/dashboard/protocol_merges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,98 +22,120 @@ class Dashboard::ProtocolMergesController < Dashboard::BaseController
before_action :authorize_overlord
respond_to :json, :html

def show
current_user = current_identity
def new
@protocol_merge = ProtocolMerge.new()
end

def perform_protocol_merge
master_protocol = Protocol.where(id: params[:master_protocol_id].to_i).first
sub_protocol = Protocol.where(id: params[:sub_protocol_id].to_i).first

merge_srs = Dashboard::MergeSrs.new()
fix_ssr_ids = Dashboard::FixSsrIds.new(master_protocol)

if (master_protocol == nil) || (sub_protocol == nil)
flash[:alert] = 'Protocol(s) not found. Check IDs and try again.'
elsif (master_protocol.has_clinical_services? && sub_protocol.has_clinical_services?)
flash[:alert] = 'Both protocols have calendars. Only one protocol may have a calendar for merge to work.'
elsif sub_protocol.fulfillment_protocols.any?
flash[:alert] = 'Protocol to be merged into Master Protocol cannot exist in SPARCFulfillment.'
else
ActiveRecord::Base.transaction do

#transfer the project roles as needed
sub_protocol.project_roles.each do |role|
if role.role != 'primary-pi' && role_should_be_assigned?(role, master_protocol)
role.update_attributes(protocol_id: master_protocol.id)
@errors = {}
confirmed = params[:protocol_merge][:confirmed] == "false" ? false : true

if params[:protocol_merge][:master_protocol_id].empty? && params[:protocol_merge][:merged_protocol_id].empty?
@errors[:master_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:master_blank]
@errors[:merged_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:merged_blank]
elsif params[:protocol_merge][:master_protocol_id].empty?
@errors[:master_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:master_blank]
elsif params[:protocol_merge][:merged_protocol_id].empty?
@errors[:merged_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:merged_blank]
elsif Protocol.where(id: params[:protocol_merge][:master_protocol_id]).empty? && Protocol.where(id: params[:protocol_merge][:merged_protocol_id]).empty?
@errors[:master_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:master_does_not_exist]
@errors[:merged_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:merged_does_not_exist]
elsif Protocol.where(id: params[:protocol_merge][:master_protocol_id]).empty?
@errors[:master_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:master_does_not_exist]
elsif Protocol.where(id: params[:protocol_merge][:merged_protocol_id]).empty?
@errors[:merged_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:merged_does_not_exist]
end

@master_protocol = Protocol.where(id: params[:protocol_merge][:master_protocol_id]).first
@merged_protocol = Protocol.where(id: params[:protocol_merge][:merged_protocol_id]).first

if @master_protocol && @merged_protocol

if @master_protocol.has_clinical_services? && @merged_protocol.has_clinical_services?
@errors[:master_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:one_calendar]
@errors[:merged_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:one_calendar]
elsif @merged_protocol.fulfillment_protocols.any?
@errors[:merged_protocol_id] = t(:dashboard)[:protocol_merge][:errors][:cannot_merge]
elsif @errors.empty? && !confirmed
@no_errors = true
return
else
ActiveRecord::Base.transaction do
merge_srs = Dashboard::MergeSrs.new()
fix_ssr_ids = Dashboard::FixSsrIds.new(@master_protocol)
#transfer the project roles as needed
@merged_protocol.project_roles.each do |role|
if role.role != 'primary-pi' && role_should_be_assigned?(role, @master_protocol)
role.update_attributes(protocol_id: @master_protocol.id)
end
end
end

# checking for and assigning research types, impact areas, and affiliations...
if has_research?(sub_protocol, 'human_subjects') && !has_research?(master_protocol, 'human_subjects')
sub_protocol.human_subjects_info.update_attributes(protocol_id: master_protocol.id)
elsif has_research?(sub_protocol, 'vertebrate_animals') && !has_research?(master_protocol, 'vertebrate_animals')
sub_protocol.vertebrate_animals_info.update_attributes(protocol_id: master_protocol.id)
elsif has_research?(sub_protocol, 'investigational_products') && !has_research?(master_protocol, 'investigational_products')
sub_protocol.investigational_products_info.update_attributes(protocol_id: master_protocol.id)
elsif has_research?(sub_protocol, 'ip_patents') && !has_research?(master_protocol, 'ip_patents')
sub_protocol.ip_patents_info.update_attributes(protocol_id: master_protocol.id)
end
# checking for and assigning research types, impact areas, and affiliations...
if has_research?(@merged_protocol, 'human_subjects') && !has_research?(@master_protocol, 'human_subjects')
@merged_protocol.human_subjects_info.update_attributes(protocol_id: @master_protocol.id)
elsif has_research?(@merged_protocol, 'vertebrate_animals') && !has_research?(@master_protocol, 'vertebrate_animals')
@merged_protocol.vertebrate_animals_info.update_attributes(protocol_id: @master_protocol.id)
elsif has_research?(@merged_protocol, 'investigational_products') && !has_research?(@master_protocol, 'investigational_products')
@merged_protocol.investigational_products_info.update_attributes(protocol_id: @master_protocol.id)
elsif has_research?(@merged_protocol, 'ip_patents') && !has_research?(@master_protocol, 'ip_patents')
@merged_protocol.ip_patents_info.update_attributes(protocol_id: @master_protocol.id)
end

sub_protocol.impact_areas.each do |area|
area.protocol_id = master_protocol.id
area.save(validate: false)
end
@merged_protocol.impact_areas.each do |area|
area.protocol_id = @master_protocol.id
area.save(validate: false)
end

sub_protocol.affiliations.each do |affiliation|
affiliation.protocol_id = master_protocol.id
affiliation.save(validate: false)
end
@merged_protocol.affiliations.each do |affiliation|
affiliation.protocol_id = @master_protocol.id
affiliation.save(validate: false)
end

# assigning service requests...
fulfillment_ssrs = []
sub_protocol.service_requests.each do |request|
request.protocol_id = master_protocol.id
request.save(validate: false)
request.sub_service_requests.each do |ssr|
ssr.update_attributes(protocol_id: master_protocol.id)
master_protocol.next_ssr_id = (master_protocol.next_ssr_id + 1)
master_protocol.save(validate: false)
if ssr.in_work_fulfillment
fulfillment_ssrs << ssr
# assigning service requests...
fulfillment_ssrs = []
@merged_protocol.service_requests.each do |request|
request.protocol_id = @master_protocol.id
request.save(validate: false)
request.sub_service_requests.each do |ssr|
ssr.update_attributes(protocol_id: @master_protocol.id)
@master_protocol.next_ssr_id = (@master_protocol.next_ssr_id + 1)
@master_protocol.save(validate: false)
if ssr.in_work_fulfillment
fulfillment_ssrs << ssr
end
end
end
end

#assigning arms..."
sub_protocol.arms.each do |arm|
arm.protocol_id = master_protocol.id
arm.save(validate: false)
end
#assigning arms..."
@merged_protocol.arms.each do |arm|
arm.protocol_id = @master_protocol.id
arm.save(validate: false)
end

#assigning documents..."
sub_protocol.documents.each do |document|
document.protocol_id = master_protocol.id
document.save(validate: false)
end
#assigning documents..."
@merged_protocol.documents.each do |document|
document.protocol_id = @master_protocol.id
document.save(validate: false)
end

#assigning_notes
sub_protocol.notes.each do |note|
note.notable_id = master_protocol.id
note.save(validate: false)
end
#assigning_notes
@merged_protocol.notes.each do |note|
note.notable_id = @master_protocol.id
note.save(validate: false)
end

#log change to DB
ProtocolMerge.create(master_protocol_id: master_protocol.id, merged_protocol_id: sub_protocol.id, identity_id: current_identity.id)
#log change to DB
ProtocolMerge.create(master_protocol_id: @master_protocol.id, merged_protocol_id: @merged_protocol.id, identity_id: current_identity.id)

#delete sub protocol
sub_protocol.delete
#delete merged protocol
@merged_protocol.delete

#cleanup
merge_srs.perform_sr_merge
fix_ssr_ids.perform_id_fix
#cleanup
merge_srs.perform_sr_merge
fix_ssr_ids.perform_id_fix
end
flash[:success] = t(:dashboard)[:protocol_merge][:success]
end
flash[:success] = 'Protocol merge successful'
end
end

Expand All @@ -130,7 +152,7 @@ def role_should_be_assigned?(role_to_be_assigned, protocol)

def authorize_overlord
unless current_user.catalog_overlord?
authorization_error('You do not have access to perform a Protocol Merge')
authorization_error(t(:dashboard)[:protocol_merge][:errors][:access])
end
end

Expand Down
24 changes: 13 additions & 11 deletions app/helpers/dashboard/epic_queues_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,34 @@ def format_pis(protocol)
end

def epic_queue_delete_button(epic_queue)
content_tag(:button,
raw(content_tag(:span, '', class: 'glyphicon glyphicon-remove', aria: { hidden: 'true' })),
type: 'button', data: { epic_queue_id: epic_queue.id, permission: 'true' }, class: "btn btn-danger actions-button delete-epic-queue-button")
link_to icon('fas', 'trash-alt'), dashboard_epic_queue_path(epic_queue.id), remote: true, method: :delete, class: 'btn btn-danger', data: { confirm_swal: 'true' }
end

def epic_queue_send_button(epic_queue)
content_tag(
:a,
raw(content_tag(:span, '', class: 'glyphicon glyphicon-hand-right')),
data: { protocol_id: epic_queue.protocol.id, permission: 'true',
eq_id: epic_queue.id },
class: 'btn btn-success push-to-epic')
link_to icon('fas', 'hand-point-right'), push_to_epic_protocol_path(epic_queue.protocol.id, eq_id: epic_queue.id), remote: true, method: :get, class: 'btn btn-success push-to-epic', data: { permission: 'true' }
end

def epic_queue_actions(epic_queue)
content_tag :div, class: 'd-flex justify-content-center' do
raw([
epic_queue_send_button(epic_queue),
epic_queue_delete_button(epic_queue)
].join(''))
end
end

def format_epic_queue_date(protocol)
date = protocol.last_epic_push_time
if date.present?
date.strftime(t(:epic_queues)[:date_formatter])
date.strftime(t(:dashboard)[:epic_queues][:date_formatter])
else
''
end
end

def format_epic_queue_created_at(epic_queue)
created_at = epic_queue.created_at
created_at.strftime(t(:epic_queues)[:date_formatter])
created_at.strftime(t(:dashboard)[:epic_queues][:date_formatter])
end

def format_status(protocol)
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/epic_queue_records/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ json.rows do
json.(@epic_queue_records.limit(params[:limit]).offset(params[:offset])) do |eqr|
json.protocol_id eqr.protocol_id
json.protocol format_protocol(eqr.protocol)
json.notes notes_button(eqr)
json.notes notes_button(eqr, protocol_id: eqr.protocol.id)
json.pis format_pis(eqr.protocol)
json.date format_epic_queue_created_at(eqr)
json.status eqr.status.capitalize
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/epic_queue_records/index.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ wb = xlsx_package.workbook
header = wb.styles.add_style alignment: { horizontal: :center, vertical: :center }, b: true

wb.add_worksheet(name: "Epic Queue Records") do |sheet|
sheet.add_row [t(:epic_queues)[:sent_protocols], t(:epic_queues)[:notes], t(:epic_queues)[:PIs], t(:epic_queues)[:date], t(:epic_queues)[:status], t(:epic_queues)[:type], t(:epic_queues)[:by]], style: [header, header, header, header, header, header, header]
sheet.add_row [t(:dashboard)[:epic_queues][:sent_protocols], t(:dashboard)[:epic_queues][:notes], t(:dashboard)[:epic_queues][:PIs], t(:dashboard)[:epic_queues][:date], t(:dashboard)[:epic_queues][:status], t(:dashboard)[:epic_queues][:type], t(:dashboard)[:epic_queues][:by]], style: [header, header, header, header, header, header, header]

@epic_queue_records.each do |eqr|
sheet.add_row [
Expand Down
14 changes: 7 additions & 7 deletions app/views/dashboard/epic_queues/_auth_user_change_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~
.bootstrap-table-dropdown-overflow
.card
#epic-queues-custom-toolbar
%table.epic-queue-table{ data: { toggle: 'table', search: 'true', 'show-columns' => 'true', 'show-refresh' => 'true', 'show-toggle' => 'true', pagination: 'true', side_pagination: 'server', url: dashboard_epic_queues_path(user_change: true), striped: 'true', toolbar: '#epic-queues-custom-toolbar' } }
%thead.primary-header
%tr
%th{data: { field: "protocol", align: "left", sortable: 'true', class: 'text-primary' } }
= t(:epic_queues)[:protocol]
= t(:dashboard)[:epic_queues][:protocol]
%th{data: { field: "pis", align: "left", sortable: 'true' } }
= t(:epic_queues)[:PIs]
= t(:dashboard)[:epic_queues][:PIs]
%th{data: { field: 'created_at', align: 'left', sortable: 'true' } }
= t(:epic_queues)[:created_at]
= t(:dashboard)[:epic_queues][:created_at]
%th{data: { field: 'name', align: 'left', sortable: 'true' } }
= t(:epic_queues)[:by]
= t(:dashboard)[:epic_queues][:by]
%th{data: { field: "date", align: "left", sortable: 'true', sorter: "dateSorter" } }
= t(:epic_queues)[:date]
= t(:dashboard)[:epic_queues][:date]
%th{data: { field: "status", align: "left", sortable: 'true' } }
= t(:epic_queues)[:status]
= t(:dashboard)[:epic_queues][:status]
35 changes: 20 additions & 15 deletions app/views/dashboard/epic_queues/_epic_queue_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.panel.panel-default#epic-queue-panel
.panel-heading
%ul.nav.nav-tabs
%li.active
= link_to t(:dashboard)[:epic_queues][:headers][:current], '#current',
data: { toggle: 'tab' }
%li
= link_to t(:dashboard)[:epic_queues][:headers][:past], '#past', data: { toggle: 'tab' }
%li
= link_to t(:dashboard)[:epic_queues][:headers][:protocol_update],
'#authorized-user-update',
data: { toggle: 'tab' }
.panel-body
.col-12.col-sm-10.mx-auto
%ul.nav.nav-tabs
%li.nav-item
= link_to t(:dashboard)[:epic_queues][:headers][:current],
'#current',
data: { toggle: 'tab' },
class: 'nav-link active'
%li.nav-item
= link_to t(:dashboard)[:epic_queues][:headers][:past],
'#past',
data: { toggle: 'tab' },
class: 'nav-link'
%li.nav-item
= link_to t(:dashboard)[:epic_queues][:headers][:protocol_update],
'#authorized-user-update',
data: { toggle: 'tab' },
class: 'nav-link'
%div
.tab-content
.tab-pane.fade.in.active#current
.tab-pane.fade.in.active.show#current
= render "epic_queues_table"
.tab-pane.fade#past
= render "epic_queue_records_table"
.tab-pane.fade#authorized-user-update
= render "auth_user_change_list"
= render "auth_user_change_list"

0 comments on commit b67bbc5

Please sign in to comment.