-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rb
More file actions
104 lines (86 loc) · 3.6 KB
/
server.rb
File metadata and controls
104 lines (86 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'sinatra'
require_relative 'setup'
configure :production do
set :host_authorization, { permitted_hosts: [] }
end
get "/" do
@matches = DB[:matches].join(:plays, match_code: :code).where(Sequel[:plays][:team_number] => ENV['TEAM']).select_all(:matches).order(:time).distinct
@next_match = @matches.where(status: 'Upcoming').first
if @next_match
@next_match_plays = DB[:plays].where(match_code: @next_match[:code]).join(:teams, number: :team_number).select(Sequel[:plays][:team_number], Sequel[:plays][:alliance], Sequel[:plays][:epa], Sequel[:teams][:name])
@next_match_prediction = JSON.parse(@next_match[:prediction])
end
@matches = @matches.to_a
erb :index
end
get '/teams' do
@teams = DB.from(:teams)
erb :'teams/index'
end
get '/teams/:number' do
@team = DB.from(:teams).where(number: params[:number]).first
@notes = DB.from(:notes).where(team_number: params[:number])
@photos = DB.from(:photos).where(team_number: params[:number])
@plays = DB[:plays].where(team_number: params[:number])
@matches = @plays.join(:matches, code: :match_code).select(Sequel[:matches][:code], Sequel[:matches][:time], Sequel[:matches][:status], Sequel[:matches][:prediction], Sequel[:matches][:real_results], Sequel[:plays][:alliance], Sequel[:plays][:epa]).order(:time)
@all_plays = DB[:plays].where(match_code: @matches.map { |m| m[:code] })
erb :'teams/show'
end
get "/teams/:number/edit" do
@team = DB.from(:teams).where(number: params[:number]).first
erb :'teams/edit'
end
post "/teams/:number" do
@team = DB.from(:teams).where(number: params[:number]).update(play_style: params[:play_style], name: params[:name])
redirect "/teams/#{params[:number]}"
end
get "/notes/new" do
@team_number = params['team_number']
erb :'notes/new'
end
post "/note" do
DB[:notes].insert(team_number: params['team_number'], content: params['content'], event_id: params[:event_id])
if params["team_number"].downcase == "boom" && params["content"].downcase == "boom"
erb :BOOM
else
redirect "/"
end
end
get "/notes/:id/edit" do
@note = DB.from(:notes).where(id: params[:id]).first
erb :'notes/edit'
end
post "/notes/:id" do
@note = DB.from(:notes).where(id: params[:id]).update(content: params[:content],team_number: params[:team_number], event_id: params[:event_id])
redirect "/teams/#{params[:team_number]}"
end
get "/photos/new" do
@team_number = params['team_number']
erb :'photos/new'
end
post "/photo" do
filename = params[:file][:filename]
file = params[:file][:tempfile]
File.open("./public/uploads/#{filename}", 'wb') do |f|
f.write(file.read)
end
DB[:photos].insert(team_number: params['team_number'], filename: filename)
redirect "/"
end
get "/events" do
@events = DB[:events].all
erb :'events/index'
end
get "/events/:code" do
@event = DB[:events].where(code: params['code']).first
@teams = DB[:attendance].where(event_id: @event[:id]).join(:teams, id: :team_id).select(Sequel[:teams][:number], Sequel[:teams][:name])
@matches = DB[:matches].where(event_id: @event[:id]).order(:time).all
@notes = DB[:notes].where(team_number: @teams.map { |t| t[:number] }).join(:teams, number: :team_number).select(Sequel[:notes][:team_number], Sequel[:notes][:content], Sequel[:teams][:name])
erb :'events/show'
end
get '/matches/:code' do
@match = DB[:matches].where(code: params[:code]).first
@plays = DB[:plays].where(match_code: params[:code]).join(:teams, number: :team_number).select(Sequel[:plays][:team_number], Sequel[:plays][:alliance], Sequel[:plays][:epa], Sequel[:teams][:name])
@match_prediction = JSON.parse(@match[:prediction])
erb :'matches/show'
end