-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
87 lines (71 loc) · 1.09 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
86
87
require 'sinatra'
tasks = []
set bind:'0.0.0.0'
id=0
class Task
attr_accessor :name,:completed,:id,:important,:urgent
def initialize name,id
@name=name
@completed = false
@important = true
@urgent = true
@id=id
end
def toggle_task
@completed=!@completed
end
def importance_toggle
@important=!@important
end
def urgent_toggle
@urgent=!@urgent
end
end
get '/' do
erb :tasks, locals: {:tasks =>tasks}
end
post '/add_task' do
t=Task.new params[:task],id
tasks << t
id=id+1
redirect '/'
end
post '/task_done' do
temp=nil
tasks.each do |task|
if task.id==params[:id].to_i
temp=task
break
end
end
if temp
temp.toggle_task
end
redirect '/'
end
post '/toggle_important' do
temp=nil
tasks.each do |task|
if task.id==params[:task_important].to_i
temp=task
break
end
end
if temp
temp.importance_toggle
end
redirect '/'
end
post '/toggle_urgent' do
temp=nil
tasks.each do |task|
if task.id==params[:task_urgent].to_i
temp=task
break
end
end
if temp
temp.urgent_toggle
end
redirect '/'
end