Skip to content
Merged
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
150 changes: 112 additions & 38 deletions WordPress/Classes/ViewRelated/Blog/SiteSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@
};

NS_ENUM(NSInteger, SiteSettingsWriting) {
SiteSettingsWritingGeotagging = 0,
SiteSettingsWritingDefaultCategory,
SiteSettingsWritingDefaultCategory = 0,
SiteSettingsWritingDefaultPostFormat,
SiteSettingsWritingRelatedPosts,
SiteSettingsWritingCount,
};

NS_ENUM(NSInteger, SiteSettingsDevice) {
SiteSettingsDeviceGeotagging = 0,
SiteSettingsDeviceDefaultCategory,
SiteSettingsDeviceDefaultPostFormat,
SiteSettingsDeviceCount,
};

NS_ENUM(NSInteger, SiteSettingsAdvanced) {
SiteSettingsAdvancedStartOver = 0,
SiteSettingsAdvancedDeleteSite,
Expand All @@ -61,6 +67,7 @@
SiteSettingsSectionAccount,
SiteSettingsSectionWriting,
SiteSettingsSectionDiscussion,
SiteSettingsSectionDevice,
SiteSettingsSectionRemoveSite,
SiteSettingsSectionAdvanced,
};
Expand All @@ -78,12 +85,13 @@ @interface SiteSettingsViewController () <UITableViewDelegate, UITextFieldDelega
@property (nonatomic, strong) SettingTableViewCell *usernameTextCell;
@property (nonatomic, strong) SettingTableViewCell *passwordTextCell;
#pragma mark - Writing Section
@property (nonatomic, strong) SwitchTableViewCell *geotaggingCell;
@property (nonatomic, strong) SettingTableViewCell *defaultCategoryCell;
@property (nonatomic, strong) SettingTableViewCell *defaultPostFormatCell;
@property (nonatomic, strong) SettingTableViewCell *relatedPostsCell;
#pragma mark - Discussion
#pragma mark - Discussion Section
@property (nonatomic, strong) SettingTableViewCell *discussionSettingsCell;
#pragma mark - Device Section
@property (nonatomic, strong) SwitchTableViewCell *geotaggingCell;
#pragma mark - Removal Section
@property (nonatomic, strong) UITableViewCell *removeSiteCell;
#pragma mark - Advanced Section
Expand Down Expand Up @@ -128,12 +136,16 @@ - (void)viewDidLoad
[sections addObject:@(SiteSettingsSectionAccount)];
}

[sections addObject:@(SiteSettingsSectionWriting)];
if ([self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin) {
[sections addObject:@(SiteSettingsSectionWriting)];
}

if ([self.blog supports:BlogFeatureWPComRESTAPI]) {
[sections addObject:@(SiteSettingsSectionDiscussion)];
}

[sections addObject:@(SiteSettingsSectionDevice)];

if ([self.blog supports:BlogFeatureRemovable]) {
[sections addObject:@(SiteSettingsSectionRemoveSite)];
}
Expand Down Expand Up @@ -195,21 +207,19 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return SiteSettingsAccountCount;
}
case SiteSettingsSectionWriting: {
if (!self.blog.isAdmin) {
// If we're not admin, we just want to show the geotagging cell
return 1;
}
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: {
return 1;
}
Expand Down Expand Up @@ -339,22 +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 (SiteSettingsWritingGeotagging):{
return self.geotaggingCell;
}
break;
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):{
Expand All @@ -366,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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nitpicky code style stuff, but for consistency within the file maybe remove the parenthesis in the case statements and remove the breaks since each case returns?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style consistency of the switch cases and breaks in this file are all over the place. I'm going to leave this alone for now as it would require touching a lot more code than the context of this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough :)


}
return nil;
}

- (SettingTableViewCell *)siteTitleCell
{
if (_siteTitleCell) {
Expand Down Expand Up @@ -494,6 +532,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case SiteSettingsSectionDiscussion: {
return self.discussionSettingsCell;
}
case SiteSettingsSectionDevice: {
return [self tableView:tableView cellForDeviceSettingsAtRow:indexPath.row];
}
case SiteSettingsSectionRemoveSite: {
return self.removeSiteCell;
}
Expand Down Expand Up @@ -546,6 +587,9 @@ - (NSString *)titleForHeaderInSection:(NSInteger)section
case SiteSettingsSectionWriting:
headingTitle = NSLocalizedString(@"Writing", @"Title for the writing section in site settings screen");
break;
case SiteSettingsSectionDevice:
headingTitle = NSLocalizedString(@"This Device", @"Title for the device section in site settings screen");
break;
case SiteSettingsSectionAdvanced:
headingTitle = NSLocalizedString(@"Advanced", @"Title for the advanced section in site settings screen");
break;
Expand Down Expand Up @@ -659,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;
Expand All @@ -685,7 +745,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];
}
}
}
};
Expand All @@ -704,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:{
Expand All @@ -726,7 +777,20 @@ - (void)tableView:(UITableView *)tableView didSelectInWritingSectionRow:(NSInteg
[self showRelatedPostsSettings];
}
break;
}
}

- (void)tableView:(UITableView *)tableView didSelectInDeviceSectionRow:(NSInteger)row
{
switch (row) {
case SiteSettingsDeviceDefaultCategory:{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the { } here, but no harm either.

[self showDefaultCategorySelector];
}
break;
case SiteSettingsDeviceDefaultPostFormat:{
[self showPostFormatSelector];
}
break;
}
}

Expand Down Expand Up @@ -774,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];
Expand Down Expand Up @@ -932,6 +999,11 @@ - (void)saveSettings
}];
}

- (BOOL)savingWritingDefaultsIsAvailable
{
return [self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin;
}

- (IBAction)cancel:(id)sender
{
if (self.isCancellable) {
Expand Down Expand Up @@ -1002,7 +1074,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