Added ability to edit and delete items and licenses

This commit is contained in:
Gregory Ballantine 2022-12-09 13:44:43 -05:00
parent db6bfe8e7a
commit 7a81e2c57e
11 changed files with 206 additions and 4 deletions

View File

@ -13,4 +13,9 @@ helpers do
return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z') return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z')
end end
def date_format_input(date)
dt = date.to_datetime
return dt.strftime('%Y-%m-%dT%H:%M:%S')
end
end end

View File

@ -2,4 +2,12 @@ class Item < Sequel::Model
one_to_many :item_comments one_to_many :item_comments
def type_selected?(option)
if self.type == option
return 'selected'
else
return ''
end
end
end end

View File

@ -37,7 +37,7 @@ post '/item/create' do
end end
get '/item/:item_id' do get '/item/:item_id' do
item = Item.where(id: params[:item_id]).first item = Item.where(id: params[:item_id]).first()
puts "#{item.name}" puts "#{item.name}"
erb :'item/view', :locals => { erb :'item/view', :locals => {
:title => item.name, :title => item.name,
@ -45,6 +45,36 @@ get '/item/:item_id' do
} }
end end
get '/item/:item_id/edit' do
item = Item.where(id: params[:item_id]).first()
puts "#{item.name}"
erb :'item/edit', :locals => {
:title => "Editing: #{item.name}",
:item => item
}
end
post '/item/:item_id/edit' do
item = Item.where(id: params[:item_id]).first()
item.name = params[:item_name]
item.serial_number = params[:item_serial]
item.sku_number = params[:item_sku]
item.purchased_from = params[:item_purchase_from]
item.purchased_at = params[:item_purchase_date]
item.manufacturer = params[:item_manufacturer]
item.type = params[:item_type]
item.save()
redirect "/item/#{item.id}"
end
get '/item/:item_id/delete' do
item = Item.where(id: params[:item_id]).first()
item.delete()
redirect '/item/list'
end
post '/item/:item_id/comment' do post '/item/:item_id/comment' do
item = Item.first(id: params[:item_id]) item = Item.first(id: params[:item_id])
@ -93,6 +123,36 @@ get '/license/:license_id' do
} }
end end
get '/license/:license_id/edit' do
license = License.where(id: params[:license_id]).first()
puts "#{license.name}"
erb :'license/edit', :locals => {
:title => "Editing: #{license.name}",
:license => license
}
end
post '/license/:license_id/edit' do
license = License.where(id: params[:license_id]).first()
license.name = params[:license_name]
license.key = params[:license_key]
license.manufacturer = params[:license_manufacturer]
license.seats_used = params[:license_seats_used]
license.seats_total = params[:license_seats_total]
license.purchased_from = params[:license_purchase_from]
license.purchased_at = params[:license_purchase_date]
license.save()
redirect "/license/#{license.id}"
end
get '/license/:license_id/delete' do
license = License.where(id: params[:license_id]).first()
license.delete()
redirect '/license/list'
end
post '/license/:license_id/comment' do post '/license/:license_id/comment' do
license = License.first(id: params[:license_id]) license = License.first(id: params[:license_id])

64
views/item/edit.erb Normal file
View File

@ -0,0 +1,64 @@
<div class="row">
<div class="twelve columns">
<h1>Editing item: <%= item.name %></h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="/item/<%= item.id %>/edit" method="POST" class="u-full-width">
<div class="row">
<div class="columns twelve">
<label for="item_name">Item name:</label>
<input class="u-full-width" type="text" placeholder="My new item" id="item_name" name="item_name" required value="<%= item.name %>">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_serial">Serial number:</label>
<input class="u-full-width" type="text" placeholder="0123456789" id="item_serial" name="item_serial" value="<%= item.serial_number %>">
</div>
<div class="six columns">
<label for="item_sku">SKU number:</label>
<input class="u-full-width" type="text" placeholder="ABC12345678" id="item_sku" name="item_sku" value="<%= item.sku_number %>">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="item_purchase_from" name="item_purchase_from" value="<%= item.purchased_from %>">
</div>
<div class="six columns">
<label for="item_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="item_purchase_date" name="item_purchase_date" value="<%= date_format_input(item.purchased_at) %>">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="item_manufacturer" name="item_manufacturer" value="<%= item.manufacturer %>">
</div>
<div class="six columns">
<label for="item_type">Item type</label>
<select class="u-full-width" id="item_type" name="item_type">
<option value="cpu" <%= item.type_selected?('cpu') %>>Processor</option>
<option value="motherboard" <%= item.type_selected?('motherboard') %>>Motherboard</option>
<option value="memory" <%= item.type_selected?('memory') %>>Memory (RAM)</option>
<option value="psu" <%= item.type_selected?('psu') %>>Power Supply</option>
<option value="case" <%= item.type_selected?('case') %>>Case</option>
<option value="storage" <%= item.type_selected?('storage') %>>Storage Device</option>
<option value="gpu" <%= item.type_selected?('gpu') %>>Graphics Card</option>
</select>
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</div>

View File

@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div class="twelve columns"> <div class="twelve columns">
<h1>Inventory List</h1> <h1>Hardware Inventory List</h1>
</div> </div>
</div> </div>

View File

@ -10,6 +10,10 @@
<div class="row"> <div class="row">
<div class="twelve columns"> <div class="twelve columns">
<p class="inventory-actions">
<a href="/item/<%= item.id %>/edit"><i class="fa-solid fa-pen-to-square"></i></a>
<a href="/item/<%= item.id %>/delete"><i class="fa-solid fa-trash"></i></a>
</p>
<table class="u-full-width"> <table class="u-full-width">
<thead> <thead>
<tr> <tr>

View File

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %> | Raven</title> <title><%= title %> | Raven</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
<link rel="stylesheet" href="/css/kraken.css"> <link rel="stylesheet" href="/css/kraken.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
</head> </head>

View File

@ -17,7 +17,7 @@
<div class="row"> <div class="row">
<div class="six columns"> <div class="six columns">
<label for="license_key">License key:</label> <label for="license_key">License key:</label>
<input class="u-full-width" type="text" placeholder="acbd1234efgh5678" id="license_key" name="license_key"> <input class="u-full-width" type="text" placeholder="acbd1234efgh5678" id="license_key" required name="license_key">
</div> </div>
<div class="six columns"> <div class="six columns">

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

@ -0,0 +1,56 @@
<div class="row">
<div class="twelve columns">
<h1>Editing: <%= license.name %></h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="/license/<%= license.id %>/edit" 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 value="<%= license.name %>">
</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" required value="<%= 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" value="<%= 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" value="<%= 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" value="<%= 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" value="<%= license.purchased_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" value="<%= date_format_input(license.purchased_at) %>">
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</div>

View File

@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div class="twelve columns"> <div class="twelve columns">
<h1>Licenses List</h1> <h1>Software Licenses List</h1>
</div> </div>
</div> </div>

View File

@ -10,6 +10,10 @@
<div class="row"> <div class="row">
<div class="twelve columns"> <div class="twelve columns">
<p class="inventory-actions">
<a href="/license/<%= license.id %>/edit"><i class="fa-solid fa-pen-to-square"></i></a>
<a href="/license/<%= license.id %>/delete"><i class="fa-solid fa-trash"></i></a>
</p>
<table class="u-full-width"> <table class="u-full-width">
<thead> <thead>
<tr> <tr>