Skip to content
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
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def wordpress_ui
end

def wordpress_kit
pod 'WordPressKit', '~> 4.9.0-beta.1'
pod 'WordPressKit', '~> 4.9.0-beta.2'
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :tag => ''
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => ''
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => 'feature/homepage-settings'
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :commit => ''
#pod 'WordPressKit', :path => '../WordPressKit-iOS'
end
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ PODS:
- WordPressKit (~> 4.9.0-beta.1)
- WordPressShared (~> 1.8.16)
- WordPressUI (~> 1.7.0)
- WordPressKit (4.9.0-beta.1):
- WordPressKit (4.9.0-beta.2):
- Alamofire (~> 4.8.0)
- CocoaLumberjack (~> 3.4)
- NSObject-SafeExpectations (= 0.0.4)
Expand Down Expand Up @@ -484,7 +484,7 @@ DEPENDENCIES:
- SVProgressHUD (= 2.2.5)
- WordPress-Editor-iOS (~> 1.19.1)
- WordPressAuthenticator (~> 1.17.0-beta.7)
- WordPressKit (~> 4.9.0-beta.1)
- WordPressKit (~> 4.9.0-beta.2)
- WordPressMocks (~> 0.0.8)
- WordPressShared (~> 1.8.16)
- WordPressUI (~> 1.7.0)
Expand Down Expand Up @@ -709,7 +709,7 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: 25a9cbe204a22dd6d540d66d90b8a889421e0b42
WordPress-Editor-iOS: 9f3d720086b90fd8b73f8eccd744c15abbdb7607
WordPressAuthenticator: aa6c0a219c17cdfdb19fe6c2a1859b2577857cd5
WordPressKit: e8aab0ace717c9b9be307ccfdda08821f31b655c
WordPressKit: e4985f2f9834ea67d1f88e114564103e0d6f94c9
WordPressMocks: b4064b99a073117bbc304abe82df78f2fbe60992
WordPressShared: 1bc316ed162f42af4e0fa2869437e9e28b532b01
WordPressUI: 1cf47a3b78154faf69caa18569ee7ece1e510fa0
Expand All @@ -725,6 +725,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: a87ab1e4badace92c75eb11dc77ede1e995b2adc
ZIPFoundation: 249fa8890597086cd536bb2df5c9804d84e122b0

PODFILE CHECKSUM: 163eb7f9c122cdb34d0147af94628a7bb40f62d8
PODFILE CHECKSUM: 101e0cc713d0978244471453c85f8c85d0408049

COCOAPODS: 1.8.4
80 changes: 80 additions & 0 deletions WordPress/Classes/Models/Blog+HomepageSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Foundation

enum HomepageType: String {
case page
case posts

var title: String {
switch self {
case .page:
return NSLocalizedString("Static Homepage", comment: "Name of setting configured when a site uses a static page as its homepage")
case .posts:
return NSLocalizedString("Classic Blog", comment: "Name of setting configured when a site uses a list of blog posts as its homepage")
}
}

var remoteType: RemoteHomepageType {
switch self {
case .page:
return .page
case .posts:
return .posts
}
}
}

extension Blog {
private enum OptionsKeys {
static let homepageType = "show_on_front"
static let homepageID = "page_on_front"
static let postsPageID = "page_for_posts"
}

/// The type of homepage used for the site: blog posts, or static pages
///
var homepageType: HomepageType? {
get {
guard let options = options,
!options.isEmpty,
let type = getOptionString(name: OptionsKeys.homepageType)
else {
return nil
}

return HomepageType(rawValue: type)
}
set {
if let value = newValue?.rawValue {
setValue(value, forOption: OptionsKeys.homepageType)
}
}
}

/// The ID of the page to use for the site's 'posts' page,
/// if `homepageType` is set to `.posts`
///
var homepagePostsPageID: Int? {
guard let options = options,
!options.isEmpty,
let pageID = getOptionNumeric(name: OptionsKeys.postsPageID)
else {
return nil
}

return pageID.intValue
}

/// The ID of the page to use for the site's homepage,
/// if `homepageType` is set to `.page`
///
var homepagePageID: Int? {
guard let options = options,
!options.isEmpty,
let pageID = getOptionNumeric(name: OptionsKeys.homepageID)
else {
return nil
}

return pageID.intValue
}
}
4 changes: 2 additions & 2 deletions WordPress/Classes/Models/Blog+Jetpack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ extension Blog {
return getOptionValue(name) as? T
}

private func getOptionString(name: String) -> String? {
func getOptionString(name: String) -> String? {
return (getOption(name: name) as NSString?).map(String.init)
}

private func getOptionNumeric(name: String) -> NSNumber? {
func getOptionNumeric(name: String) -> NSNumber? {
switch getOptionValue(name) {
case let numericValue as NSNumber:
return numericValue
Expand Down
5 changes: 4 additions & 1 deletion WordPress/Classes/Models/Blog.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ typedef NS_ENUM(NSUInteger, BlogFeature) {
/// Does the blog support deleting media?
BlogFeatureMediaDeletion,
/// Does the blog support Stock Photos feature (free photos library)
BlogFeatureStockPhotos
BlogFeatureStockPhotos,
/// Does the blog support setting the homepage type and pages?
BlogFeatureHomepageSettings
};

typedef NS_ENUM(NSInteger, SiteVisibility) {
Expand Down Expand Up @@ -195,6 +197,7 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
- (BOOL)isPrivateAtWPCom;
- (nullable NSArray *)sortedCategories;
- (nullable id)getOptionValue:(NSString *) name;
- (void)setValue:(id)value forOption:(NSString *)name;
- (NSString *)loginUrl;
- (NSString *)urlWithPath:(NSString *)path;
- (NSString *)adminUrlWithPath:(NSString *)path;
Expand Down
18 changes: 18 additions & 0 deletions WordPress/Classes/Models/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ - (BOOL)supports:(BlogFeature)feature
return [self supportsRestApi] && [self isAdmin];
case BlogFeatureMediaDeletion:
return [self isAdmin];
case BlogFeatureHomepageSettings:
return [self supportsRestApi] && [self isAdmin];
}
}

Expand Down Expand Up @@ -797,4 +799,20 @@ - (id)getOptionValue:(NSString *)name
return optionValue;
}

- (void)setValue:(id)value forOption:(NSString *)name
{
[self.managedObjectContext performBlockAndWait:^{
if ( self.options == nil || (self.options.count == 0) ) {
return;
}

NSMutableDictionary *mutableOptions = [self.options mutableCopy];

NSDictionary *valueDict = @{ @"value": value };
mutableOptions[name] = valueDict;

self.options = [NSDictionary dictionaryWithDictionary:mutableOptions];
}];
}

@end
59 changes: 59 additions & 0 deletions WordPress/Classes/Services/HomepageSettingsService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Foundation
import WordPressKit

/// Service allowing updating of homepage settings
///
struct HomepageSettingsService {
public enum ResponseError: Error {
case decodingFailed
}

let blog: Blog

fileprivate let context: NSManagedObjectContext
fileprivate let remote: HomepageSettingsServiceRemote
fileprivate let siteID: Int

init?(blog: Blog, context: NSManagedObjectContext) {
guard let api = blog.wordPressComRestApi(), let dotComID = blog.dotComID as? Int else {
return nil
}

self.remote = HomepageSettingsServiceRemote(wordPressComRestApi: api)
self.siteID = dotComID
self.blog = blog
self.context = context
}

public func setHomepageType(_ type: HomepageType,
withPostsPageID postsPageID: Int? = nil,
homePageID: Int? = nil,
success: @escaping () -> Void,
failure: @escaping (Error) -> Void) {

let originalHomepageType = blog.homepageType

switch type {
case .page:
blog.homepageType = .page
case .posts:
blog.homepageType = .posts
}

ContextManager.sharedInstance().save(context)

remote.setHomepageType(type: type.remoteType,
for: siteID,
withPostsPageID: postsPageID,
homePageID: homePageID,
success: success,
failure: { error in
self.context.performAndWait {
self.blog.homepageType = originalHomepageType
ContextManager.sharedInstance().saveContextAndWait(self.context)
}

failure(error)
})
}
}
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PostService.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern const NSUInteger PostServiceDefaultNumberToSync;
- (Post *)createDraftPostForBlog:(Blog *)blog;
- (Page *)createDraftPageForBlog:(Blog *)blog;

- (AbstractPost *)findPostWithID:(NSNumber *)postID inBlog:(Blog *)blog;
- (nullable AbstractPost *)findPostWithID:(NSNumber *)postID inBlog:(Blog *)blog;

- (NSUInteger)countPostsWithoutRemote;

Expand Down
5 changes: 5 additions & 0 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum FeatureFlag: Int, CaseIterable {
case floatingCreateButton
case newReaderNavigation
case tenor
case homepageSettings

/// Returns a boolean indicating if the feature is enabled
var enabled: Bool {
Expand All @@ -37,6 +38,8 @@ enum FeatureFlag: Int, CaseIterable {
return true
case .tenor:
return BuildConfiguration.current ~= [.localDeveloper, .a8cBranchTest]
case .homepageSettings:
return BuildConfiguration.current == .localDeveloper
}
}
}
Expand Down Expand Up @@ -73,6 +76,8 @@ extension FeatureFlag: OverrideableFlag {
return "New Reader Navigation"
case .tenor:
return "Tenor GIF media source"
case .homepageSettings:
return "Homepage Settings"
}
}

Expand Down
24 changes: 24 additions & 0 deletions WordPress/Classes/Utility/WPImmuTableRows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ struct CheckmarkRow: ImmuTableRow {

}

struct ActivityIndicatorRow: ImmuTableRow {
static let cell = ImmuTableCell.class(WPTableViewCellDefault.self)

let title: String
let animating: Bool
let action: ImmuTableAction?

func configureCell(_ cell: UITableViewCell) {
cell.textLabel?.text = title

let indicator = UIActivityIndicatorView(style: .gray)
indicator.tintColor = WPStyleGuide.cellGridiconAccessoryColor()

if animating {
indicator.startAnimating()
}

cell.accessoryView = indicator

WPStyleGuide.configureTableViewCell(cell)
}

}

struct LinkRow: ImmuTableRow {
static let cell = ImmuTableCell.class(WPTableViewCellDefault.self)

Expand Down
Loading