82 lines
2.1 KiB
Ruby
82 lines
2.1 KiB
Ruby
|
namespace '/license' do
|
||
|
|
||
|
get '' do
|
||
|
redirect '/license/list'
|
||
|
end
|
||
|
get '/list' do
|
||
|
licenses = License.reverse(:updated_at).all()
|
||
|
erb :'license/list', :locals => {
|
||
|
:title => 'List of Licenses',
|
||
|
:licenses => licenses
|
||
|
}
|
||
|
end
|
||
|
|
||
|
get '/create' do
|
||
|
erb :'license/create', :locals => {
|
||
|
:title => 'Create New License'
|
||
|
}
|
||
|
end
|
||
|
post '/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_id' do
|
||
|
license = License.where(id: params[:license_id]).first()
|
||
|
puts "#{license.name}"
|
||
|
erb :'license/view', :locals => {
|
||
|
:title => license.name,
|
||
|
:license => license
|
||
|
}
|
||
|
end
|
||
|
|
||
|
get '/: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_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_id/delete' do
|
||
|
license = License.where(id: params[:license_id]).first()
|
||
|
license.delete()
|
||
|
|
||
|
redirect '/license/list'
|
||
|
end
|
||
|
|
||
|
post '/: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
|
||
|
|
||
|
end
|