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

ENH Updated UI for versioned objects and all its versioned relations #2912

Closed
Closed
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
34 changes: 34 additions & 0 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\HiddenClass;
use SilverStripe\ORM\Hierarchy\Hierarchy;
Expand Down Expand Up @@ -1089,11 +1090,44 @@ public function Breadcrumbs($unlinked = false)
]));
}

$badge = null;
$status = $this->getStatusFlag($record);

if (count($status) > 0) {
$flags = '';
foreach ($status as $flag => $flagData) {
$titleAttrebute = sprintf(' title="%s"', Convert::raw2xml($flagData['title']));
$flags .= sprintf(
'<span class="badge version-status version-status--%s" %s>%s</span>',
'status-' . Convert::raw2xml($flag),
(isset($flagData['title'])) ? $titleAttrebute : '',
Convert::raw2xml($flagData['text'])
);
}
$badge = DBField::create_field('HTMLFragment', $flags);
}

$this->extend('updateBadge', $badge);

if ($badge) {
/** @var ArrayData $lastItem */
$lastItem = $items->last();
$lastItem->setField('Extra', $badge);
}

$this->extend('updateBreadcrumbs', $items);

return $items;
}

private function getStatusFlag(SiteTree $record): array
{
$flags = $record->getStatusFlags();
$this->extend('updateStatusFlags', $flags);

return $flags;
}

/**
* Create serialized JSON string with site tree hints data to be injected into
* 'data-hints' attribute of root node of jsTree.
Expand Down
4 changes: 2 additions & 2 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@ public function getCMSActions()
// Get status of page
$isOnDraft = $this->isOnDraft();
$isPublished = $this->isPublished();
$stagesDiffer = $this->stagesDiffer();
$stagesDiffer = $this->_cache_statusFlags ? true : $this->stagesDifferRecursive();

// Check permissions
$canPublish = $this->canPublish();
Expand Down Expand Up @@ -2960,7 +2960,7 @@ public function getStatusFlags($cached = true)
'text' => _t(__CLASS__.'.ADDEDTODRAFTSHORT', 'Draft'),
'title' => _t(__CLASS__.'.ADDEDTODRAFTHELP', "Page has not been published yet")
];
} elseif ($this->isModifiedOnDraft()) {
} elseif ($this->isModifiedOnDraft() || $this->stagesDifferRecursive()) {
$flags['modified'] = [
'text' => _t(__CLASS__.'.MODIFIEDONDRAFTSHORT', 'Modified'),
'title' => _t(__CLASS__.'.MODIFIEDONDRAFTHELP', 'Page has unpublished changes'),
Expand Down
7 changes: 7 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ en:
SilverStripe\CMS\Controllers\CMSMain:
ACCESS: "Access to '{title}' section"
ACCESS_HELP: 'Allow viewing of the section containing page tree and content. View and edit permissions can be handled through page specific dropdowns, as well as the separate "Content permissions".'
ADDEDTODRAFTHELP: 'Page has not been published yet'
ARCHIVE: Archive
ARCHIVEDPAGE: "Archived page '{title}'"
ARCHIVEDPAGEHELP: 'Page is removed from draft and live'
ARCHIVEDPAGESHORT: 'Archived'
AddNew: 'Add new page'
AddNewButton: 'Add new'
AddPageRestriction: 'Note: Some page types are not allowed for this selection'
Expand All @@ -31,7 +34,11 @@ en:
DUPLICATED: "Duplicated '{title}' successfully"
DUPLICATEDWITHCHILDREN: "Duplicated '{title}' and children successfully"
EMAIL: Email
MODIFIEDONDRAFTSHORT: 'Modified'
MODIFIEDONDRAFTHELP: 'Page has unpublished changes'
NEWPAGE: 'New {pagetype}'
ONLIVEONLYSHORT: 'On live only'
ONLIVEONLYSHORTHELP: 'Page is published, but has been deleted from draft'
PAGENOTEXISTS: "This page doesn't exist"
PAGES: 'Page status'
PAGESALLOPT: 'All pages'
Expand Down
78 changes: 78 additions & 0 deletions tests/behat/features/page-with-versioned-objects.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Feature: Publish a page
As a site owner
I want see versioned badge on page with draft and modified versioned child objects

Background:
Given a "Test Page Versioned Object" "My Page" with "URLSegment"="my-page"
And the "Test Page Versioned Object" "My Page" is not published
And the "Versioned parent object" "My Versioned Parent Object" with "TestPageVersionedObject"="1"
And the "Non Versioned parent object" "My Non Versioned Parent Object" with "TestPageVersionedObject"="1"
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "TEST_DATAOBJECT_EDIT"
And I am logged in as a member of "EDITOR" group

Scenario: I should see versioned badge on page with draft and modified versioned child object
Given I go to "/admin/pages"
And I should see "My Page" in the tree
And I click on "My Page" in the tree
Then I should see "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
And I click on the "#tab-Root_VersionedParentObjects" element
And I should see "My Versioned Parent Object" in the "#Form_EditForm" element
And I should see "Draft" in the "#Form_EditForm" element
Then I click "My Versioned Parent Object" in the "#Form_EditForm_VersionedParentObjects" element
And I should see "My Versioned Parent Object" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
And I click "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
Then I click "My Versioned Parent Object" in the "#Form_EditForm_VersionedParentObjects" element
And I press the "Publish" button
And I should not see "Draft" in the ".breadcrumbs-wrapper" element
And I click "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
Then I click "My Versioned Parent Object" in the "#Form_EditForm_VersionedParentObjects" element
And I fill in "Name" with "My Versioned Parent Object with changes"
And I press the "Save" button
Then I should see "Modified" in the ".breadcrumbs-wrapper" element
And I click "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
Then I press the "Publish" button
And I should not see "Modified" in the ".breadcrumbs-wrapper" element
And I should not see "Modified" in the "#Form_EditForm" element

Scenario: I should see versioned badge on page with draft and modified versioned grandchild object
Given I go to "/admin/pages"
And I should see "My Page" in the tree
And I click on "My Page" in the tree
Then I should see "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
And I click on the "#tab-Root_NonVersionedParentObjects" element
Then I click "My Non Versioned Parent Object" in the "#Form_EditForm_NonVersionedParentObjects" element
And I should not see "Draft" in the ".breadcrumbs-wrapper" element
Then I click "Versioned child objects" in the ".ui-tabs-nav" element
And I click "Add Versioned Child Object" in the "#Form_ItemEditForm_VersionedChildObjects" element
And I fill in "Name" with "My Versioned child object"
And I press the "Create" button
And I wait 2 seconds
And I should see "Draft" in the ".breadcrumbs-wrapper" element
Then I click "My Non Versioned Parent Object" in the ".breadcrumbs-wrapper" element
And I should see "Modified" in the ".breadcrumbs-wrapper" element
Then I click "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Draft" in the ".breadcrumbs-wrapper" element
And I should see "My Non Versioned Parent Object" in the "#Form_EditForm" element
And I should see "Modified" in the "#Form_EditForm" element
And I press the "Publish" button
Then I click "My Non Versioned Parent Object" in the "#Form_EditForm" element
Then I click "Versioned child objects" in the ".ui-tabs-nav" element
And I click "My Versioned child object" in the "#Form_ItemEditForm_VersionedChildObjects" element
And I fill in "Name" with "My Versioned child object with changes"
Then I press the "Save" button
And I should see "Modified" in the ".breadcrumbs-wrapper" element
Then I click "My Non Versioned Parent Object" in the ".breadcrumbs-wrapper" element
And I should see "Modified" in the ".breadcrumbs-wrapper" element
And I click "Versioned child objects" in the ".ui-tabs-nav" element
And I should see "Versioned child object with changes" in the "#Form_ItemEditForm_VersionedChildObjects" element
And I should see "Modified" in the "#Form_ItemEditForm_VersionedChildObjects" element
Then I click "My Page" in the ".breadcrumbs-wrapper" element
And I should see "Modified" in the ".breadcrumbs-wrapper" element
And I should see "My Non Versioned Parent Object" in the "#Form_EditForm" element
And I should see "Modified" in the "#Form_EditForm" element
Loading