Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Parent from Page Settings screen #19021

Closed
8 changes: 8 additions & 0 deletions WordPress/Classes/Models/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class Page: AbstractPost {
return date.longUTCStringWithoutTime()
}

/// Boolean indicating whether the page has changes that weren't uploaded yet.
override func hasLocalChanges() -> Bool {
if let originalPage = original as? Page, parentID != originalPage.parentID {
return true
}
return super.hasLocalChanges()
}

/// Returns the selector string to use as a sectionNameKeyPath, depending on the given keyPath.
///
@objc static func sectionIdentifier(dateKeyPath: String) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class EditPageViewController: UIViewController {
fileprivate var content: String?
fileprivate var hasShownEditor = false
fileprivate var isHomePageEditor = false
private var homepageEditorCompletion: HomepageEditorCompletion?

var homepageEditorCompletion: HomepageEditorCompletion?

convenience init(page: Page) {
self.init(page: page, blog: page.blog, postTitle: nil, content: nil, appliedTemplate: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ class PageListViewController: AbstractPostListViewController, UIViewControllerRe
WPAppAnalytics.track(.postListEditAction, withProperties: propertiesForAnalytics(), with: page)

let editorViewController = EditPageViewController(page: page)
editorViewController.homepageEditorCompletion = { [weak self] in
self?._tableViewHandler.refreshTableView()
}

present(editorViewController, animated: false)
}

Expand Down
79 changes: 75 additions & 4 deletions WordPress/Classes/ViewRelated/Pages/PageSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

@interface PageSettingsViewController ()

@property (nonatomic, strong, readonly, nonnull) ParentPagesController *parentPagesController;

@end

@implementation PageSettingsViewController

- (void)configureSections
{
self.sections = @[@(PostSettingsSectionMeta),@(PostSettingsSectionFeaturedImage)];
}
#pragma mark - Properties

- (Page *)page
{
Expand All @@ -22,4 +21,76 @@ - (Page *)page
return nil;
}

#pragma mark - Init

- (instancetype)initWithPost:(AbstractPost *)aPost
{
self = [super initWithPost:aPost];
if (self && self.page && self.page.blog) {
NSManagedObjectContext *mainContext = [[ContextManager sharedInstance] mainContext];
_parentPagesController = [[ParentPagesController alloc] initWithBlog: self.page.blog managedObjectContext:mainContext];
}
return self;
}

#pragma mark - View Lifecycle

- (void)viewWillAppear:(BOOL)animated
{
[self.parentPagesController refreshPages];
[super viewWillAppear: animated];
}

#pragma mark - Table Configuration

- (void)configureSections
{
self.sections = @[@(PostSettingsSectionMeta),@(PostSettingsSectionFeaturedImage)];
}

- (void)configureMetaSectionRows
{
[super configureMetaSectionRows];
NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithArray:self.postMetaSectionRows];
[mutableArray addObject: @(PostSettingsRowParent)];
self.postMetaSectionRows = [mutableArray copy];
}

- (UITableViewCell *)configureMetaPostMetaCellForIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [[self.postMetaSectionRows objectAtIndex:indexPath.row] integerValue];
if (row == PostSettingsRowParent) {
Page *parentPage = [self.parentPagesController selectedParentForPage:self.page];
UITableViewCell *cell = [self getWPTableViewDisclosureCell];
cell.textLabel.text = NSLocalizedString(@"Set Parent", @"Label for a row that opens the Set Parent options view controller");
cell.accessibilityIdentifier = @"SetParentPage";
cell.detailTextLabel.text = parentPage ? parentPage.postTitle : @"";
cell.tag = PostSettingsRowParent;
return cell;
}
return [super configureMetaPostMetaCellForIndexPath:indexPath];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.tag == PostSettingsRowParent) {
[self showSetParentController];
}
}

#pragma mark - User Interaction

- (void)showSetParentController
{
NSArray<Page *> *pages = [self.parentPagesController availableParentsForEditingForPage:self.page];
ParentPageSettingsViewController *controller = [ParentPageSettingsViewController fromStoryboardWith:pages selectedPage:self.page];
controller.uploadChangesOnSave = false;
controller.dismissOnItemSelected = true;
if (self.navigationController) {
[self.navigationController pushViewController:controller animated:true];
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

@objc extension PageSettingsViewController {

convenience init(page: Page) {
self.init(post: page)
}

}
35 changes: 16 additions & 19 deletions WordPress/Classes/ViewRelated/Pages/Pages.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -22,13 +20,13 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LM5-dj-tFF">
<rect key="frame" x="0.0" y="110" width="375" height="557"/>
<rect key="frame" x="0.0" y="90" width="375" height="577"/>
<connections>
<segue destination="54R-UA-mAH" kind="embed" id="f4C-M8-QGj"/>
</connections>
</containerView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kb7-5Y-cyY" customClass="FilterTabBar" customModule="WordPress" customModuleProvider="target">
<rect key="frame" x="0.0" y="64" width="375" height="46"/>
<rect key="frame" x="0.0" y="44" width="375" height="46"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="46" placeholder="YES" id="k7G-Mg-MRE"/>
Expand Down Expand Up @@ -76,7 +74,7 @@
<objects>
<tableViewController id="54R-UA-mAH" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" layoutMarginsFollowReadableWidth="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="47" sectionHeaderHeight="24" sectionFooterHeight="1" id="y3a-Ok-AN1">
<rect key="frame" x="0.0" y="0.0" width="375" height="557"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="577"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<sections/>
Expand All @@ -101,7 +99,7 @@
<objects>
<navigationController storyboardIdentifier="ParentPageSettings" id="QcV-Yi-qZN" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="i29-WU-Owk">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand All @@ -115,7 +113,7 @@
<!--Parent Page Settings View Controller-->
<scene sceneID="pZd-4V-qlT">
<objects>
<viewController id="en5-L6-oun" customClass="ParentPageSettingsViewController" customModule="WordPress" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="ParentPageSettingsViewController" id="en5-L6-oun" customClass="ParentPageSettingsViewController" customModule="WordPress" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="iSZ-D8-Et4"/>
<viewControllerLayoutGuide type="bottom" id="AEa-4M-1Cd"/>
Expand All @@ -125,11 +123,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="rFc-KI-K05">
<rect key="frame" x="0.0" y="120" width="375" height="547"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<rect key="frame" x="0.0" y="95" width="375" height="572"/>
<color key="backgroundColor" systemColor="groupTableViewBackgroundColor"/>
</tableView>
<searchBar contentMode="redraw" translatesAutoresizingMaskIntoConstraints="NO" id="DaX-Id-Nby">
<rect key="frame" x="0.0" y="64" width="375" height="56"/>
<rect key="frame" x="0.0" y="44" width="375" height="51"/>
<textInputTraits key="textInputTraits"/>
</searchBar>
</subviews>
Expand All @@ -145,19 +143,13 @@
</constraints>
</view>
<navigationItem key="navigationItem" id="fJK-CD-lVY">
<barButtonItem key="leftBarButtonItem" title="Cancel" id="vsX-CE-sq7">
<connections>
<action selector="cancelAction:" destination="en5-L6-oun" id="7nD-eL-LcM"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Done" id="Ybc-8A-PTe">
<connections>
<action selector="doneAction:" destination="en5-L6-oun" id="pGj-nC-QNQ"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="cancelButton" destination="vsX-CE-sq7" id="nQK-bh-bZX"/>
<outlet property="doneButton" destination="Ybc-8A-PTe" id="dxy-DZ-9VV"/>
<outlet property="searchBar" destination="DaX-Id-Nby" id="3r8-LD-SOe"/>
<outlet property="tableView" destination="rFc-KI-K05" id="BE5-XQ-QGl"/>
Expand All @@ -168,4 +160,9 @@
<point key="canvasLocation" x="1240.8" y="1047.5262368815593"/>
</scene>
</scenes>
<resources>
<systemColor name="groupTableViewBackgroundColor">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
Loading