Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up adjustments to DueBy model #638

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<attribute name="alertStart" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="autodata" optional="YES" attributeType="String"/>
<attribute name="deadline" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="dueByDaystamp" optional="YES" attributeType="Transformable" valueTransformerName="DueByTableValueTransformer" customClassName="NSDictionary"/>
<attribute name="dueBy" optional="YES" attributeType="Transformable" valueTransformerName="DueByTableValueTransformer" customClassName="NSDictionary"/>
<attribute name="graphUrl" attributeType="String"/>
<attribute name="healthKitMetric" optional="YES" attributeType="String"/>
<attribute name="hhmmFormat" attributeType="Boolean" usesScalarValueType="YES"/>
Expand Down
13 changes: 12 additions & 1 deletion BeeKit/Model/DueBy/DueByDictionary.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
// Part of BeeSwift. Copyright Beeminder

import SwiftyJSON

/// Delta and Total due by YYYYMMDD daystamp
public typealias DueByDictionary = [String: BeeminderDueByEntry]
public typealias DueByDictionary = [String: DueByEntry]

extension DueByDictionary {
/// Creates a DueByDictionary from SwiftyJSON
/// - Parameter json: JSON object containing due by data
/// - Returns: Dictionary mapping daystamps to DueByEntry objects
public init(json: JSON) {
self = json.dictionaryValue.compactMapValues(DueByEntry.init)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import SwiftyJSON

@objc(BeeminderDueByEntry)
public class BeeminderDueByEntry: NSObject, Codable {
@objc(DueByEntry)
public class DueByEntry: NSObject, Codable {
public let total: Double
public let delta: Double
public let formattedTotal: String
Expand Down
4 changes: 2 additions & 2 deletions BeeKit/Model/Goal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class Goal: NSManagedObject {
@objc(removeRecentData:)
@NSManaged public func removeFromRecentData(_ values: Set<DataPoint>)

@NSManaged public var dueByDaystamp: DueByDictionary
@NSManaged public var dueBy: DueByDictionary

/// The last time this record in the CoreData store was updated
@NSManaged public var lastModifiedLocal: Date
Expand Down Expand Up @@ -173,7 +173,7 @@ public class Goal: NSManagedObject {
self.useDefaults = json["use_defaults"].boolValue
self.won = json["won"].boolValue
self.yAxis = json["yaxis"].stringValue
self.dueByDaystamp = json["dueby"].dictionaryValue.compactMapValues(BeeminderDueByEntry.init)
self.dueBy = DueByDictionary(json: json["dueby"])

// Replace recent data with results from server
// Note at present this leaks data points in the main db. This is probably fine for now
Expand Down
2 changes: 1 addition & 1 deletion BeeSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 70;
objects = {

/* Begin PBXBuildFile section */
Expand Down
4 changes: 2 additions & 2 deletions BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
self.datapointTableController.hhmmformat = goal.hhmmFormat
self.datapointTableController.datapoints = goal.recentData.sorted(by: {$0.updatedAt < $1.updatedAt})

self.deltasLabel.isHidden = goal.dueByDaystamp.isEmpty
self.deltasLabel.isHidden = goal.dueBy.isEmpty
self.deltasLabel.attributedText = self.dueByTableAttributedString

self.refreshCountdown()
Expand Down Expand Up @@ -681,7 +681,7 @@ private extension GoalViewController {

private extension GoalViewController {
var dueByTableAttributedString: NSAttributedString {
let textAndColor: [(text: String, color: UIColor)] = goal.dueByDaystamp
let textAndColor: [(text: String, color: UIColor)] = goal.dueBy
.sorted(using: SortDescriptor(\.key))
.compactMap { $0.value.formattedDelta }
.map { $0 == "✔" ? "✓" : $0 }
Expand Down
Loading