Added abilities to view and edit benchmark info

This commit is contained in:
Gregory Ballantine 2025-05-30 01:45:49 -04:00
parent cf9235cb18
commit ed085e4b40
5 changed files with 94 additions and 7 deletions

View File

@ -27,4 +27,32 @@ class GameData < Sinatra::Base
redirect "/benchmark/#{benchmark.id}"
end
get '/benchmark/:benchmark_id' do
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
erb :'benchmark/view', locals: {
title: benchmark.name,
benchmark: benchmark
}
end
get '/benchmark/:benchmark_id/edit' do
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
erb :'benchmark/edit', locals: {
title: "Editing: #{benchmark.name}",
benchmark: benchmark
}
end
post '/benchmark/:benchmark_id/edit' do
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
benchmark.update(
name: params[:benchmark_name],
scoring: params[:benchmark_scoring],
description: params[:benchmark_description]
)
redirect "/benchmark/#{benchmark.id}"
end
end

43
views/benchmark/edit.erb Normal file
View File

@ -0,0 +1,43 @@
<div class="grid-x grid-margin-x">
<div class="cell small-12">
<h1>Editing: <%= benchmark.name %></h1>
</div>
</div>
<div class="grid-x grid-margin-x">
<form class="cell small-12" action="/benchmark/<%= benchmark.id %>/edit" method="post">
<div class="grid-x grid-padding-x">
<div class="cell medium-9">
<label>
Benchmark name
<input type="text" name="benchmark_name" placeholder="Example benchmark" value="<%= benchmark.name %>">
</label>
</div>
<div class="cell medium-3">
<label>
Scoring type
<select name="benchmark_scoring">
<option value="fps" <% if benchmark.scoring == 'fps' %>selected<% end %>>Frames per Second (fps)</option>
<option value="ms" <% if benchmark.scoring == 'ms' %>selected<% end %>>Frame Time (ms)</option>
<option value="pts" <% if benchmark.scoring == 'pts' %>selected<% end %>>Total Points</option>
</select>
</label>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="cell small-12">
<textarea name="benchmark_description" class="cell small-12"><%= benchmark.description %></textarea>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="cell small-12">
<input type="submit" class="button" value="Submit">
</div>
</div>
</form>
</div>

View File

@ -18,17 +18,15 @@
<tr>
<th>Benchmark name</th>
<th>Scoring type</th>
<th>Date added</th>
<th>Date modified</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<% benchmarks.each do |b| %>
<tr>
<td><%= b.name %></td>
<td><a href="/benchmark/<%= b.id %>"><%= b.name %></a</td>
<td><%= b.scoring %></td>
<td><%= date_format(b.created_at) %></td>
<td><%= date_format(b.updated_at) %></td>
<td><%= b.description %></td>
</tr>
<% end %>
</tbody>

18
views/benchmark/view.erb Normal file
View File

@ -0,0 +1,18 @@
<div class="grid-x grid-margin-x">
<div class="cell small-12">
<h1><%= benchmark.name %></h1>
</div>
<div class="cell small-12">
<p><a href="/benchmark/<%= benchmark.id %>/edit">Edit</a></p>
</div>
<div class="cell small-12">
Benchmark scoring type: <%= benchmark.scoring %>
</div>
<div class="cell small-12">
Description:
<p><%= benchmark.description %></p>
</div>
</div>

View File

@ -4,11 +4,11 @@
</div>
<div class="cell small-12">
Hardware type: <%= hardware.type %>
<p><a href="/hardware/<%= hardware.id %>/edit">Edit</a></p>
</div>
<div class="cell small-12">
<p><a href="/hardware/<%= hardware.id %>/edit">Edit</a></p>
Hardware type: <%= hardware.type %>
</div>
</div>