Added item view page; added some helpers for simplifying view logic

This commit is contained in:
Gregory Ballantine 2022-12-08 01:12:31 -05:00
parent dd136d19c9
commit 11d33e394b
5 changed files with 78 additions and 0 deletions

View File

@ -5,6 +5,7 @@ $box-shadow-2: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
body{
background: lightgrey;
padding-left: $nav-width;
}
#main-nav{
@ -60,3 +61,16 @@ body{
border-radius: 5px;
box-shadow: $box-shadow-2;
}
#item-header{
.item-name{
margin-bottom: 5px;
}
.item-created,
.item-updated{
color: #666;
font-size: 1.75rem;
font-style: italic;
}
}

16
lib/helpers.rb Normal file
View File

@ -0,0 +1,16 @@
helpers do
def nullable(value)
if (value) and (value != '')
return value
else
return 'N/a'
end
end
def date_format(date)
dt = date.to_datetime
return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z')
end
end

View File

@ -35,3 +35,12 @@ post '/item/create' do
redirect "/item/#{item.id}"
end
get '/item/:item_id' do
item = Item.where(id: params[:item_id]).first
puts "#{item.name}"
erb :'item/view', :locals => {
:title => item.name,
:item => item
}
end

View File

@ -23,5 +23,8 @@ DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('d
# Load models
require_relative 'lib/models/item.rb'
# Load helper functions
require_relative 'lib/helpers.rb'
# Register route handlers
require_relative 'lib/routes.rb'

36
views/item/view.erb Normal file
View File

@ -0,0 +1,36 @@
<div id="item-header" class="row">
<div class="twelve columns">
<h1 class="item-name"><%= item.name %></h1>
<h4 class="item-created">Item added at: <%= date_format(item.created_at) %></h4>
<% if item.updated_at %>
<h4 class="item-updated">Last updated at: <%= date_format(item.updated_at) %></h4>
<% end %>
</div>
</div>
<div class="row">
<div class="twelve columns">
<table class="u-full-width">
<thead>
<tr>
<th>Item type:</th>
<th>Manufacturer:</th>
<th>Serial number:</th>
<th>SKU number:</th>
<th>Vendor:</th>
<th>Purchase Date:</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= item.type %></td>
<td><%= nullable(item.manufacturer) %></td>
<td><%= nullable(item.serial_number) %></td>
<td><%= nullable(item.sku_number) %></td>
<td><%= nullable(item.purchased_from) %></td>
<td><%= nullable(date_format(item.purchased_at)) %></td>
</tr>
</tbody>
</table>
</div>
</div>