diff --git a/lib/helpers.rb b/lib/helpers.rb index f88e02b..d4ec2c8 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -13,4 +13,9 @@ helpers do return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z') end + def date_format_input(date) + dt = date.to_datetime + return dt.strftime('%Y-%m-%dT%H:%M:%S') + end + end diff --git a/lib/models/item.rb b/lib/models/item.rb index 0b7b427..36f4450 100644 --- a/lib/models/item.rb +++ b/lib/models/item.rb @@ -2,4 +2,12 @@ class Item < Sequel::Model one_to_many :item_comments + def type_selected?(option) + if self.type == option + return 'selected' + else + return '' + end + end + end diff --git a/lib/routes.rb b/lib/routes.rb index e402b1c..55d8362 100644 --- a/lib/routes.rb +++ b/lib/routes.rb @@ -37,7 +37,7 @@ post '/item/create' do end get '/item/:item_id' do - item = Item.where(id: params[:item_id]).first + item = Item.where(id: params[:item_id]).first() puts "#{item.name}" erb :'item/view', :locals => { :title => item.name, @@ -45,6 +45,36 @@ get '/item/:item_id' do } 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 item = Item.first(id: params[:item_id]) @@ -93,6 +123,36 @@ get '/license/:license_id' do } 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 license = License.first(id: params[:license_id]) diff --git a/views/item/edit.erb b/views/item/edit.erb new file mode 100644 index 0000000..f724788 --- /dev/null +++ b/views/item/edit.erb @@ -0,0 +1,64 @@ +