Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Kennedy committed Aug 9, 2019
1 parent 3ce5daa commit 20fd4c5
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/app/endpoint/home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Endpoint
# Home serves the main web application.
class Home < Endpoint
helpers Sinatra::Cookies

# Set the url prefix these routes will map to
set :prefix, "/#{base_path}"

Expand Down
25 changes: 16 additions & 9 deletions lib/app/endpoint/oauth2_endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def resume_execution

client = FHIR::Client.for_testing_instance(@instance)
sequence = test_case.sequence.new(@instance, client, settings.disable_tls_tests, sequence_result)
first_test_count = sequence.test_count

timer_count = 0
stayalive_timer_seconds = 20

finished = false

total_tests = sequence_result.group_run ? test_group.test_cases.map { |test| test.sequence.test_count }.reduce(:+) : sequence.test_count

stream :keep_open do |out|
EventMachine::PeriodicTimer.new(stayalive_timer_seconds) do
timer_count += 1
Expand All @@ -85,19 +86,25 @@ def resume_execution

out << js_hide_wait_modal
out << js_show_test_modal
count = sequence_result.result_count

submitted_test_cases_count = sequence_result.next_test_cases.split(',')
total_tests = submitted_test_cases_count.reduce(first_test_count) do |total, set|
sequence_test_count = test_set.test_case_by_id(set).sequence.test_count
total + sequence_test_count
end
previous_test_sequence_ids = sequence_result.group_run ? test_group.test_cases.map(&:id)&.split(sequence_result.test_case_id)&.first : []
previous_test_sequence_ids << sequence_result.test_case_id
previous_test_results = @instance.previous_test_results(previous_test_sequence_ids)

prev_count = previous_test_results.length
count = prev_count
sequence_result = sequence.resume(request, headers, request.params, @error_message) do |result|
if count > prev_count
rerun = nil
else
previous_test_results[-1] = result.result
rerun = previous_test_results
end
count += 1
out << js_update_result(sequence, test_set, result, count, sequence.test_count, count, total_tests)
out << js_update_result(sequence, test_set, result, count, sequence.test_count, count, total_tests, rerun)
@instance.save!
end

all_test_cases << test_case.id
failed_test_cases << test_case.id if sequence_result.fail?
@instance.sequence_results.push(sequence_result)
Expand All @@ -119,7 +126,7 @@ def resume_execution

# continue processesing any afterwards

test_count = first_test_count
test_count = count
until next_test_case.nil?
test_case = test_set.test_case_by_id(next_test_case)

Expand Down
2 changes: 2 additions & 0 deletions lib/app/endpoint/test_set_endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def self.included(klass)
sequence_test_count = test_set.test_case_by_id(set).sequence.test_count
total + sequence_test_count
end
total_test_sequences = submitted_test_cases.count

test_group = nil
test_group = test_set.test_case_by_id(submitted_test_cases.first).test_group
Expand Down Expand Up @@ -184,6 +185,7 @@ def self.included(klass)
end

sequence_result.next_test_cases = ([next_test_case] + submitted_test_cases).join(',')
sequence_result.group_run = total_test_sequences > 1

all_test_cases << test_case.id
failed_test_cases << test_case.id if sequence_result.fail?
Expand Down
13 changes: 11 additions & 2 deletions lib/app/helpers/browser_logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@ def js_stayalive(time)
"<script>console.log('Time running: ' + #{time})</script>"
end

def js_update_result(sequence, _test_set, _result, set_count, set_total, count, total)
def js_update_result(sequence, _test_set, result, set_count, set_total, count, total, rerun = nil)
cancel_button =
if sequence.sequence_result
"<a href=\"sequence_result/#{sequence.sequence_result.id}/cancel\" class=\"btn btn-secondary\">Cancel Sequence</a>"
else
''
end

width = (1.0 / total) * 100
rerun_html = ''
if rerun.present?
rerun.each { |run| rerun_html += "<div class='progress-bar progress-bar-#{run}' role='progressbar' aria-valuenow='#{width}' aria-valuemin='0' aria-valuemax='100' style='width: #{width}%;'></div>" }
end
result_html = "<div class='progress-bar progress-bar-#{result.result}' role='progressbar' aria-valuenow='#{width}' aria-valuemin='0' aria-valuemax='100' style='width: #{width}%;'></div>"

%(
<script>
$('#testsRunningModal').find('.number-complete:last').html('(#{set_count} of #{set_total} #{sequence.class.title} tests complete)');
$('#testsRunningModal .modal-footer').html('#{cancel_button}');
var progress = Math.round((#{count}/#{total}) * 100);
console.log('js_update_result (' + progress + ')');
$('#progress-bar').attr('aria-valuenow', progress).css('width', progress + '%');
$('#current-progress').text(progress + '%');
$(document.getElementsByClassName('progress')).append(\"#{rerun_html}\");
$(document.getElementsByClassName('progress')).append(\"#{result_html}\");
</script>
)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/app/models/sequence_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class SequenceResult

property :created_at, DateTime, default: proc { DateTime.now }

property :group_run, Boolean

has n, :test_results, order: [:test_index.asc]
belongs_to :testing_instance

Expand Down
6 changes: 6 additions & 0 deletions lib/app/models/testing_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class TestingInstance
has n, :supported_resources, order: [:index.asc]
has n, :resource_references

def previous_test_results(previous_sequence_ids)
previous_test_cases = previous_sequence_ids.map { |sequence_id| latest_results_by_case[sequence_id.to_s] }
previous_test_results = previous_test_cases.map { |test_case| test_case&.test_results&.map(&:result) }
previous_test_results.flatten
end

def latest_results
sequence_results.each_with_object({}) do |result, hash|
hash[result.name] = result if hash[result.name].nil? || hash[result.name].created_at < result.created_at
Expand Down
5 changes: 2 additions & 3 deletions lib/app/views/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,8 @@
<div class="modal-body">
Tests are currently running <span class="number-complete"></span>
<p>
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-striped active" id="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
</div>
<div class="progress" id="progress-bar"></div>
<span id="current-progress"> 0% </span>
</p>
</div>

Expand Down
5 changes: 2 additions & 3 deletions lib/app/views/guided.erb
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,8 @@
<div class="modal-body">
Tests are currently running <span class="number-complete"></span>
<p>
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-striped active" id="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
</div>
<div class="progress" id="progress-bar"></div>
<span id="current-progress"> 0% </span>
</p>
</div>

Expand Down
32 changes: 28 additions & 4 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ body {

}

.progress .progress-bar.active {
background-color: #f98718;
}

#PrerequisitesModal label {
margin-bottom: .1rem;
text-transform: uppercase;
Expand Down Expand Up @@ -1173,6 +1169,34 @@ body {
/* background-image: url("../images/guided-background.png"); */
}

#progress-bar .progress-bar-pass {
background-color: #28a745;
}

#progress-bar .progress-bar-fail {
background-color: #cb2431;
}

#progress-bar .progress-bar-skip {
background-color: #00e1e1;
}

#progress-bar .progress-bar-error {
background-color: #f0f;
}

#progress-bar .progress-bar-omit {
background-color: #999;
}

#progress-bar .progress-bar-wait {
background-color: #999;
}

#progress-bar .progress-bar-todo {
background-color: #999;
}

.tab-pane {
display:none;
}
Expand Down

0 comments on commit 20fd4c5

Please sign in to comment.