Skip to content

Commit 15aad85

Browse files
committed
Full Schedule Functionality (expand)
1. Grouping of same-time events now works 2. Event parsing now handles empty cells 3. Description text is actually set
1 parent ef88533 commit 15aad85

2 files changed

Lines changed: 38 additions & 36 deletions

File tree

BrickHack-Mobile/Controllers/ScheduleTableViewController.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ class ScheduleTableViewController: UITableViewController {
139139
}
140140

141141
// Text content
142+
// Note "description" is our own property!
142143
cell.titleLabel.text = currentTimelineEvent.event.title
143-
144-
cell.descriptionLabel.text = currentTimelineEvent.event.timeString
144+
cell.descriptionLabel.text = currentTimelineEvent.event.description
145145

146146
// Configure favorite accessory
147147
let favButton = FavoriteButton(type: .custom)
@@ -189,7 +189,11 @@ class ScheduleTableViewController: UITableViewController {
189189
eventSum += eventsInSection.count
190190
}
191191

192-
return eventSum
192+
// This gets the index to the SECTION.
193+
// Now, we need to increment it relative to the section
194+
// to find out corresponding row's absolute index.
195+
// (debug time for this: 1.5 hours)
196+
return eventSum + indexPath.row
193197
}
194198

195199
// Because of the Wonderful Way UIKit works (https://stackoverflow.com/a/12810613/1431900),
@@ -301,7 +305,6 @@ class ScheduleTableViewController: UITableViewController {
301305
timelineEvent.allColor = self.backColor
302306
}
303307

304-
// @TODO: Set the current event with a TimelinePoint
305308
let mostCurrentEvent = self.timelineEvents.filter({ $0.event.section == sectionIndex }).last
306309
mostCurrentEvent?.timelinePoint = TimelinePoint(color: self.backColor, filled: true)
307310

@@ -373,11 +376,6 @@ class ScheduleTableViewController: UITableViewController {
373376

374377
self.tableView.reloadData()
375378

376-
print("EVENTS AFTER REFRESH: ")
377-
for event in self.timelineEvents {
378-
// print(event)
379-
}
380-
381379
// Show toast to user
382380
toastView.configureContent(title: "Schedule updated!", body: "")
383381
SwiftMessages.hide()

BrickHack-Mobile/Models/ScheduleParser.swift

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,39 +184,37 @@ class ScheduleParser {
184184

185185
}
186186

187+
187188
// MARK: Parsing
188-
// Postcondition: Events that are not fully defined will be SILENTLY SKIPPED.
189-
// @FIXME: Add support for empty-description events!!
189+
190190
// Sets event data as a field
191+
// @FIXME: Bug when setting date ("monday 1am") as date is set then converted? something like that
192+
// Day index appears to be fine.
191193
private static func parseEvents(data: Welcome) {
192194

195+
var currentEvent = Event()
196+
193197
// The parse loop
194198
// @FIXME: Using 3rd sheet as test, convert to 1st for production
195-
for (rowIndex, rowData) in data.sheets[2].data[0].rowData.enumerated() {
199+
for (rowIndex, rowData) in data.sheets[0].data[0].rowData.enumerated() {
196200

197201
// See comment below for how this skip variable functions
198202
var skip = false
199-
var currentEvent = Event()
200203

201204
// Use indexing to more accurately determine column purpose
202205
for columnIndex in 0..<rowData.columns.count {
203206

204207
// Skip section day header title ("Saturday", "Sunday").
205-
// "section" 0 is Saturday, 1 is sunday
208+
// "section" 0 is Saturday, 1 is Sunday
206209
// Note that this is NOT the same as Table View sections -- remember, we are only in the model!
207210
// (and that's how it was named on the spreadsheet)
208211
if skip {
209212
skip = false
210213
continue
211214
}
212215

213-
// Check for valid text
214-
// (And convinence so we don't have to read this mess of an index)
215-
// Note: error message is printed in SHEETS index (1-based) for easier debugging there.
216-
guard let cellText = rowData.columns[columnIndex].userEnteredValue?.stringValue else {
217-
print("Unable to parse cell value \(rowData.columns[columnIndex]) at row \(rowIndex + 1), column \(columnIndex + 1)")
218-
continue
219-
}
216+
// Only set if text is valid, otherwise, #emptystring
217+
let cellText = rowData.columns[columnIndex].userEnteredValue?.stringValue ?? ""
220218

221219
// Now, onto the core parsing.
222220

@@ -241,21 +239,11 @@ class ScheduleParser {
241239
// Now, figure out what part of the Event struct we're filling.
242240
switch columnIndex {
243241
case 0:
244-
// This is the ScheduleKeyword, handled in the above switch statement
245-
// However we use this opportunity to set the schedule index tag from the previous row.
246-
currentEvent.section = sectionIndex
247-
break
248242

249-
case 1: currentEvent.time = stringToDate(cellText) ?? Date()
250-
case 2: currentEvent.title = cellText
251-
case 3: currentEvent.location = cellText
252-
case 4: currentEvent.description = cellText
253-
case 5: currentEvent.uuid = cellText
254-
255-
// Once we reach the fifth case, we know we're at the end of the data for a cell.
256-
// This means that now we can reset the event!
257-
self.events.append(currentEvent)
258-
currentEvent = Event()
243+
guard rowIndex > 1 || !currentEvent.title.isEmpty else {
244+
print("broken like me right now")
245+
break
246+
}
259247

260248
// However, we also need to figure out what UI section the data is in.
261249
// Assuming events are in cronological order:
@@ -269,6 +257,22 @@ class ScheduleParser {
269257
// Otherwise, keep them in the same section.
270258
}
271259
}
260+
261+
// This is the ScheduleKeyword, handled in the above switch statement
262+
// However we use this opportunity to set the schedule index tag from the previous row.
263+
currentEvent.section = sectionIndex
264+
265+
// Append the completed event
266+
self.events.append(currentEvent)
267+
268+
// Reset event manually
269+
currentEvent = Event()
270+
271+
case 1: currentEvent.time = stringToDate(cellText) ?? Date()
272+
case 2: currentEvent.title = cellText
273+
case 3: currentEvent.location = cellText
274+
case 4: currentEvent.description = cellText
275+
case 5: currentEvent.uuid = cellText
272276
default: break
273277
}
274278

@@ -311,7 +315,7 @@ class ScheduleParser {
311315
}
312316

313317
// Helper function for debugging JSON
314-
private func prettyPrintJSON(data: Data) {
318+
private static func prettyPrintJSON(data: Data) {
315319
let json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments)
316320

317321
guard let json2 = json else {

0 commit comments

Comments
 (0)