From 37c2bf4e25c62c8527cbf647328402f8cceec489 Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Wed, 25 Nov 2015 18:30:01 +0100 Subject: [PATCH 1/2] Data model changes for account settings (v43) --- MIGRATIONS.md | 5 + .../WordPress.xcdatamodeld/.xccurrentversion | 2 +- .../WordPress 43.xcdatamodel/contents | 521 ++++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 4 +- 4 files changed, 530 insertions(+), 2 deletions(-) create mode 100644 WordPress/Classes/WordPress.xcdatamodeld/WordPress 43.xcdatamodel/contents diff --git a/MIGRATIONS.md b/MIGRATIONS.md index 41a8b641727b..38be97e03939 100644 --- a/MIGRATIONS.md +++ b/MIGRATIONS.md @@ -3,6 +3,11 @@ This file documents changes in the data model. Please explain any changes to the data model as well as any custom migrations. +## WordPress 43 (@koke 2015-11-23) + +- Added new entity `AccountSettings` +- `Account` has now a new one-to-one relationship mapping to `AccountSettings` + ## WordPress 42 (@jleandroperez 2015-11-06) Changes to the data model: diff --git a/WordPress/Classes/WordPress.xcdatamodeld/.xccurrentversion b/WordPress/Classes/WordPress.xcdatamodeld/.xccurrentversion index f2220e0983c1..ab39ed13a0b5 100644 --- a/WordPress/Classes/WordPress.xcdatamodeld/.xccurrentversion +++ b/WordPress/Classes/WordPress.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - WordPress 42.xcdatamodel + WordPress 43.xcdatamodel diff --git a/WordPress/Classes/WordPress.xcdatamodeld/WordPress 43.xcdatamodel/contents b/WordPress/Classes/WordPress.xcdatamodeld/WordPress 43.xcdatamodel/contents new file mode 100644 index 000000000000..1159de47c178 --- /dev/null +++ b/WordPress/Classes/WordPress.xcdatamodeld/WordPress 43.xcdatamodel/contents @@ -0,0 +1,521 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 808d33754d20..2df0c0b57884 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1593,6 +1593,7 @@ E1B912841BB01266003C25B9 /* PeopleCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleCell.swift; sourceTree = ""; }; E1B912881BB01288003C25B9 /* PeopleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleViewController.swift; sourceTree = ""; }; E1B9128A1BB0129C003C25B9 /* WPStyleGuide+People.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WPStyleGuide+People.swift"; sourceTree = ""; }; + E1BCFBC51C0626C5004BDADF /* WordPress 43.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 43.xcdatamodel"; sourceTree = ""; }; E1C265C71BECFCDD00DC4C6B /* WPCrashlyticsLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WPCrashlyticsLogger.h; sourceTree = ""; }; E1C265C81BECFCDD00DC4C6B /* WPCrashlyticsLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WPCrashlyticsLogger.m; sourceTree = ""; }; E1C807471696F72E00E545A6 /* WordPress 9.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 9.xcdatamodel"; sourceTree = ""; }; @@ -6463,6 +6464,7 @@ E125443B12BF5A7200D87A0A /* WordPress.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + E1BCFBC51C0626C5004BDADF /* WordPress 43.xcdatamodel */, B555E1131C04A1DD00CEC81B /* WordPress 42.xcdatamodel */, B566DE701BFE46D9002B9DBB /* WordPress 41.xcdatamodel */, FA2D12891BCED0AD006F2A15 /* WordPress 40.xcdatamodel */, @@ -6506,7 +6508,7 @@ 8350E15911D28B4A00A7B073 /* WordPress.xcdatamodel */, E125443D12BF5A7200D87A0A /* WordPress 2.xcdatamodel */, ); - currentVersion = B555E1131C04A1DD00CEC81B /* WordPress 42.xcdatamodel */; + currentVersion = E1BCFBC51C0626C5004BDADF /* WordPress 43.xcdatamodel */; name = WordPress.xcdatamodeld; path = Classes/WordPress.xcdatamodeld; sourceTree = ""; From 9b08925f16941280dda915f085014d7cf803b029 Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Wed, 25 Nov 2015 18:47:39 +0100 Subject: [PATCH 2/2] Added AccountSettings model --- .../Classes/Models/AccountSettings.swift | 147 ++++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 4 + 2 files changed, 151 insertions(+) create mode 100644 WordPress/Classes/Models/AccountSettings.swift diff --git a/WordPress/Classes/Models/AccountSettings.swift b/WordPress/Classes/Models/AccountSettings.swift new file mode 100644 index 000000000000..b4df92141afc --- /dev/null +++ b/WordPress/Classes/Models/AccountSettings.swift @@ -0,0 +1,147 @@ +import Foundation + +struct AccountSettings { + // MARK: - My Profile + let firstName: String // first_name + let lastName: String // last_name + let displayName: String // display_name + let aboutMe: String // description + + // MARK: - Account Settings + let username: String // user_login + let email: String // user_email + let primarySiteID: Int // primary_site_ID + let webAddress: String // user_URL + let language: String // language +} + +class ManagedAccountSettings: NSManagedObject { + static let entityName = "AccountSettings" + + @NSManaged var firstName: String + @NSManaged var lastName: String + @NSManaged var displayName: String + @NSManaged var aboutMe: String + + @NSManaged var username: String + @NSManaged var email: String + @NSManaged var primarySiteID: Int + @NSManaged var webAddress: String + @NSManaged var language: String + + @NSManaged var account: WPAccount + + func updateWith(accountSettings: AccountSettings) { + firstName = accountSettings.firstName + lastName = accountSettings.lastName + displayName = accountSettings.displayName + aboutMe = accountSettings.aboutMe + + username = accountSettings.username + email = accountSettings.email + primarySiteID = accountSettings.primarySiteID + webAddress = accountSettings.webAddress + language = accountSettings.language + } + + /** + Applies a change to the account settings + + To change a setting, you create a change and apply it to the AccountSettings object. + This method will return a new change object to apply if you want to revert the changes (for instance, if they failed to save) + + - returns: the change object needed to revert this change + */ + func applyChange(change: AccountSettingsChange) -> AccountSettingsChange { + let reverse = reverseChange(change) + + switch change { + case .FirstName(let value): + self.firstName = value + case .LastName(let value): + self.lastName = value + case .DisplayName(let value): + self.displayName = value + case .AboutMe(let value): + self.aboutMe = value + case .Email(let value): + self.email = value + case .PrimarySite(let value): + self.primarySiteID = value + case .WebAddress(let value): + self.webAddress = value + case .Language(let value): + self.language = value + } + + return reverse + } + + private func reverseChange(change: AccountSettingsChange) -> AccountSettingsChange { + switch change { + case .FirstName(_): + return .FirstName(self.firstName) + case .LastName(_): + return .LastName(self.lastName) + case .DisplayName(_): + return .DisplayName(self.displayName) + case .AboutMe(_): + return .AboutMe(self.aboutMe) + case .Email(_): + return .Email(self.email) + case .PrimarySite(_): + return .PrimarySite(self.primarySiteID) + case .WebAddress(_): + return .WebAddress(self.webAddress) + case .Language(_): + return .Language(self.language) + } + } +} + +extension AccountSettings { + init(managed: ManagedAccountSettings) { + firstName = managed.firstName + lastName = managed.lastName + displayName = managed.displayName + aboutMe = managed.aboutMe + + username = managed.username + email = managed.email + primarySiteID = managed.primarySiteID + webAddress = managed.webAddress + language = managed.language + } +} + +enum AccountSettingsChange { + case FirstName(String) + case LastName(String) + case DisplayName(String) + case AboutMe(String) + case Email(String) + case PrimarySite(Int) + case WebAddress(String) + case Language(String) + + var stringValue: String { + switch self { + case .FirstName(let value): + return value + case .LastName(let value): + return value + case .DisplayName(let value): + return value + case .AboutMe(let value): + return value + case .Email(let value): + return value + case .PrimarySite(let value): + return String(value) + case .WebAddress(let value): + return value + case .Language(let value): + return value + } + } +} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 2df0c0b57884..554225e018c9 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -514,6 +514,7 @@ E183ECB116B2179B00C2EB11 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 296890770FE971DC00770264 /* Security.framework */; }; E183ECB216B2179B00C2EB11 /* Twitter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC24E5F21577DFF400A6D5B5 /* Twitter.framework */; }; E18EE95119349EC300B0A40C /* ReaderTopicServiceRemote.m in Sources */ = {isa = PBXBuildFile; fileRef = E18EE95019349EC300B0A40C /* ReaderTopicServiceRemote.m */; }; + E18FCF081C062B84005FCA25 /* AccountSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18FCF071C062B84005FCA25 /* AccountSettings.swift */; }; E19A10CA1B010AA0006192B0 /* WPURLRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E19A10C91B010AA0006192B0 /* WPURLRequestTest.m */; }; E19DF741141F7BDD000002F3 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E19DF740141F7BDD000002F3 /* libz.dylib */; }; E1A03EE217422DCF0085D192 /* BlogToAccount.m in Sources */ = {isa = PBXBuildFile; fileRef = E1A03EE117422DCE0085D192 /* BlogToAccount.m */; }; @@ -1555,6 +1556,7 @@ E18EE94C19349EBA00B0A40C /* BlogServiceRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlogServiceRemote.h; sourceTree = ""; }; E18EE94F19349EC300B0A40C /* ReaderTopicServiceRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReaderTopicServiceRemote.h; sourceTree = ""; }; E18EE95019349EC300B0A40C /* ReaderTopicServiceRemote.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReaderTopicServiceRemote.m; sourceTree = ""; }; + E18FCF071C062B84005FCA25 /* AccountSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountSettings.swift; sourceTree = ""; }; E1939C671B15B4D2001AFEF7 /* WordPress 30.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 30.xcdatamodel"; sourceTree = ""; }; E19853331755E461001CC6D5 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = ""; }; E19853341755E4B3001CC6D5 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = ""; }; @@ -2053,6 +2055,7 @@ B545186718E9E08000AC3A54 /* Notifications */, 5D42A3D6175E7452005CFF05 /* AbstractPost.h */, 5D42A3D7175E7452005CFF05 /* AbstractPost.m */, + E18FCF071C062B84005FCA25 /* AccountSettings.swift */, 5D42A3D8175E7452005CFF05 /* BasePost.h */, 5D42A3D9175E7452005CFF05 /* BasePost.m */, CEBD3EA90FF1BA3B00C1396E /* Blog.h */, @@ -4791,6 +4794,7 @@ 5D6C4B121B604190005E3C43 /* RichTextView.swift in Sources */, 5D119DA3176FBE040073D83A /* UIImageView+AFNetworkingExtra.m in Sources */, 5DF59C0B1770AE3A00171208 /* UILabel+SuggestSize.m in Sources */, + E18FCF081C062B84005FCA25 /* AccountSettings.swift in Sources */, E1F5A1BC1771C90A00E0495F /* WPTableImageSource.m in Sources */, 5948AD0E1AB734F2006E8882 /* WPAppAnalytics.m in Sources */, 851734431798C64700A30E27 /* NSURL+Util.m in Sources */,