2022-12-07 17:52:27 -05:00
|
|
|
get '/' do
|
2022-12-08 17:26:44 -05:00
|
|
|
items = Item.reverse(:updated_at).limit(10).all()
|
2022-12-07 17:52:27 -05:00
|
|
|
erb :index, :locals => {
|
|
|
|
:title => 'Dashboard',
|
|
|
|
:items => items
|
|
|
|
}
|
|
|
|
end
|
2022-12-07 20:12:23 -05:00
|
|
|
|
|
|
|
get '/item' do
|
|
|
|
redirect '/item/list'
|
|
|
|
end
|
|
|
|
get '/item/list' do
|
2022-12-08 17:26:44 -05:00
|
|
|
items = Item.reverse(:updated_at).all()
|
2022-12-07 20:12:23 -05:00
|
|
|
erb :'item/list', :locals => {
|
|
|
|
:title => 'List of Items',
|
|
|
|
:items => items
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/item/create' do
|
|
|
|
erb :'item/create', :locals => {
|
|
|
|
:title => 'Create New Item'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
post '/item/create' do
|
|
|
|
item = Item.create(
|
|
|
|
name: params[:item_name],
|
|
|
|
serial_number: params[:item_serial],
|
|
|
|
sku_number: params[:item_sku],
|
|
|
|
purchased_from: params[:item_purchase_from],
|
|
|
|
purchased_at: params[:item_purchase_date],
|
|
|
|
manufacturer: params[:item_manufacturer],
|
|
|
|
type: params[:item_type]
|
|
|
|
)
|
|
|
|
|
|
|
|
redirect "/item/#{item.id}"
|
|
|
|
end
|
2022-12-08 01:12:31 -05:00
|
|
|
|
|
|
|
get '/item/:item_id' do
|
2022-12-09 13:44:43 -05:00
|
|
|
item = Item.where(id: params[:item_id]).first()
|
2022-12-08 01:12:31 -05:00
|
|
|
puts "#{item.name}"
|
|
|
|
erb :'item/view', :locals => {
|
|
|
|
:title => item.name,
|
|
|
|
:item => item
|
|
|
|
}
|
|
|
|
end
|
2022-12-08 01:32:41 -05:00
|
|
|
|
2022-12-09 13:44:43 -05:00
|
|
|
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
|
|
|
|
|
2022-12-08 01:32:41 -05:00
|
|
|
post '/item/:item_id/comment' do
|
|
|
|
item = Item.first(id: params[:item_id])
|
|
|
|
|
|
|
|
comment = ItemComment.create(body: params[:comment_body])
|
|
|
|
item.add_item_comment(comment)
|
|
|
|
|
|
|
|
redirect "/item/#{item.id}"
|
|
|
|
end
|
2022-12-08 17:26:44 -05:00
|
|
|
|
|
|
|
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
|
2022-12-09 11:42:12 -05:00
|
|
|
|
2022-12-09 13:44:43 -05:00
|
|
|
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
|
|
|
|
|
2022-12-09 11:42:12 -05:00
|
|
|
post '/license/:license_id/comment' do
|
|
|
|
license = License.first(id: params[:license_id])
|
|
|
|
|
|
|
|
comment = LicenseComment.create(body: params[:comment_body])
|
|
|
|
license.add_license_comment(comment)
|
|
|
|
|
|
|
|
redirect "/license/#{license.id}"
|
|
|
|
end
|