Added form to hardware view page for adding test results
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2024-02-09 10:03:27 -05:00
parent f7979cd005
commit e6333b855f
3 changed files with 68 additions and 10 deletions

View File

@ -14,7 +14,7 @@ class GameData < Sinatra::Base
get '/hardware/add' do get '/hardware/add' do
erb :'hardware/add', locals: { erb :'hardware/add', locals: {
title: 'Add Hardware' title: 'Add Hardware',
} }
end end
post '/hardware/add' do post '/hardware/add' do
@ -27,10 +27,12 @@ class GameData < Sinatra::Base
end end
get '/hardware/:hardware_id' do get '/hardware/:hardware_id' do
benchmarks = Benchmark.order(:name).all()
hardware = Hardware.where(id: params[:hardware_id]).first() hardware = Hardware.where(id: params[:hardware_id]).first()
erb :'hardware/view', locals: { erb :'hardware/view', locals: {
title: hardware.name, title: hardware.name,
hardware: hardware hardware: hardware,
benchmarks: benchmarks
} }
end end

View File

@ -29,12 +29,20 @@ class GameData < Sinatra::Base
Result.create( Result.create(
hardware_id: params[:result_hardware], hardware_id: params[:result_hardware],
benchmark_id: params[:result_benchmark], benchmark_id: params[:result_benchmark],
score: params[:result_average], avg_score: params[:result_average],
minimum_score: result_minimum, min_score: result_minimum,
maximum_score: result_maximum max_score: result_maximum
) )
if params.key?(:result_referrer)
if params[:result_referrer] == 'hardware'
redirect "/hardware/#{params[:result_hardware]}"
elsif params[:result_referrer] == 'benchmark'
redirect "/benchmark/#{params[:result_benchmark]}"
end
else
redirect '/result' redirect '/result'
end end
end
end end

View File

@ -2,18 +2,66 @@
<div class="cell small-12"> <div class="cell small-12">
<h1><%= hardware.name %></h1> <h1><%= hardware.name %></h1>
</div> </div>
<div class="cell small-12">
Hardware type: <%= hardware.type %>
</div> </div>
</div>
<hr>
<div class="grix-x grix-margin-x"> <div class="grix-x grix-margin-x">
<div class="cell small-12"> <div class="cell small-12">
<%= hardware.type %> <form class="u-full-width" action="/result/add" method="post">
<input type="hidden" name="result_hardware" value="<%= hardware.id %>">
<input type="hidden" name="result_referrer" value="hardware">
<div class="grid-x grid-margin-x">
<div class="cell medium-5">
<label for="result_benchmark">
Add benchmark result:
<select class="u-full-width" id="result_benchmark" name="result_benchmark">
<% benchmarks.each do |b| %>
<option value="<%= b.id %>"><%= b.name %></option>
<% end %>
</select>
</label>
</div> </div>
<div class="cell small-12"> <div class="cell medium-2">
<label for="result_average">
Average score:
<input type="text" id="result_average" name="result_average" value="">
</label>
</div>
<div class="cell medium-2">
<label for="result_minimum">
Minimum score:
<input type="text" id="result_minimum" name="result_minimum" value="">
</label>
</div>
<div class="cell medium-2">
<label for="result_maximum">
Maximum score:
<input type="text" id="result_maximum" name="result_maximum" value="">
</label>
</div>
<div class="cell medium-1">
<input type="submit" class="u-full-width button" value="Submit">
</div>
</div>
</form>
<hr>
<h4>Benchmark results involving this hardware:</h4> <h4>Benchmark results involving this hardware:</h4>
<ul> <ul>
<% hardware.results().each do |r| %> <% hardware.results().each do |r| %>
<li><% r.score %></li> <li><%= r.avg_score %></li>
<% end %> <% end %>
</ul> </ul>
</div> </div>