Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (53 sloc) 1.94 KB
require 'rubygems'
require 'active_record'
require 'yaml'
require 'logger'
require 'csv'
require 'builder'
require 'sinatra'
dbconfig = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)
#ActiveRecord::Base.logger = Logger.new(STDERR)
class MasterTicket < ActiveRecord::Base
attr_accessible :id, :package, :category, :license, :target, :resolution, :summary
end
class UseTicket < ActiveRecord::Base
attr_accessible :id, :assignee, :category, :status, :resolution, :summary
end
get '/' do
@masters = []
@uses = []
erb :index
end
post '/search' do
params.inspect
@masters = MasterTicket.where("summary like ? ", '%' +params['search'] + '%').order('id').all
@masters.inspect
@uses = UseTicket.where("summary like ? ", '%' +params['search'] + '%').order('id').all
@uses.inspect
erb :master
end
get "/upload" do
erb :upload
end
post "/upload" do
ActiveRecord::Base.connection.execute("TRUNCATE TABLE master_tickets")
i = 0
CSV.foreach(params['csvfile'][:tempfile], :quote_char => '"', :col_sep =>',', :row_sep =>:auto) do |row|
MasterTicket.new(:id=>row[0],:category => row[1], :target => row[2], :license => row[3], :resolution => row[4], :summary =>row[5]).save if row[0].to_i > 0
i = i+1
end
return "The file was successfully uploaded! #{i} records"
end
get "/upload_use" do
erb :upload_use
end
post "/upload_use" do
ActiveRecord::Base.connection.execute("TRUNCATE TABLE use_tickets")
i = 0
CSV.foreach(params['csvfile'][:tempfile], :quote_char => '"', :col_sep =>',', :row_sep =>:auto) do |row|
UseTicket.new(:id=>row[0],:assignee => row[1], :status => row[2], :resolution => row[3], :summary =>row[4], :category => row[5]).save if row[0].to_i > 0
i = i+1
end
return "The file was successfully uploaded! #{i} records"
end
Jump to Line
Something went wrong with that request. Please try again.