Skip to content

Commit f4ec348

Browse files
authored
Merge pull request #245 from TaskarCenterAtUW/feature-undo
Undo Functionality
2 parents 2bfa826 + 9097c0b commit f4ec348

19 files changed

+957
-276
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@
213213
FA8C74D82C60E95100D28220 /* PosmLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8C74D72C60E95100D28220 /* PosmLogin.swift */; };
214214
FA9AEC002D5CACB6006A3A31 /* UserNodesHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9AEBFF2D5CACB3006A3A31 /* UserNodesHelper.swift */; };
215215
FA9F381C2DB2FF4B00D7AABF /* ShadowOverlayRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9F381B2DB2FF3E00D7AABF /* ShadowOverlayRenderer.swift */; };
216+
FA9F38202DC5585600D7AABF /* QuestUndoManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9F381F2DC5584D00D7AABF /* QuestUndoManager.swift */; };
217+
FA9F38222DC93F5300D7AABF /* UndoSidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9F38212DC93F3D00D7AABF /* UndoSidebarView.swift */; };
216218
FA9FE2D82BAC75390036F618 /* OAuthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9FE2D72BAC75390036F618 /* OAuthViewController.swift */; };
217219
FABF3CF42B7419BB0080EAC9 /* LocationManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FABF3CF32B7419BB0080EAC9 /* LocationManagerDelegate.swift */; };
218220
FABF3CF82B822F120080EAC9 /* CustomSureAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = FABF3CF72B822F120080EAC9 /* CustomSureAlert.swift */; };
@@ -229,6 +231,7 @@
229231
FAD5C5162AFCBE720040C61A /* GoInfoGameUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD5C5152AFCBE720040C61A /* GoInfoGameUITestsLaunchTests.swift */; };
230232
FAE2584F2D39819300D2BB12 /* ManageQuestsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE2584E2D39819300D2BB12 /* ManageQuestsView.swift */; };
231233
FAE258522D3A780F00D2BB12 /* FloatingActionButtonStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE258512D3A780F00D2BB12 /* FloatingActionButtonStack.swift */; };
234+
FAEE21DB2DCA1963002F9BEC /* UndoButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEE21DA2DCA1963002F9BEC /* UndoButton.swift */; };
232235
FAF44FBD2B3084EC004FE664 /* OnboardingView1.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAF44FBC2B3084EC004FE664 /* OnboardingView1.swift */; };
233236
FAF44FBF2B3084FB004FE664 /* OnboardingView2.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAF44FBE2B3084FB004FE664 /* OnboardingView2.swift */; };
234237
FAF44FC12B30850A004FE664 /* OnboardingView3.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAF44FC02B30850A004FE664 /* OnboardingView3.swift */; };
@@ -535,6 +538,8 @@
535538
FA8C74D72C60E95100D28220 /* PosmLogin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PosmLogin.swift; sourceTree = "<group>"; };
536539
FA9AEBFF2D5CACB3006A3A31 /* UserNodesHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNodesHelper.swift; sourceTree = "<group>"; };
537540
FA9F381B2DB2FF3E00D7AABF /* ShadowOverlayRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowOverlayRenderer.swift; sourceTree = "<group>"; };
541+
FA9F381F2DC5584D00D7AABF /* QuestUndoManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestUndoManager.swift; sourceTree = "<group>"; };
542+
FA9F38212DC93F3D00D7AABF /* UndoSidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoSidebarView.swift; sourceTree = "<group>"; };
538543
FA9FE2D72BAC75390036F618 /* OAuthViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuthViewController.swift; sourceTree = "<group>"; };
539544
FABF3CF32B7419BB0080EAC9 /* LocationManagerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManagerDelegate.swift; sourceTree = "<group>"; };
540545
FABF3CF72B822F120080EAC9 /* CustomSureAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSureAlert.swift; sourceTree = "<group>"; };
@@ -555,6 +560,7 @@
555560
FAD5C5152AFCBE720040C61A /* GoInfoGameUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoInfoGameUITestsLaunchTests.swift; sourceTree = "<group>"; };
556561
FAE2584E2D39819300D2BB12 /* ManageQuestsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageQuestsView.swift; sourceTree = "<group>"; };
557562
FAE258512D3A780F00D2BB12 /* FloatingActionButtonStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingActionButtonStack.swift; sourceTree = "<group>"; };
563+
FAEE21DA2DCA1963002F9BEC /* UndoButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoButton.swift; sourceTree = "<group>"; };
558564
FAF44FBC2B3084EC004FE664 /* OnboardingView1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView1.swift; sourceTree = "<group>"; };
559565
FAF44FBE2B3084FB004FE664 /* OnboardingView2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView2.swift; sourceTree = "<group>"; };
560566
FAF44FC02B30850A004FE664 /* OnboardingView3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView3.swift; sourceTree = "<group>"; };
@@ -1224,6 +1230,7 @@
12241230
A4E711A52B57BBCA00C9DE08 /* QuestProtocols.swift */,
12251231
A4E711A72B57CA4300C9DE08 /* QuestsRepository.swift */,
12261232
FA6DB8B42D96BE510070CCD3 /* HiddenQuestManager.swift */,
1233+
FA9F381F2DC5584D00D7AABF /* QuestUndoManager.swift */,
12271234
97AC1C122B70EF0A004F0BF4 /* Surfaces.swift */,
12281235
);
12291236
path = quests;
@@ -1317,6 +1324,8 @@
13171324
children = (
13181325
FA87A80F2B68142F000A6BEA /* LoadingView.swift */,
13191326
FAE258512D3A780F00D2BB12 /* FloatingActionButtonStack.swift */,
1327+
FA9F38212DC93F3D00D7AABF /* UndoSidebarView.swift */,
1328+
FAEE21DA2DCA1963002F9BEC /* UndoButton.swift */,
13201329
FA5071972D71F1B000CE9798 /* SyncLogger.swift */,
13211330
);
13221331
path = Utils;
@@ -2082,6 +2091,7 @@
20822091
isa = PBXSourcesBuildPhase;
20832092
buildActionMask = 2147483647;
20842093
files = (
2094+
FA9F38202DC5585600D7AABF /* QuestUndoManager.swift in Sources */,
20852095
FA8C74D42C5A443700D28220 /* QuestOptions.swift in Sources */,
20862096
A4AD130C2B5E80F20041A881 /* StoredElement.swift in Sources */,
20872097
05DBBB5D2B1262BA00B6F110 /* OverpassRepository.swift in Sources */,
@@ -2103,6 +2113,7 @@
21032113
FA18CAE72CC80A34008247F2 /* UploadPhotoModel.swift in Sources */,
21042114
97439F782B87444200DA43E1 /* CrossingKerbHeightForm.swift in Sources */,
21052115
FAFDA1FA2C6B861A00ECEAE9 /* FileStorageManager.swift in Sources */,
2116+
FAEE21DB2DCA1963002F9BEC /* UndoButton.swift in Sources */,
21062117
A4834A3F2B67737500D4F0AA /* StoredChangeset.swift in Sources */,
21072118
973FC02F2B58F81F00878269 /* StepsRamp.swift in Sources */,
21082119
FAFDA2082C6E8F2500ECEAE9 /* APIConfiguration.swift in Sources */,
@@ -2137,6 +2148,7 @@
21372148
FA50718E2D54E1D200CE9798 /* BingTileOverlay.swift in Sources */,
21382149
973FC0352B592C0F00878269 /* StairNumberForm.swift in Sources */,
21392150
FA8C74C22C4E89C800D28220 /* LongForm.swift in Sources */,
2151+
FA9F38222DC93F5300D7AABF /* UndoSidebarView.swift in Sources */,
21402152
FAC9E60F2B04F9C800E2C608 /* OverpassRequestManager.swift in Sources */,
21412153
18EC425E2B849FE000DE05D7 /* TactilePavingCrosswalk.swift in Sources */,
21422154
FA8C74D82C60E95100D28220 /* PosmLogin.swift in Sources */,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1630"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
</BuildAction>
10+
<TestAction
11+
buildConfiguration = "Debug"
12+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
13+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
14+
shouldUseLaunchSchemeArgsEnv = "YES"
15+
shouldAutocreateTestPlan = "YES">
16+
<Testables>
17+
<TestableReference
18+
skipped = "NO"
19+
parallelizable = "YES">
20+
<BuildableReference
21+
BuildableIdentifier = "primary"
22+
BlueprintIdentifier = "FAD5C5042AFCBE720040C61A"
23+
BuildableName = "GoInfoGameTests.xctest"
24+
BlueprintName = "GoInfoGameTests"
25+
ReferencedContainer = "container:GoInfoGame.xcodeproj">
26+
</BuildableReference>
27+
</TestableReference>
28+
</Testables>
29+
</TestAction>
30+
<LaunchAction
31+
buildConfiguration = "Debug"
32+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
33+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
34+
launchStyle = "0"
35+
useCustomWorkingDirectory = "NO"
36+
ignoresPersistentStateOnLaunch = "NO"
37+
debugDocumentVersioning = "YES"
38+
debugServiceExtension = "internal"
39+
allowLocationSimulation = "YES">
40+
</LaunchAction>
41+
<ProfileAction
42+
buildConfiguration = "Release"
43+
shouldUseLaunchSchemeArgsEnv = "YES"
44+
savedToolIdentifier = ""
45+
useCustomWorkingDirectory = "NO"
46+
debugDocumentVersioning = "YES">
47+
</ProfileAction>
48+
<AnalyzeAction
49+
buildConfiguration = "Debug">
50+
</AnalyzeAction>
51+
<ArchiveAction
52+
buildConfiguration = "Release"
53+
revealArchiveInOrganizer = "YES">
54+
</ArchiveAction>
55+
</Scheme>

GoInfoGame/GoInfoGame/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1616
// Override point for customization after application launch.
1717

1818
//clear DB to avoid overlap of data after workspace selection
19-
DatabaseConnector.shared.clearDB()
19+
// DatabaseConnector.shared.clearDB()
2020
validateAccessToken()
2121
return true
2222
}

GoInfoGame/GoInfoGame/AppQuestManager.swift

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,37 @@ class AppQuestManager {
6868
// Fetches all the available quests from Database
6969
func fetchQuestsFromDB() -> [DisplayUnitWithCoordinate] {
7070

71-
let nodesFromStorage = dbInstance.getNodes().filter { n in
72-
n.tags.count != 0
71+
let allOriginalNodes = dbInstance.getNodes().filter { $0.isOriginal && $0.tags.count != 0 }
72+
73+
let nodesFromStorage = allOriginalNodes.compactMap { original in
74+
if let edited = self.dbInstance.getNode(id: original.id, version: .edited),
75+
edited.tags.count != 0,
76+
edited.tags["ext:gig_complete"] != "yes" {
77+
return edited
78+
} else if original.tags["ext:gig_complete"] != "yes" {
79+
return original
80+
} else {
81+
return nil
82+
}
7383
}
74-
let waysFromStorage = dbInstance.getWays().filter{w in w.tags.count != 0 }
84+
85+
let allOriginalWays = dbInstance.getWays().filter {
86+
$0.isOriginal && $0.tags.count != 0
87+
}
88+
89+
let waysFromStorage = allOriginalWays.compactMap { original in
90+
if let edited = self.dbInstance.getWay(id: original.id, version: .edited),
91+
edited.tags.count != 0,
92+
edited.tags["ext:gig_complete"] != "yes" {
93+
return edited
94+
} else if original.tags["ext:gig_complete"] != "yes" {
95+
return original
96+
} else {
97+
return nil
98+
}
99+
}
100+
101+
75102
let nodeElements = nodesFromStorage.map({$0.asNode()})
76103
let wayElements = waysFromStorage.map({$0.asWay()})
77104

@@ -109,21 +136,14 @@ class AppQuestManager {
109136
let position = dbInstance.getCenterForWay(id: String(way.id)) ?? CLLocationCoordinate2D()
110137
let unit = DisplayUnitWithCoordinate(displayUnit: duplicateQuest.displayUnit, coordinateInfo: position, id: way.id, isHidden: false)
111138
displayUnits.append(unit)
112-
// if(quest is SideWalkWidth){
113-
// if let q = quest as? SideWalkWidth {
114-
// q.assignAnsweringHandler()
115-
// }
116-
// }
117139
wayQuests.append(duplicateQuest)
118140
break
119141
}
120142
}
121143
}
122144
print("Sending back items")
123145
print(allQuests)
124-
125-
print(nodeElements.filter({ $0.id == 1026105 }))
126-
146+
127147

128148
// get hidden ids from hiddenElements
129149
let hiddenIds = HiddenQuestManager.shared.hiddenQuests.map { $0.id }

GoInfoGame/GoInfoGame/DataBase/DBModels/StoredNode.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ import osmapi
1414
// Stores a node instance
1515
class StoredNode : Object {
1616

17-
@Persisted(primaryKey: true) var id: Int = 0
17+
@Persisted(primaryKey: true) var compoundId: String
18+
@Persisted var id: Int
1819
@Persisted var tags = Map<String,String>()
1920
@Persisted var version: Int = 0
2021
@Persisted var timestamp : String = ""
2122
@Persisted var point: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
2223

24+
@Persisted var isOriginal: Bool = false
25+
26+
func generateCompoundId() {
27+
self.compoundId = "\(id)-\(isOriginal ? "original" : "edited")"
28+
}
29+
2330
// Give another method that gives node
2431
public func asNode() -> Node {
2532
let position = LatLon(latitude: point.latitude , longitude: point.longitude)

GoInfoGame/GoInfoGame/DataBase/DBModels/StoredWay.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,35 @@ import osmparser
1212
import MapKit
1313
import osmapi
1414

15+
enum StoredWayVersion: String {
16+
case original
17+
case edited
18+
}
19+
20+
enum StoredNodeVersion: String {
21+
case original
22+
case edited
23+
}
24+
25+
1526
// Represents one stored way
1627
class StoredWay: Object {
1728

18-
@Persisted(primaryKey: true) var id: Int = 0
29+
@Persisted(primaryKey: true) var compoundId: String
30+
@Persisted var id: Int
1931
@Persisted var tags = Map<String,String>()
2032
@Persisted var version: Int = 0
2133
@Persisted var timestamp : String = ""
2234
@Persisted var nodes: List<Int64> = List<Int64>()
2335
// Need to persist the points
2436
@Persisted var polyline: List<CLLocationCoordinate2D> = List<CLLocationCoordinate2D>()
2537

38+
@Persisted var isOriginal: Bool = false
39+
40+
func generateCompoundId() {
41+
self.compoundId = "\(id)-\(isOriginal ? "original" : "edited")"
42+
}
43+
2644

2745
public func asWay() -> Way {
2846
var theTags: [String:String] = [:]

0 commit comments

Comments
 (0)