-
Notifications
You must be signed in to change notification settings - Fork 4
/
activity_table_slot.rb
137 lines (117 loc) · 3.95 KB
/
activity_table_slot.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
module PomodoroTracker
class ActivityTableSlot < ShoesSlotManager::Slot
TABLE_COLUMNS = ['Description', 'Pomodori', 'Estimate', 'Actions']
DESCRIPTION_WIDTH = 300
POMODORI_WIDTH = ESTIMATE_WIDTH = 100
ACTIONS_WIDTH = 300
DESCRIPTION_LEFT = MENU_WIDTH
POMODORI_LEFT = DESCRIPTION_LEFT + DESCRIPTION_WIDTH
ESTIMATE_LEFT = POMODORI_LEFT + POMODORI_WIDTH
ACTIONS_LEFT = ESTIMATE_LEFT + ESTIMATE_WIDTH
START_BUTTON = :start
DO_TODAY_BUTTON = :do_today
DO_ANOTHER_DAY_BUTTON = :do_another_day
DELETE_BUTTON = :delete
RESURRECT_BUTTON = :resurrect
FINISH_BUTTON = :finish
# activities - the activities to be displayed
# activity_inventory - the activity inventory needed to make changes to
# activities save to the DB
# buttons - array with symbols for buttons to be used
def init_data(slot_manager = nil, options = nil, activities, activity_inventory, buttons)
@slot_manager = slot_manager
@options = options
@activities = activities
@activity_inventory = activity_inventory
@buttons = buttons
end
def content
table_header
@activities_table = stack do
@activities.each{ |activity| new_activity_column(activity) }
end
end
def table_header
flow do
TABLE_COLUMNS.each do |column_name|
left_value = self.class.const_get(column_name.upcase + '_LEFT')
para strong(column_name), left:left_value
end
end
end
def new_activity(activity)
@activities_table.append do new_activity_column(activity) end
end
def new_activity_column(activity)
flow do
TABLE_COLUMNS[0..-2].each do |column_name|
activity_column activity, column_name
end
# actions column is kind of special
actions_column(activity)
end
end
def actions_column(activity)
flow width: ACTIONS_WIDTH do
start_button(activity) if @buttons.include? START_BUTTON
do_another_day_button(activity) if @buttons.include? DO_ANOTHER_DAY_BUTTON
do_today_button(activity) if @buttons.include? DO_TODAY_BUTTON
resurrect_button(activity) if @buttons.include? RESURRECT_BUTTON
delete_button(activity) if @buttons.include? DELETE_BUTTON
finish_button(activity) if @buttons.include? FINISH_BUTTON
end
end
def activity_column activity, column_name
flow width: column_width(column_name) do
para activity.send(column_name.downcase)
end
end
def column_width(column_name)
self.class.const_get((column_name.upcase + "_WIDTH").to_sym)
end
private
def start_button(activity)
button 'Start' do
activity.start
@slot_manager.open PomodoroRunningTab, activity,
@activity_inventory,
@options
end
end
def do_another_day_button(activity)
button 'Do another day' do |do_another_day_button|
activity.do_another_day
remove_row_of do_another_day_button
end
end
def do_today_button(activity)
button "Do Today" do |do_today_button|
activity.do_today
remove_row_of do_today_button
end
end
def delete_button(activity)
button "Delete" do |delete_button|
if confirm 'Sure to delete this activity?'
@activity_inventory.remove activity
remove_row_of delete_button
end
end
end
def resurrect_button(activity)
button 'Resurrect' do |resurrect_button|
activity.resurrect
remove_row_of resurrect_button
end
end
def finish_button(activity)
button 'Finish' do |finish_button|
activity.finish
remove_row_of finish_button
end
end
def remove_row_of(element)
element.parent.parent.remove
end
end
end