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

Sj sla ui update #522

Merged
merged 3 commits into from
Jun 29, 2016
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
26 changes: 7 additions & 19 deletions app/assets/javascripts/dashboard/study_level_activities.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,13 @@ $ ->
type: 'DELETE'
url: "/dashboard/line_items/#{line_item_id}"

$(document).on 'click', '.otf_fulfillments', ->
selected_row = $(this).parents('tr')
fulfillments_row = $("#fulfillments_row") #already displayed
span = $(this).children('.glyphicon')
line_item_id = $(this).parents('table.study_level_activities').bootstrapTable('getData')[selected_row.data('index')].id
fulfillments_already_displayed = fulfillments_row.attr('data-line_item_id') == "#{line_item_id}"

fulfillments_row.prev('tr').first().find('.glyphicon-chevron-down').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-right').parents('.otf_fulfillments').attr('data-original-title', 'View Fulfillments')
fulfillments_row.remove()
unless fulfillments_already_displayed
span.removeClass('glyphicon-chevron-right').addClass('glyphicon-refresh')
$(this).parents('tr').after("<tr id='fulfillments_row'></tr>")
$.ajax
type: 'GET'
url: '/dashboard/fulfillments'
data: 'line_item_id' : line_item_id
else
$(this).attr('data-original-title', 'View Fulfillments')
span.removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-right')
$(document).on 'click', '.otf_fulfillment_list', ->
line_item_id = $(this).data('line-item-id')
data = line_item_id: line_item_id
$.ajax
type: 'GET'
url: "/dashboard/fulfillments"
data: "line_item_id" : line_item_id

# Fulfillment Bindings

Expand Down
6 changes: 5 additions & 1 deletion app/controllers/dashboard/fulfillments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def new
end

def create
@fulfillment = Fulfillment.create(params[:fulfillment])
@fulfillment = Fulfillment.new(params[:fulfillment])
if @fulfillment.valid?
@fulfillment.save
@line_item = @fulfillment.line_item
flash[:success] = t(:dashboard)[:fulfillments][:created]
else
@errors = @fulfillment.errors
Expand All @@ -54,6 +56,7 @@ def edit

def update
if @fulfillment.update_attributes(params[:fulfillment])
@line_item = @fulfillment.line_item
flash[:success] = t(:dashboard)[:fulfillments][:updated]
else
@errors = @fulfillment.errors
Expand All @@ -62,6 +65,7 @@ def update

def destroy
if @fulfillment.delete
@line_item = @fulfillment.line_item
flash[:alert] = t(:dashboard)[:fulfillments][:destroyed]
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/dashboard/study_level_activities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def sla_form_services_select form, line_item
end

def fulfillments_drop_button line_item_id
content_tag(:button, class: 'btn btn-primary btn-sm otf_fulfillments list', title: "View Fulfillments", type: "button", aria: {label: "Fulfillments List"}, data: {toggle: "tooltip", animation: 'false'}) do
content_tag(:span, '', class: "glyphicon glyphicon-chevron-right", aria: {hidden: "true"})
end
raw content_tag(:button, 'List', id: "list-#{line_item_id}", type: 'button', class: 'btn btn-success otf_fulfillment_list', title: 'List', type: "button", aria: {label: "List Fulfillments"}, data: {line_item_id: line_item_id})
end

def fulfillment_options_buttons fulfillment_id
Expand Down
6 changes: 3 additions & 3 deletions app/views/dashboard/fulfillments/create.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

$("#modal_errors").html("<%= escape_javascript(render(partial: 'shared/modal_errors', locals: {errors: @errors})) %>")
<% unless @errors %>
$("#fulfillments-table").bootstrapTable 'refresh', {silent: true}
$("#modal_place").modal 'hide'
$("#flashes_container").html("<%= escape_javascript(render('shared/flash')) %>")
<% end %>
$("#modal_place").html("<%= escape_javascript(render(partial: 'dashboard/study_level_activities/fulfillments_table', locals: {line_item: @line_item, header_text: 'Fulfillments List'})) %>");
$("#fulfillments-table").bootstrapTable()
<% end %>
6 changes: 3 additions & 3 deletions app/views/dashboard/fulfillments/destroy.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

$("#modal_errors").html("<%= escape_javascript(render(partial: 'shared/modal_errors', locals: {errors: @errors})) %>")
<% unless @errors %>
$("#fulfillments-table").bootstrapTable 'refresh', {silent: true}
$("#modal_place").modal 'hide'
$("#flashes_container").html("<%= escape_javascript(render('shared/flash')) %>")
<% end %>
$("#modal_place").html("<%= escape_javascript(render(partial: 'dashboard/study_level_activities/fulfillments_table', locals: {line_item: @line_item, header_text: 'Fulfillments List'})) %>");
$("#fulfillments-table").bootstrapTable()
<% end %>
5 changes: 2 additions & 3 deletions app/views/dashboard/fulfillments/index.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# 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.

$("#fulfillments_row").attr('data-line_item_id', "<%= @line_item.id %>")
$("#fulfillments_row").html("<%= escape_javascript(render(:partial =>'dashboard/study_level_activities/fulfillments_table', locals: {line_item: @line_item})) %>");
$("#fulfillments_row").prev("tr").first().find(".otf_fulfillments > .glyphicon").removeClass("glyphicon-refresh").addClass("glyphicon-chevron-down").parents("button").attr('data-original-title', 'Hide Fulfillments')
$("#modal_place").html("<%= escape_javascript(render(partial: 'dashboard/study_level_activities/fulfillments_table', locals: {line_item: @line_item, header_text: 'Fulfillments List'})) %>");
$("#fulfillments-table").bootstrapTable()
$("#modal_place").modal('show')
6 changes: 3 additions & 3 deletions app/views/dashboard/fulfillments/update.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

$("#modal_errors").html("<%= escape_javascript(render(partial: 'shared/modal_errors', locals: {errors: @errors})) %>")
<% unless @errors %>
$("#fulfillments-table").bootstrapTable 'refresh', {silent: true}
$("#modal_place").modal 'hide'
$("#flashes_container").html("<%= escape_javascript(render('shared/flash')) %>")
<% end %>
$("#modal_place").html("<%= escape_javascript(render(partial: 'dashboard/study_level_activities/fulfillments_table', locals: {line_item: @line_item, header_text: 'Fulfillments List'})) %>");
$("#fulfillments-table").bootstrapTable()
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@
-# 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.

%td{colspan: 11}
.bootstrap-table-dropdown-overflow
#fulfillment-custom-toolbar
%button.btn.btn-success.otf_fulfillment_new{type: "button", "aria-label" => "Add Fulfillment", data: {line_item_id: line_item.id}}
= t(:dashboard)[:fulfillments][:add]
%table.fulfillments{id: "fulfillments-table", data: {toggle: 'table', search: "true", "show-columns" => "true", "show-refresh" => "true", "show-toggle" => "true", url: dashboard_fulfillments_path(format: :json, line_item_id: line_item.id), "sort-name" => "fulfillment_date", "sort-order" => 'asc', sorter: "dateSorter", striped: "true", toolbar: "#fulfillment-custom-toolbar", "show-export" => "false", "export-types" => ['excel']}}
%thead.secondary-header
%tr
%th{data: {class: 'fulfillment_date', align: "left", field: "fulfillment_date"}}
= t(:dashboard)[:fulfillments][:table][:date]
%th{data: {class: 'qty_type', align: "left", field: "quantity"}}
= t(:dashboard)[:fulfillments][:table][:time]
%th{data: {class: 'quantity', align: "left", field: "quantity_type"}}
= t(:dashboard)[:fulfillments][:table][:time_unit]
%th{data: {class: 'options', align: "center", field: "options"}}
= t(:dashboard)[:fulfillments][:table][:actions]

.modal-dialog.modal-lg
.modal-content
.modal-header
%button.close{type: 'button', data: {dismiss: 'modal'}}
%span{aria: {hidden:'true'}} &times;
%span.sr-only= t(:actions)[:close]
%h4.modal-title.text-center
= header_text

.modal-body
%td{colspan: 11}
.bootstrap-table-dropdown-overflow
#fulfillment-custom-toolbar
%table.fulfillments{id: "fulfillments-table", data: {toggle: 'table', search: "true", "show-columns" => "true", "show-refresh" => "true", "show-toggle" => "true", url: dashboard_fulfillments_path(format: :json, line_item_id: line_item.id), "sort-name" => "fulfillment_date", "sort-order" => 'asc', sorter: "dateSorter", striped: "true", toolbar: "#fulfillment-custom-toolbar", "show-export" => "false", "export-types" => ['excel']}}
%thead.secondary-header
%tr
%th{data: {class: 'fulfillment_date', align: "left", field: "fulfillment_date"}}
= t(:dashboard)[:fulfillments][:table][:date]
%th{data: {class: 'qty_type', align: "left", field: "quantity"}}
= t(:dashboard)[:fulfillments][:table][:time]
%th{data: {class: 'quantity', align: "left", field: "quantity_type"}}
= t(:dashboard)[:fulfillments][:table][:time_unit]
%th{data: {class: 'options', align: "center", field: "options"}}
= t(:dashboard)[:fulfillments][:table][:actions]

.modal-footer
.center-block
%button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}}
= t(:actions)[:close]
%button.btn.btn-success.otf_fulfillment_new{type: "button", "aria-label" => "Add Fulfillment", data: {line_item_id: line_item.id}}
= t(:dashboard)[:fulfillments][:add]
24 changes: 14 additions & 10 deletions spec/controllers/dashboard/fulfillments/post_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
context "params[:fulfillment] describes a valid Fulfillment" do
before(:each) do
# stub a Fulfillment#create to return a valid fulfillment
fulfillment = instance_double(Fulfillment, id: 1)
allow(fulfillment).to receive(:valid?).and_return(true)
allow(Fulfillment).to receive(:create).and_return(fulfillment)
@fulfillment = instance_double(Fulfillment, id: 1)
allow(@fulfillment).to receive(:valid?).and_return(true)
allow(Fulfillment).to receive(:new).and_return(@fulfillment)
allow(@fulfillment).to receive(:save)
allow(@fulfillment).to receive(:line_item)

log_in_dashboard_identity(obj: build_stubbed(:identity))

xhr :post, :create, fulfillment: "fulfillment attributes"
end

it "should create Fulfillment" do
expect(Fulfillment).to have_received(:create).with("fulfillment attributes")
expect(Fulfillment).to have_received(:new).with("fulfillment attributes")
expect(@fulfillment).to have_received(:save)
end

it "should not set @errors" do
Expand All @@ -29,19 +32,20 @@
context "params[:fulfillment] describes an invalid Fulfillment" do
before(:each) do
# stub an invalid Fulfillment
fulfillment = instance_double(Fulfillment, id: 1)
allow(fulfillment).to receive(:valid?).and_return(false)
allow(fulfillment).to receive(:errors).and_return("my errors")

allow(Fulfillment).to receive(:create).and_return(fulfillment)
@fulfillment = instance_double(Fulfillment, id: 1)
allow(@fulfillment).to receive(:valid?).and_return(false)
allow(Fulfillment).to receive(:new).and_return(@fulfillment)
allow(@fulfillment).to receive(:errors).and_return("my errors")
allow(@fulfillment).to receive(:save)
allow(@fulfillment).to receive(:line_item)

log_in_dashboard_identity(obj: build_stubbed(:identity))

xhr :post, :create, fulfillment: "fulfillment attributes"
end

it "should attempt to create Fulfillment" do
expect(Fulfillment).to have_received(:create).with("fulfillment attributes")
expect(Fulfillment).to have_received(:new).with("fulfillment attributes")
end

it "should set @errors" do
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/dashboard/fulfillments/put_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
instance_double(Fulfillment, id: 1)
end
allow(@fulfillment).to receive(:update_attributes).and_return(true)
allow(@fulfillment).to receive(:line_item)

log_in_dashboard_identity(obj: build_stubbed(:identity))

Expand All @@ -33,6 +34,7 @@
instance_double(Fulfillment, id: 1)
end
allow(@fulfillment).to receive(:update_attributes).and_return(false)
allow(@fulfillment).to receive(:line_item)
allow(@fulfillment).to receive(:errors).and_return("my errors")

logged_in_user = build_stubbed(:identity)
Expand Down