From 6c76ae285d64bd0bc8ea61d8341c8b334e056f78 Mon Sep 17 00:00:00 2001 From: kurzee Date: Wed, 3 Feb 2016 17:33:06 -0600 Subject: [PATCH 1/3] Moves Geotagging to "This Device" only shows "Writing" section to admin users. --- .../Blog/SiteSettingsViewController.m | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m b/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m index c5a173f4feb5..5862c7b252b4 100644 --- a/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m +++ b/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m @@ -43,13 +43,17 @@ }; NS_ENUM(NSInteger, SiteSettingsWriting) { - SiteSettingsWritingGeotagging = 0, - SiteSettingsWritingDefaultCategory, + SiteSettingsWritingDefaultCategory = 0, SiteSettingsWritingDefaultPostFormat, SiteSettingsWritingRelatedPosts, SiteSettingsWritingCount, }; +NS_ENUM(NSInteger, SiteSettingsDevice) { + SiteSettingsDeviceGeotagging = 0, + SiteSettingsDeviceCount, +}; + NS_ENUM(NSInteger, SiteSettingsAdvanced) { SiteSettingsAdvancedStartOver = 0, SiteSettingsAdvancedDeleteSite, @@ -61,6 +65,7 @@ SiteSettingsSectionAccount, SiteSettingsSectionWriting, SiteSettingsSectionDiscussion, + SiteSettingsSectionDevice, SiteSettingsSectionRemoveSite, SiteSettingsSectionAdvanced, }; @@ -78,12 +83,13 @@ @interface SiteSettingsViewController () Date: Wed, 3 Feb 2016 18:05:29 -0600 Subject: [PATCH 2/3] Allows non-admin users of XML-RPC to change defaults. --- .../ViewRelated/Blog/SiteSettingsViewController.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m b/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m index 5862c7b252b4..816d7c41f462 100644 --- a/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m +++ b/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m @@ -134,7 +134,7 @@ - (void)viewDidLoad [sections addObject:@(SiteSettingsSectionAccount)]; } - if (self.blog.isAdmin) { + if (self.blog.isAdmin || ![self.blog supports:BlogFeatureWPComRESTAPI]) { [sections addObject:@(SiteSettingsSectionWriting)]; } @@ -696,7 +696,9 @@ - (void)showPostFormatSelector if ([status isKindOfClass:[NSString class]]) { if (weakSelf.blog.settings.defaultPostFormat != status) { weakSelf.blog.settings.defaultPostFormat = status; - [weakSelf saveSettings]; + if ([weakSelf savingWritingDefaultsIsAvailable]) { + [weakSelf saveSettings]; + } } } }; @@ -943,6 +945,11 @@ - (void)saveSettings }]; } +- (BOOL)savingWritingDefaultsIsAvailable +{ + return [self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin; +} + - (IBAction)cancel:(id)sender { if (self.isCancellable) { @@ -1013,7 +1020,9 @@ - (void)postCategoriesViewController:(PostCategoriesViewController *)controller { self.blog.settings.defaultCategoryID = category.categoryID; self.defaultCategoryCell.detailTextLabel.text = category.categoryName; - [self saveSettings]; + if ([self savingWritingDefaultsIsAvailable]) { + [self saveSettings]; + } } @end From 22416502a0bcf700190ceb95b78c7cb2be432892 Mon Sep 17 00:00:00 2001 From: kurzee Date: Wed, 3 Feb 2016 18:28:34 -0600 Subject: [PATCH 3/3] Shows default post options for all XML-RPC users under "This Device" instead. --- .../Blog/SiteSettingsViewController.m | 104 +++++++++++++----- 1 file changed, 79 insertions(+), 25 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m b/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m index 816d7c41f462..67194cf8eb8a 100644 --- a/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m +++ b/WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m @@ -51,6 +51,8 @@ NS_ENUM(NSInteger, SiteSettingsDevice) { SiteSettingsDeviceGeotagging = 0, + SiteSettingsDeviceDefaultCategory, + SiteSettingsDeviceDefaultPostFormat, SiteSettingsDeviceCount, }; @@ -134,7 +136,7 @@ - (void)viewDidLoad [sections addObject:@(SiteSettingsSectionAccount)]; } - if (self.blog.isAdmin || ![self.blog supports:BlogFeatureWPComRESTAPI]) { + if ([self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin) { [sections addObject:@(SiteSettingsSectionWriting)]; } @@ -205,18 +207,17 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger return SiteSettingsAccountCount; } case SiteSettingsSectionWriting: { - NSInteger rowsToHide = 0; - if (![self.blog supports:BlogFeatureWPComRESTAPI]) { - // NOTE: Sergio Estevao (2015-09-23): Hides the related post for self-hosted sites not in jetpack - // because this options is not available for them. - rowsToHide += 1; - } - return SiteSettingsWritingCount - rowsToHide; + return SiteSettingsWritingCount; } case SiteSettingsSectionDiscussion: { return 1; } case SiteSettingsSectionDevice: { + if ([self.blog supports:BlogFeatureWPComRESTAPI]) { + // NOTE: Brent Coursey (2016-02-03): Only show geotagging cell for user of the REST API (REST). + // Any post default options are available in the Writing section for REST users. + return 1; + } return SiteSettingsDeviceCount; } case SiteSettingsSectionRemoveSite: { @@ -348,18 +349,28 @@ - (UITableViewCell *)removeSiteCell return _removeSiteCell; } +- (void)configureDefaultCategoryCell +{ + PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; + PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:self.blog.settings.defaultCategoryID]; + [self.defaultCategoryCell setTextValue:[postCategory categoryName]]; +} + +- (void)configureDefaultPostFormatCell +{ + [self.defaultPostFormatCell setTextValue:self.blog.defaultPostFormatText]; +} + - (UITableViewCell *)tableView:(UITableView *)tableView cellForWritingSettingsAtRow:(NSInteger)row { switch (row) { case (SiteSettingsWritingDefaultCategory):{ - PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; - PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:self.blog.settings.defaultCategoryID]; - [self.defaultCategoryCell setTextValue:[postCategory categoryName]]; + [self configureDefaultCategoryCell]; return self.defaultCategoryCell; } break; case (SiteSettingsWritingDefaultPostFormat):{ - [self.defaultPostFormatCell setTextValue:self.blog.defaultPostFormatText]; + [self configureDefaultPostFormatCell]; return self.defaultPostFormatCell; } case (SiteSettingsWritingRelatedPosts):{ @@ -371,6 +382,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForWritingSettingsAt return nil; } +- (UITableViewCell *)tableView:(UITableView *)tableView cellForDeviceSettingsAtRow:(NSInteger)row +{ + switch (row) { + case (SiteSettingsDeviceGeotagging):{ + return self.geotaggingCell; + } + break; + case (SiteSettingsDeviceDefaultCategory):{ + [self configureDefaultCategoryCell]; + return self.defaultCategoryCell; + } + break; + case (SiteSettingsDeviceDefaultPostFormat):{ + [self configureDefaultPostFormatCell]; + return self.defaultPostFormatCell; + } + break; + + } + return nil; +} + - (SettingTableViewCell *)siteTitleCell { if (_siteTitleCell) { @@ -500,7 +533,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return self.discussionSettingsCell; } case SiteSettingsSectionDevice: { - return self.geotaggingCell; + return [self tableView:tableView cellForDeviceSettingsAtRow:indexPath.row]; } case SiteSettingsSectionRemoveSite: { return self.removeSiteCell; @@ -670,6 +703,22 @@ - (void)tableView:(UITableView *)tableView didSelectInAccountSectionRow:(NSInteg } } +- (void)showDefaultCategorySelector +{ + PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; + NSNumber *defaultCategoryID = self.blog.settings.defaultCategoryID ?: @(PostCategoryUncategorized); + PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:defaultCategoryID]; + NSArray *currentSelection = @[]; + if (postCategory){ + currentSelection = @[postCategory]; + } + PostCategoriesViewController *postCategoriesViewController = [[PostCategoriesViewController alloc] initWithBlog:self.blog + currentSelection:currentSelection + selectionMode:CategoriesSelectionModeBlogDefault]; + postCategoriesViewController.delegate = self; + [self.navigationController pushViewController:postCategoriesViewController animated:YES]; +} + - (void)showPostFormatSelector { NSArray *titles = self.blog.sortedPostFormatNames; @@ -717,18 +766,7 @@ - (void)tableView:(UITableView *)tableView didSelectInWritingSectionRow:(NSInteg { switch (row) { case SiteSettingsWritingDefaultCategory:{ - PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; - NSNumber *defaultCategoryID = self.blog.settings.defaultCategoryID ?: @(PostCategoryUncategorized); - PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:defaultCategoryID]; - NSArray *currentSelection = @[]; - if (postCategory){ - currentSelection = @[postCategory]; - } - PostCategoriesViewController *postCategoriesViewController = [[PostCategoriesViewController alloc] initWithBlog:self.blog - currentSelection:currentSelection - selectionMode:CategoriesSelectionModeBlogDefault]; - postCategoriesViewController.delegate = self; - [self.navigationController pushViewController:postCategoriesViewController animated:YES]; + [self showDefaultCategorySelector]; } break; case SiteSettingsWritingDefaultPostFormat:{ @@ -739,7 +777,20 @@ - (void)tableView:(UITableView *)tableView didSelectInWritingSectionRow:(NSInteg [self showRelatedPostsSettings]; } break; + } +} +- (void)tableView:(UITableView *)tableView didSelectInDeviceSectionRow:(NSInteger)row +{ + switch (row) { + case SiteSettingsDeviceDefaultCategory:{ + [self showDefaultCategorySelector]; + } + break; + case SiteSettingsDeviceDefaultPostFormat:{ + [self showPostFormatSelector]; + } + break; } } @@ -787,6 +838,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath case SiteSettingsSectionDiscussion: { [self showDiscussionSettingsForBlog:self.blog]; } break; + case SiteSettingsSectionDevice: { + [self tableView:tableView didSelectInDeviceSectionRow:indexPath.row]; + } break; case SiteSettingsSectionRemoveSite:{ [tableView deselectSelectedRowWithAnimation:YES]; [self showRemoveSiteForBlog:self.blog];