-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
85 lines (76 loc) · 2.31 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
83
84
85
require 'cuba'
require 'cuba/render'
require 'slim'
require 'ohm'
require 'pry'
Dir["./models/**/*.rb"].each { |rb| require rb }
Dir["./lib/**/*.rb"].each { |rb| require rb }
Dir["./helpers/**/*.rb"].each { |rb| require rb }
Cuba.use Rack::Static, root: "public", urls: ["/js"]
Cuba.plugin UserHelpers
Cuba.plugin Cuba::Render
Cuba.settings[:render][:template_engine] = "slim"
Cuba.define do
on "user" do
if current_user
pomodoro = Pomodoro.new({ user: current_user })
render("add_pomodoro", pomodoro: pomodoro)
on param("pomodoro") do |params|
Pomodoro.create(params)
res.redirect user_path
end
res.write partial("search_pomodoro")
on param("pomodoro_search") do |params|
if pomodoros_created_at(params["created_at"]).empty?
res.redirect user_path
else
res.write partial("search", pomodoros: pomodoros_created_at(params["created_at"]))
res.write partial("current_pomodoro", pomodoro: only_current_pomodoro)
res.write partial("home", pomodoros: pomodoros_by_date)
end
end
res.write partial("current_pomodoro", pomodoro: only_current_pomodoro)
res.write partial("home", pomodoros: pomodoros_by_date)
else
res.redirect root_path
end
end
on "pomarolo/finish/:pomodoro_id" do |pomodoro_id|
if current_user
Pomodoro[pomodoro_id].swap_finish
res.redirect user_path
else
res.redirect root_path
end
end
on "pomarolo/interruption/:pomodoro_id" do |pomodoro_id|
if current_user
on param("interruption") do |params|
Interruption.create(params)
res.redirect user_path
end
res.write partial("interruptions", interruptions: list_interruptions(pomodoro_id))
else
res.redirect root_path
end
end
on "pomarolo/:pomodoro_id/real/:value" do |pomodoro_id, value|
if current_user
Pomodoro[pomodoro_id].real_po(value)
res.write partial("current_pomodoro", pomodoro: only_current_pomodoro)
else
res.redirect root_path
end
end
on "pomarolo/current/:pomodoro_id" do |pomodoro_id|
if current_user
Pomodoro[pomodoro_id].current_pomodoro!(only_current_pomodoro)
res.redirect user_path
else
res.redirect root_path
end
end
on default do
run Authentication
end
end