Add an alphabetical index (Fixes #5)

This commit is contained in:
Will Rossiter 2014-09-07 20:35:08 +12:00
parent 0b91b91e33
commit 31a3b8a744
9 changed files with 166 additions and 48 deletions

View File

@ -20,12 +20,13 @@ class DocumentationViewer extends Controller {
private static $extensions = array(
'DocumentationViewerVersionWarning'
);
/**
* @var array
*/
private static $allowed_actions = array(
'home',
'all',
'LanguageForm',
'doLanguageForm',
'handleRequest',
@ -144,6 +145,8 @@ class DocumentationViewer extends Controller {
* @return SS_HTTPResponse
*/
public function handleAction($request, $action) {
$action = $request->param('Action');
try {
if(preg_match('/DocumentationSearchForm/', $request->getURL())) {
$action = 'results';
@ -174,29 +177,33 @@ class DocumentationViewer extends Controller {
if(!$request->isGET() || isset($_GET['action_results'])) {
return $response;
}
// look up the manifest to see find the nearest match against the
// list of the URL. If the URL exists then set that as the current
// page to match against.
if($record = $this->getManifest()->getPage($this->request->getURL())) {
$this->record = $record;
$type = get_class($this->record);
$body = $this->renderWith(array(
"DocumentationViewer_{$type}",
"DocumentationViewer"
));
if($response->getStatusCode() !== 200) {
// look up the manifest to see find the nearest match against the
// list of the URL. If the URL exists then set that as the current
// page to match against.
if($record = $this->getManifest()->getPage($this->request->getURL())) {
$this->record = $record;
return new SS_HTTPResponse($body, 200);
$type = get_class($this->record);
$body = $this->renderWith(array(
"DocumentationViewer_{$type}",
"DocumentationViewer"
));
return new SS_HTTPResponse($body, 200);
}
else {
$this->init();
$class = get_class($this);
$body = $this->renderWith(array("{$class}_error", $class));
return new SS_HTTPResponse($body, 404);
}
}
else {
$this->init();
$class = get_class($this);
$body = $this->renderWith(array("{$class}_error", $class));
return new SS_HTTPResponse($body, 404);
}
return $response;
}
/**
@ -244,6 +251,13 @@ class DocumentationViewer extends Controller {
public function getVersions() {
return ($this->record) ? $this->record->getEntity()->getVersions() : null;
}
/**
* @return DocumentationEntityVersion
*/
public function getStableVersion() {
return ($this->record) ? $this->record->getEntity()->getStableVersion() : null;
}
/**
* Generate a list of entities which have been registered and which can
@ -322,14 +336,30 @@ class DocumentationViewer extends Controller {
*
* @return string
*/
public function Link() {
public function Link($action = '') {
$link = Controller::join_links(
Director::absoluteBaseURL(),
Config::inst()->get('DocumentationViewer', 'link_base')
Config::inst()->get('DocumentationViewer', 'link_base'),
$action
);
return $link;
}
}
public function AllPages() {
$pages = $this->getManifest()->getPages();
$output = new ArrayList();
foreach($pages as $url => $page) {
$output->push(new ArrayData(array(
'Link' => $url,
'Title' => $page['title'],
'FirstLetter' => strtoupper(substr($page['title'], 0, 1))
)));
}
return GroupedList::create($output->sort('Title', 'ASC'));
}
/**
* Build the language dropdown.

View File

@ -14,8 +14,9 @@ class DocumentationViewerVersionWarning extends Extension {
$version = $this->owner->getVersion();
$versions = $this->owner->getVersions();
if($page && $verions->count() > 0) {
if($version && $page && $versions->count() > 0) {
$stable = $this->owner->getStableVersion();
$compare = $version->compare($stable);
// same

View File

@ -81,7 +81,7 @@ class DocumentationEntity extends ViewableData {
return false;
}
$sortedVersions = $this->getVersions();
$sortedVersions = $this->getVersions()->toArray();
usort($sortedVersions, create_function('$a,$b', 'return version_compare($a,$b);'));

View File

@ -35,10 +35,24 @@ class DocumentationEntityLanguage extends ViewableData {
/**
* @return string
* @return DocumentationEntityVersion
*/
public function getVersion() {
return $this->entity->getVersion();
return $this->entity;
}
/**
* @return array
*/
public function getVersions() {
return $this->entity->getEntity()->getVersions();
}
/**
* @return
*/
public function getStableVersion() {
return $this->entity->getEntity()->getStableVersion();
}
/**

View File

@ -128,6 +128,12 @@ class DocumentationEntityVersion extends ViewableData {
return $this->entity->getTitle();
}
/**
* @return DocumentationEntity
*/
public function getEntity() {
return $this->entity;
}
/**
* Returns an integer value based on if a given version is the latest

View File

@ -28,6 +28,10 @@ html {
border-radius: 3px;
}
.no-box {
padding: 15px;
}
/*! main content column */
#content {
float: right;
@ -41,7 +45,8 @@ html {
width: 25%;
float: left;
}
#sidebar .nav {
#sidebar .nav,
#sidebar .minor-nav {
margin: 0;
padding: 0;
list-style: none;
@ -62,6 +67,11 @@ html {
font-weight: bold;
}
#sidebar .minor-nav a {
color: #181C17;
opacity: 0.4;
}
#layout {
padding-bottom: 20px;
}
@ -165,8 +175,9 @@ html {
#page-numbers a {
padding: 3px 5px;
}
#page-numbers span {
background-color: #ACD5CA;
}
#page-numbers a:hover {
color: #FFFFFF;

View File

@ -62,6 +62,10 @@ p {
margin: 0 0 10px;
}
.text-wrap {
word-break: break-all;
}
/*! lists */
ul {
margin: 15px 0 20px 20px;
@ -95,11 +99,32 @@ dd {
margin: 5px 0 10px 20px;
}
.semantic {
list-style: none;
margin: 0;
padding: 0;
}
ul.third {
overflow: hidden;
}
ul.third li {
float: left;
width: 33.3%;
padding-right: 30px;
padding-bottom: 20px;
}
ul.third li:nth-child(3n+1) {
clear: both;
}
/*! headers */
h1 {
font-size: 30px;
line-height: 30px;
margin-bottom: 10px;
margin-top: 0;
letter-spacing: -1px;
}

View File

@ -1,20 +1,28 @@
<div id="sidebar" class="box">
<ul class="nav">
<% loop Entities %>
<% if DefaultEntity %>
<% else %>
<li><a href="$Link" class="$LinkingMode top">$Title <% if IsFolder %><span class="is-folder">&#9658;</span><% end_if %></a>
<% if LinkingMode == current %>
<% if Children %>
<ul>
<% loop Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
<% end_loop %>
</ul><% end_if %>
<% end_if %>
</li>
<% end_if %>
<% end_loop %>
</ul>
<div id="sidebar">
<div class="box">
<ul class="nav">
<% loop Entities %>
<% if DefaultEntity %>
<% else %>
<li><a href="$Link" class="$LinkingMode top">$Title <% if IsFolder %><span class="is-folder">&#9658;</span><% end_if %></a>
<% if LinkingMode == current %>
<% if Children %>
<ul>
<% loop Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
<% end_loop %>
</ul><% end_if %>
<% end_if %>
</li>
<% end_if %>
<% end_loop %>
</ul>
</div>
<div class="no-box">
<ul class="minor-nav">
<li><a href="{$Link(all)}">Documentation Index</a></li>
</ul>
</div>
</div>

View File

@ -0,0 +1,23 @@
<div class="box">
<h1>Documentation Index</h1>
<div id="page-numbers">
<span>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<a href="#$FirstLetter">$FirstLetter</a>
<% end_loop %>
</span>
</div>
<% loop $AllPages.GroupedBy(FirstLetter) %>
<h2 id="$FirstLetter">$FirstLetter</h2>
<ul class="third semantic">
<% loop $Children %>
<li>
<a href="$Link">$Title</a>
</li>
<% end_loop %>
</ul>
<% end_loop %>
</div>