-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-gui.rkt
More file actions
233 lines (215 loc) · 9.4 KB
/
Copy pathtask-gui.rkt
File metadata and controls
233 lines (215 loc) · 9.4 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#lang racket
(require racket/gui)
(require "task-client.rkt")
; main window
(define frame (new frame%
[label "Task Manager"]
[width 800]
[height 800]))
; horizontal panel to split interaction buttons and task list
(define panel (new horizontal-panel% [parent frame]))
; vertical panel for interaction buttons
(define functions (new vertical-panel%
[parent panel]))
;vertical panel for task list
(define tasks (new vertical-panel%
[parent panel]))
;radio box for tracking which tasks we display
(define displayType (void))
;clears all tasks from the panel (this does not delete them)
(define (clearTaskPanel)
(send tasks change-children (lambda (l) '())))
; add a single task to the task display panel
(define (displaySingleTask task)
(let ([taskPanel (new vertical-panel%
[parent tasks])])
(begin
(new message%
[parent taskPanel]
[label (string-append "Task: " (hash-ref task 'name))])
(new message%
[parent taskPanel]
[label (string-append "Due: " (dateString (hash-ref task 'due)))])
(new message%
[parent taskPanel]
[label (string-append "Priority: " (hash-ref task 'priority))])
(new message%
[parent taskPanel]
[label (string-append "Duration: " (number->string (hash-ref task 'duration)))])
(new button%
[parent taskPanel]
[label "edit"]
[callback (lambda (button event)
(launchEditTaskDialog task))])
(new button%
[parent taskPanel]
[label "delete"]
[callback (lambda (button event)
(begin
(deleteTask (hash-ref task 'ID))
(listTasks)))])
)))
; Shows all or todays tasks based on current setting
(define (listTasks)
(if (equal? "All Tasks" (send displayType get-item-label (send displayType get-selection)))
(listAllTasks)
(listTodaysTasks)))
; Add all current tasks to the task display panel
(define (listAllTasks)
(begin
(clearTaskPanel)
(showTasks (hash-ref (readTaskList) 'tasks))))
; Add all tasks chosen for today (based on priority and amount of time to work each day) to the display panel
(define (listTodaysTasks)
(begin
(clearTaskPanel)
(showTasks (getTodaysTasks))))
; add tasks in given list to the task display panel
(define (showTasks list)
(if (null? list)
(void)
(begin
(displaySingleTask (car list))
(showTasks (cdr list)))))
;function that adds all interaction buttons to the interactions panel
(define (draw-buttons)
(begin
(send functions change-children (lambda (l) '()))
(new button% ; Button to add a task
[parent functions]
[label "Add Task"]
[callback (lambda (button event)
(launchAddTaskDialog))])
(new button% ; Button to clear all tasks
[parent functions]
[label "Clear Tasks"]
[callback (lambda (button event)
(begin
(overrideTaskList)
(clearTaskPanel)))])
(set! displayType (new radio-box% ; Radio button to choose display method for tasks
[parent functions]
[label "Display"]
[choices (list "All Tasks" "Today's Tasks")]
[callback (lambda (button event)
(listTasks))]))
(new text-field%
[parent functions]
[label "Working Hours"]
[callback (lambda (field event)
(begin
(changeWorkHours (string->number (send field get-value)))
(listTasks)))])))
; Launch the dialog box to add a task
(define (launchAddTaskDialog)
(begin
(define addTaskDialog (instantiate dialog% ("Add Task"))) ; main dialog object
(define nameBox (new text-field% ; text field for task name
[parent addTaskDialog]
[label "Task Name"]))
(define dueDayBox (new text-field% ; text field for task due date
[parent addTaskDialog]
[label "Due Day"]))
(define dueMonthBox (new text-field% ; text field for task due date
[parent addTaskDialog]
[label "Due Month"]))
(define dueYearBox (new text-field% ; text field for task due date
[parent addTaskDialog]
[label "Due Year"]))
(define priorityBox (new combo-field% ; text field for task due date
[parent addTaskDialog]
[label "Priority"]
[choices (list "very high" "high" "medium" "low" "very low")]
[init-value "medium"]))
(define durationBox (new text-field% ; text field for task due date
[parent addTaskDialog]
[label "Duration"]))
(define buttonPanel (new horizontal-panel% ; panel to hold buttons
[parent addTaskDialog]
[alignment '(center center)]))
(new button% ; button to add task
[parent buttonPanel]
[label "Add Task"]
[callback (lambda (button event)
(begin
(addTask
'auto
(list
(cons 'name (send nameBox get-value))
(cons 'due (simpleMakeDate
(string->number (send dueDayBox get-value))
(string->number (send dueMonthBox get-value))
(string->number (send dueYearBox get-value))))
(cons 'priority (send priorityBox get-value))
(cons 'duration (string->number (send durationBox get-value)))))
(listTasks)
(send addTaskDialog show #f)))])
(new button% ; button to cancel operation
[parent buttonPanel]
[label "Cancel"]
[callback (lambda (button event)
(send addTaskDialog show #f))])
(send addTaskDialog show #t)))
; launch dialog to edit a task
(define (launchEditTaskDialog task)
(begin
(define editTaskDialog (instantiate dialog% ("Edit Task"))) ; main dialog object
(define nameBox (new text-field% ; text field for task name
[parent editTaskDialog]
[label "Task Name"]))
(define dueDayBox (new text-field% ; text field for task due date
[parent editTaskDialog]
[label "Due Day"]))
(define dueMonthBox (new text-field% ; text field for task due date
[parent editTaskDialog]
[label "Due Month"]))
(define dueYearBox (new text-field% ; text field for task due date
[parent editTaskDialog]
[label "Due Year"]))
(define priorityBox (new combo-field% ; text field for task due date
[parent editTaskDialog]
[label "Priority"]
[choices (list "very high" "high" "medium" "low" "very low")]
[init-value "medium"]))
(define durationBox (new text-field% ; text field for task due date
[parent editTaskDialog]
[label "Duration"]))
; initialize fields
(send nameBox set-value (hash-ref task 'name))
(send dueDayBox set-value (number->string (getDay (hash-ref task 'due))))
(send dueMonthBox set-value (number->string (getMonth (hash-ref task 'due))))
(send dueYearBox set-value (number->string (getYear (hash-ref task 'due))))
(send priorityBox set-value (hash-ref task 'priority))
(send durationBox set-value (number->string (hash-ref task 'duration)))
(define buttonPanel (new horizontal-panel% ; panel to hold buttons
[parent editTaskDialog]
[alignment '(center center)]))
(new button% ; button to add task
[parent buttonPanel]
[label "edit Task"]
[callback (lambda (button event)
(begin
(editTask
(hash-ref task 'ID)
(list
(cons 'name (send nameBox get-value))
(cons 'due (simpleMakeDate
(string->number (send dueDayBox get-value))
(string->number (send dueMonthBox get-value))
(string->number (send dueYearBox get-value))))
(cons 'priority (send priorityBox get-value))
(cons 'duration (string->number (send durationBox get-value)))))
(listTasks)
(send editTaskDialog show #f)))])
(new button% ; button to cancel operation
[parent buttonPanel]
[label "Cancel"]
[callback (lambda (button event)
(send editTaskDialog show #f))])
(send editTaskDialog show #t)))
;function to launch the gui
(define (start-gui)
(begin
(draw-buttons)
(listTasks)
(send frame show #t)))