Added License model and views

This commit is contained in:
Gregory Ballantine 2022-12-08 17:26:44 -05:00
parent f1aca6e318
commit 36f7fb82a6
9 changed files with 209 additions and 11 deletions

View File

@ -62,13 +62,17 @@ body{
box-shadow: $box-shadow-2; box-shadow: $box-shadow-2;
} }
#item-header{ #item-header,
.item-name{ #license-header{
.item-name,
.license-name{
margin-bottom: 5px; margin-bottom: 5px;
} }
.item-created, .item-created,
.item-updated{ .item-updated,
.license-created,
.license-updated{
color: #666; color: #666;
font-size: 1.75rem; font-size: 1.75rem;
font-style: italic; font-style: italic;

View File

@ -0,0 +1,22 @@
Sequel.migration do
up do
create_table(:licenses) do
primary_key :id
String :name, null: false
String :key, null: false
String :manufacturer
Integer :seats_used, default: 0
Integer :seats_total, default: 1
String :purchased_from
DateTime :purchased_at
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end
end
down do
drop_table(:licenses)
end
end

5
lib/models/license.rb Normal file
View File

@ -0,0 +1,5 @@
class License < Sequel::Model
end

View File

@ -1,5 +1,5 @@
get '/' do get '/' do
items = Item.all items = Item.reverse(:updated_at).limit(10).all()
erb :index, :locals => { erb :index, :locals => {
:title => 'Dashboard', :title => 'Dashboard',
:items => items :items => items
@ -10,7 +10,7 @@ get '/item' do
redirect '/item/list' redirect '/item/list'
end end
get '/item/list' do get '/item/list' do
items = Item.all items = Item.reverse(:updated_at).all()
erb :'item/list', :locals => { erb :'item/list', :locals => {
:title => 'List of Items', :title => 'List of Items',
:items => items :items => items
@ -53,3 +53,42 @@ post '/item/:item_id/comment' do
redirect "/item/#{item.id}" redirect "/item/#{item.id}"
end end
get '/license' do
redirect '/license/list'
end
get '/license/list' do
licenses = License.reverse(:updated_at).all()
erb :'license/list', :locals => {
:title => 'List of Licenses',
:licenses => licenses
}
end
get '/license/create' do
erb :'license/create', :locals => {
:title => 'Create New License'
}
end
post '/license/create' do
license = License.create(
name: params[:license_name],
key: params[:license_key],
manufacturer: params[:license_manufacturer],
seats_used: params[:license_seats_used],
seats_total: params[:license_seats_total],
purchased_from: params[:license_purchase_from],
purchased_at: params[:license_purchase_date]
)
redirect "/license/#{license.id}"
end
get '/license/:license_id' do
license = License.where(id: params[:license_id]).first()
puts "#{license.name}"
erb :'license/view', :locals => {
:title => license.name,
:license => license
}
end

View File

@ -23,6 +23,7 @@ DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('d
# Load models # Load models
require_relative 'lib/models/item.rb' require_relative 'lib/models/item.rb'
require_relative 'lib/models/item_comment.rb' require_relative 'lib/models/item_comment.rb'
require_relative 'lib/models/license.rb'
# Load helper functions # Load helper functions
require_relative 'lib/helpers.rb' require_relative 'lib/helpers.rb'

View File

@ -1,7 +1,21 @@
<p><a href="/item/create">Create new item</a></p> <div class="row">
<div class="twelve columns">
<h1>Inventory List</h1>
</div>
</div>
<ul> <div class="row">
<div class="twelve columns">
<p><a href="/item/create">Create new item</a></p>
<% if items.length > 0 %>
<ul>
<% items.each do |item| %> <% items.each do |item| %>
<li><%= item.name %></li> <li><%= item.name %></li>
<% end %> <% end %>
</ul> </ul>
<% else %>
<p>There is nothing registered in your inventory yet.</p>
<% end %>
</div>
</div>

56
views/license/create.erb Normal file
View File

@ -0,0 +1,56 @@
<div class="row">
<div class="twelve columns">
<h1>Create new license</h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="/license/create" method="POST" class="u-full-width">
<div class="row">
<div class="columns twelve">
<label for="license_name">Item name:</label>
<input class="u-full-width" type="text" placeholder="My new license" id="license_name" name="license_name" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_key">License key:</label>
<input class="u-full-width" type="text" placeholder="acbd1234efgh5678" id="license_key" name="license_key">
</div>
<div class="six columns">
<label for="license_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="license_manufacturer" name="license_manufacturer">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_seats_used">Seats used on license:</label>
<input class="u-full-width" type="number" placeholder="0" id="license_seats_used" name="license_seats_used">
</div>
<div class="six columns">
<label for="license_seats_total">Total seats on license:</label>
<input class="u-full-width" type="number" placeholder="1" id="license_seats_total" name="license_seats_total">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="license_purchase_from" name="license_purchase_from">
</div>
<div class="six columns">
<label for="license_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="license_purchase_date" name="license_purchase_date">
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</div>

21
views/license/list.erb Normal file
View File

@ -0,0 +1,21 @@
<div class="row">
<div class="twelve columns">
<h1>Licenses List</h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<p><a href="/license/create">Create new license</a></p>
<% if licenses.length > 0 %>
<ul>
<% licenses.each do |license| %>
<li><a href="/license/<%= license.id %>"><%= license.name %></a></li>
<% end %>
</ul>
<% else %>
<p>There is nothing registered in your inventory yet.</p>
<% end %>
</div>
</div>

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

@ -0,0 +1,36 @@
<div id="license-header" class="row">
<div class="twelve columns">
<h1 class="license-name"><%= license.name %></h1>
<h4 class="license-created">License added at: <%= date_format(license.created_at) %></h4>
<% if license.updated_at %>
<h4 class="license-updated">Last updated at: <%= date_format(license.updated_at) %></h4>
<% end %>
</div>
</div>
<div class="row">
<div class="twelve columns">
<table class="u-full-width">
<thead>
<tr>
<th>License key:</th>
<th>Manufacturer:</th>
<th>Seats used:</th>
<th>Seats total:</th>
<th>Vendor:</th>
<th>Purchase Date:</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= license.key %></td>
<td><%= nullable(license.manufacturer) %></td>
<td><%= nullable(license.seats_used) %></td>
<td><%= nullable(license.seats_total) %></td>
<td><%= nullable(license.purchased_from) %></td>
<td><%= nullable(date_format(license.purchased_at)) %></td>
</tr>
</tbody>
</table>
</div>
</div>