This repository has been archived by the owner on Nov 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
82 lines (70 loc) · 1.79 KB
/
app.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
$: << File.dirname(__FILE__)
require 'sinatra'
require 'sinatra/base'
require 'sinatra/respond_with'
require 'sinatra/reloader' if development?
require 'haml'
require 'sass'
require 'json'
require 'tracker.rb'
class Timesheet < Sinatra::Base
register Sinatra::RespondWith
configure :development do
register Sinatra::Reloader
enable :logging
end
configure :development, :production do
set :haml, :format => :html5
set :port, 1337
set :server, "thin"
set :sessions, true
end
before "*.:format" do
content_type params[:format]
end
get "/" do
redirect to("/timer")
end
get "/timer?.?:format?" do
@active_tab = "index"
@summary = Tracker.summary
@running = Tracker.running?
respond_to do |format|
format.html { haml :index }
format.json { @summary.to_json }
format.txt { @summary.inspect }
end
end
post "/timer.?:format?" do
status = "false"
if params[:cmd].eql?('start')
error = "Already running" if Tracker.running?
status = Tracker.start
elsif params[:cmd].eql?('stop')
error = "Not started" unless Tracker.running?
status = Tracker.stop( params[:comment] )
end
status = status ? "ok" : "error"
response = { :status => status }
response[:error] = error if error
respond_to do |format|
format.html { redirect '/' }
format.json { response.to_json }
format.txt { response.inspect }
end
end
get "/history.?:format?" do
@history = Tracker.history
respond_to do |format|
format.json { @history.to_json}
format.html { haml :history}
format.txt { @history.inspect }
end
end
get '/css/custom.css', :provides => [:css] do
respond_to do |format|
format.css { sass :custom }
end
end
run! if app_file == $0
end