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( private static $extensions = array(
'DocumentationViewerVersionWarning' 'DocumentationViewerVersionWarning'
); );
/** /**
* @var array * @var array
*/ */
private static $allowed_actions = array( private static $allowed_actions = array(
'home', 'home',
'all',
'LanguageForm', 'LanguageForm',
'doLanguageForm', 'doLanguageForm',
'handleRequest', 'handleRequest',
@ -144,6 +145,8 @@ class DocumentationViewer extends Controller {
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function handleAction($request, $action) { public function handleAction($request, $action) {
$action = $request->param('Action');
try { try {
if(preg_match('/DocumentationSearchForm/', $request->getURL())) { if(preg_match('/DocumentationSearchForm/', $request->getURL())) {
$action = 'results'; $action = 'results';
@ -174,29 +177,33 @@ class DocumentationViewer extends Controller {
if(!$request->isGET() || isset($_GET['action_results'])) { if(!$request->isGET() || isset($_GET['action_results'])) {
return $response; 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); if($response->getStatusCode() !== 200) {
$body = $this->renderWith(array( // look up the manifest to see find the nearest match against the
"DocumentationViewer_{$type}", // list of the URL. If the URL exists then set that as the current
"DocumentationViewer" // 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() { public function getVersions() {
return ($this->record) ? $this->record->getEntity()->getVersions() : null; 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 * Generate a list of entities which have been registered and which can
@ -322,14 +336,30 @@ class DocumentationViewer extends Controller {
* *
* @return string * @return string
*/ */
public function Link() { public function Link($action = '') {
$link = Controller::join_links( $link = Controller::join_links(
Director::absoluteBaseURL(), Director::absoluteBaseURL(),
Config::inst()->get('DocumentationViewer', 'link_base') Config::inst()->get('DocumentationViewer', 'link_base'),
$action
); );
return $link; 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. * Build the language dropdown.

View File

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

View File

@ -81,7 +81,7 @@ class DocumentationEntity extends ViewableData {
return false; return false;
} }
$sortedVersions = $this->getVersions(); $sortedVersions = $this->getVersions()->toArray();
usort($sortedVersions, create_function('$a,$b', 'return version_compare($a,$b);')); 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() { 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 $this->entity->getTitle();
} }
/**
* @return DocumentationEntity
*/
public function getEntity() {
return $this->entity;
}
/** /**
* Returns an integer value based on if a given version is the latest * Returns an integer value based on if a given version is the latest

View File

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

View File

@ -62,6 +62,10 @@ p {
margin: 0 0 10px; margin: 0 0 10px;
} }
.text-wrap {
word-break: break-all;
}
/*! lists */ /*! lists */
ul { ul {
margin: 15px 0 20px 20px; margin: 15px 0 20px 20px;
@ -95,11 +99,32 @@ dd {
margin: 5px 0 10px 20px; 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 */ /*! headers */
h1 { h1 {
font-size: 30px; font-size: 30px;
line-height: 30px; line-height: 30px;
margin-bottom: 10px; margin-bottom: 10px;
margin-top: 0;
letter-spacing: -1px; letter-spacing: -1px;
} }

View File

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