Skip to content

Commit

Permalink
Merge pull request #717 from sparc-request/sj-updating_document_logic
Browse files Browse the repository at this point in the history
SJ - Reworking Document Logic
  • Loading branch information
Stuart-Johnson committed May 18, 2020
2 parents 1258348 + a442649 commit 54394f8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
5 changes: 2 additions & 3 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def create

create_document_file
@selector = "#{@document.unique_selector}_documents"
@documentable = @document.documentable
flash.now[:success] = t(:documents)[:flash_messages][:created]
}
end
Expand Down Expand Up @@ -103,10 +104,8 @@ def destroy
respond_to do |format|
format.js {
mark_document_as_accessed if @document.last_accessed_at.nil?
@documentable = @document.documentable
@document.destroy
if @document.documentable_type != "LineItem"
flash[:alert] = t(:documents)[:flash_messages][:removed]
end
}
end
end
Expand Down
25 changes: 3 additions & 22 deletions app/views/documents/create.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,8 @@

<% if @error.present? %>
$('#doc_modal_errors').empty().append("<div class='alert alert-danger'><%= @error %></div>")
<% elsif @document.documentable_type == "Fulfillment" %>
##Document is being added to Fulfillment
$("#modal_area").html("<%= escape_javascript(render(partial: 'study_level_activities/fulfillments_table', locals: {line_item: @document.documentable.line_item, header_text: 'Fulfillments List'})) %>")
$("#fulfillments-table").bootstrapTable()

$('.fulfillments-list li').find("[data-field='docs']").closest('li').hide()
$('.fulfillments-list li').find("[data-field='notes']").closest('li').hide()
$('.fulfillments-list li').find("[data-field='export_invoiced']").closest('li').hide()
exclude_from_export('fulfillments-table')

$('#fulfillments-table').on 'load-success.bs.table', () ->
$('input.invoice_toggle').bootstrapToggle()
$('input.credit_toggle').bootstrapToggle()

$('#fulfillments-table').on 'column-switch.bs.table', (e, field, checked) ->
if field == 'invoiced' && checked == true
$('input.invoice_toggle').bootstrapToggle()
if field == 'credited' && checked == true
$('input.credit_toggle').bootstrapToggle()
<% else %>
##Document is being added to Line Item
$('#study-level-activities-table').bootstrapTable('refresh', {silent: "true"})
$('.modal').modal('hide')
$("#modal_area").html("<%= escape_javascript(render(partial: 'index', locals: { documents: @documentable.documents, documentable_type: @document.documentable_type, documentable_id: @documentable.id, documentable_sym: @document.documentable_type.downcase.to_sym})) %>")
$("#modal_place").modal(backdrop: 'static', keyboard: false)
$("#modal_place").modal 'show'
<% end %>
10 changes: 6 additions & 4 deletions app/views/documents/destroy.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
# 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.~

<% if @document.documentable_type == "LineItem" %>
$('#study-level-activities-table').bootstrapTable('refresh', {silent: "true"})
$('.modal').modal('hide')
<% else %>
<% if ["Identity", "Protocol"].include?(@document.documentable_type) %>
##Document is a report, doesn't use modal window.
$("#flashes_container").html("<%= escape_javascript(render('flash')) %>");
refreshDocumentsTables()
<% else %>
$("#modal_area").html("<%= escape_javascript(render(partial: 'index', locals: { documents: @documentable.documents, documentable_type: @document.documentable_type, documentable_id: @documentable.id, documentable_sym: @document.documentable_type.downcase.to_sym})) %>")
$("#modal_place").modal(backdrop: 'static', keyboard: false)
$("#modal_place").modal 'show'
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@
when_i_click_on_line_item_documents_icon
when_i_click_on_the_add_document_button
when_i_upload_a_document
when_i_click_on_line_item_documents_icon
then_i_should_see_the_document
end
end

context 'User deletes document' do
scenario 'and does not see the document anymore' do
given_i_am_viewing_the_study_level_activities_tab
when_i_have_a_document_to_upload
when_i_click_on_line_item_documents_icon
when_i_click_on_the_add_document_button
when_i_upload_a_document
when_i_click_the_delete_icon
then_i_should_not_see_the_document
end
end

def given_i_am_viewing_the_study_level_activities_tab
protocol = create_and_assign_protocol_to_me
sparc_protocol = protocol.sparc_protocol
Expand Down Expand Up @@ -87,4 +98,14 @@ def then_i_should_see_the_line_item_documents_list
def then_i_should_see_the_document
expect(page).to have_content('test_document.txt')
end

def when_i_click_the_delete_icon
first("div.delete a").click
wait_for_ajax
end

def then_i_should_not_see_the_document
expect(page).to_not have_css("div.comment a")
expect(page).to have_text("This line item has no documents")
end
end

0 comments on commit 54394f8

Please sign in to comment.