FIX Use the first stable version to list pages in "all"

* Add version to Pages as they are built in the DocumentationManifest
* Add getter for version from request/URL
* Filter Pages in Documentation Index by the requested version
This commit is contained in:
Robbie Averill 2016-12-07 10:32:37 +13:00
parent 40d70a0b32
commit 1a4475af1b
No known key found for this signature in database
GPG Key ID: 99FDF145321F81D6
5 changed files with 55 additions and 16 deletions

View File

@ -432,12 +432,13 @@ class DocumentationManifest
$link = $this->stripLinkBase($page->Link());
$this->pages[$link] = array(
'title' => $page->getTitle(),
'basename' => $basename,
'filepath' => DocumentationHelper::normalizePath($path),
'type' => get_class($page),
'title' => $page->getTitle(),
'version' => $page->getVersion(),
'basename' => $basename,
'filepath' => DocumentationHelper::normalizePath($path),
'type' => get_class($page),
'entitypath' => $this->entity->getPath(),
'summary' => $page->getSummary()
'summary' => $page->getSummary()
);
}

View File

@ -251,7 +251,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
if (in_array($action, $allowed)) {
//
// if it's one of the allowed actions such as search or all then the
// URL must be prefixed with one of the allowed languages.
// URL must be prefixed with one of the allowed languages and versions
//
return parent::handleAction($request, $action);
} else {
@ -275,8 +275,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
$type = get_class($this->record);
$body = $this->renderWith(
array(
"DocumentationViewer_{$type}",
"DocumentationViewer"
"DocumentationViewer_{$type}",
'DocumentationViewer'
)
);
@ -288,8 +288,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
} elseif (!$url || $url == $lang) {
$body = $this->renderWith(
array(
"DocumentationViewer_DocumentationFolder",
"DocumentationViewer"
'DocumentationViewer_DocumentationFolder',
'DocumentationViewer'
)
);
@ -572,15 +572,21 @@ class DocumentationViewer extends Controller implements PermissionProvider
* Generate a list of all the pages in the documentation grouped by the
* first letter of the page.
*
* @param string|int|null $version
* @return GroupedList
*/
public function AllPages()
public function AllPages($version = null)
{
$pages = $this->getManifest()->getPages();
$output = new ArrayList();
$baseLink = $this->getDocumentationBaseHref();
foreach ($pages as $url => $page) {
// Option to skip Pages that do not belong to the current version
if (!is_null($version) && (string) $page['version'] !== (string) $version) {
continue;
}
$first = strtoupper(trim(substr($page['title'], 0, 1)));
if ($first) {
@ -599,6 +605,16 @@ class DocumentationViewer extends Controller implements PermissionProvider
return GroupedList::create($output->sort('Title', 'ASC'));
}
/**
* Return all Pages that apply to the current version (from the route)
*
* @return GroupedList
*/
public function getAllVersionPages()
{
return $this->AllPages($this->getRequestedVersion());
}
/**
* Documentation Search Form. Allows filtering of the results by many entities
* and multiple versions.
@ -761,4 +777,24 @@ class DocumentationViewer extends Controller implements PermissionProvider
{
return $this->getManifest()->getHasDefaultEntity();
}
/**
* Gets the requested version from the URL
*
* @return string
*/
public function getRequestedVersion()
{
return (string) $this->request->param('Version');
}
/**
* Gets the link to the "documentation index" containing the currently requested version
*
* @return string
*/
public function getDocumentationIndexLink()
{
return $this->Link($this->getRequestedVersion() . '/all');
}
}

View File

@ -15,7 +15,9 @@ class DocumentationPage extends ViewableData
/**
* @var string
*/
protected $title, $summary, $introduction;
protected $title;
protected $summary;
protected $introduction;
/**
* @var DocumentationEntity

View File

@ -63,7 +63,7 @@
<div class="no-box">
<ul class="minor-nav">
<li><a href="{$Link(all)}">Documentation Index</a></li>
<li><a href="$DocumentationIndexLink">Documentation Index</a></li>
</ul>
</div>
</div>

View File

@ -1,13 +1,13 @@
<div id="documentation_index" class="box">
<div id="page-numbers">
<span>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<% loop $AllVersionPages.GroupedBy(FirstLetter) %>
<a href="#$FirstLetter">$FirstLetter</a>
<% end_loop %>
</span>
</div>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<% loop $AllVersionPages.GroupedBy(FirstLetter) %>
<h2 id="$FirstLetter">$FirstLetter</h2>
<ul class="third semantic">
@ -18,4 +18,4 @@
<% end_loop %>
</ul>
<% end_loop %>
</div>
</div>