-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.rb
92 lines (77 loc) · 1.94 KB
/
server.rb
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
require 'sinatra'
require 'haml'
require 'sass'
require 'client'
require 'project'
require 'progress_report'
require 'storage'
# For Countdown widget
require 'countdown'
module EDash
class Server < Sinatra::Base
set :static, true
set :public, 'public'
set :haml, { :format => :html5 }
before do
headers 'Content-Type' => 'text/html; charset=utf-8'
end
def initialize
Storage.init_store(options.environment.to_s)
super
end
helpers do
def path_root
"http://" + request.env["HTTP_HOST"]
end
end
get '/?', :agent => /iPhone|iPod/ do
@projects = Project.all
haml :mobile
end
get '/detail/:project', :agent => /iPhone|iPod/ do
@project = Project.find(params[:project])
if (@project.nil?)
return 404
end
haml :detail, :layout => false
end
get '/?' do
@projects = Project.all
@countdowns = Countdown.all
haml :index
end
post '/build/?' do
project = Project.find(params[:project])
if (project.nil?)
project = Project.new(params)
else
project.update_from(params)
end
Project.save(project)
EDash::Client.send_message(request.host, project.to_json)
end
post '/progress/?' do
project = Project.find(params[:project])
if (project.nil?)
return 404
else
project.progress = ProgressReport.new(params[:progress])
Project.save(project)
end
EDash::Client.send_message(request.host, project.to_json)
end
post '/countdown/?' do
countdown = Countdown.find_or_create(params[:countdown])
EDash::Client.send_message(request.host, countdown.to_json)
redirect '/'
end
get '/main.css' do
content_type 'text/css', :charset => 'utf-8'
sass :main
end
get '/mobile.css' do
content_type 'text/css', :charset => 'utf-8'
sass :mobile
end
end
end