Merge pull request #491 from jaugustin/feat-section-hide-show

[DX] Sections enhancement #489
This commit is contained in:
William Durand 2014-08-25 10:45:25 +02:00
commit 87d269fedb
8 changed files with 107 additions and 20 deletions

View File

@ -27,6 +27,7 @@ class Configuration implements ConfigurationInterface
->prototype('scalar')
->end()
->end()
->booleanNode('default_sections_opened')->defaultValue(true)->end()
->arrayNode('motd')
->addDefaultsIfNotSet()
->children()

View File

@ -31,6 +31,7 @@ class NelmioApiDocExtension extends Extension
$container->setParameter('nelmio_api_doc.motd.template', $config['motd']['template']);
$container->setParameter('nelmio_api_doc.exclude_sections', $config['exclude_sections']);
$container->setParameter('nelmio_api_doc.default_sections_opened', $config['default_sections_opened']);
$container->setParameter('nelmio_api_doc.api_name', $config['name']);
$container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']);
$container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']);

View File

@ -75,6 +75,11 @@ class HtmlFormatter extends AbstractFormatter
*/
private $motdTemplate;
/**
* @var boolean
*/
private $defaultSectionsOpened;
/**
* @param array $authentication
*/
@ -179,6 +184,14 @@ class HtmlFormatter extends AbstractFormatter
return $this->motdTemplate;
}
/**
* @param boolean $defaultSectionsOpened
*/
public function setDefaultSectionsOpened($defaultSectionsOpened)
{
$this->defaultSectionsOpened = $defaultSectionsOpened;
}
/**
* {@inheritdoc}
*/
@ -212,20 +225,21 @@ class HtmlFormatter extends AbstractFormatter
private function getGlobalVars()
{
return array(
'apiName' => $this->apiName,
'authentication' => $this->authentication,
'endpoint' => $this->endpoint,
'enableSandbox' => $this->enableSandbox,
'requestFormatMethod' => $this->requestFormatMethod,
'acceptType' => $this->acceptType,
'bodyFormats' => $this->bodyFormats,
'defaultBodyFormat' => $this->defaultBodyFormat,
'requestFormats' => $this->requestFormats,
'defaultRequestFormat' => $this->defaultRequestFormat,
'date' => date(DATE_RFC822),
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
'motdTemplate' => $this->motdTemplate
'apiName' => $this->apiName,
'authentication' => $this->authentication,
'endpoint' => $this->endpoint,
'enableSandbox' => $this->enableSandbox,
'requestFormatMethod' => $this->requestFormatMethod,
'acceptType' => $this->acceptType,
'bodyFormats' => $this->bodyFormats,
'defaultBodyFormat' => $this->defaultBodyFormat,
'requestFormats' => $this->requestFormats,
'defaultRequestFormat' => $this->defaultRequestFormat,
'date' => date(DATE_RFC822),
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
'motdTemplate' => $this->motdTemplate,
'defaultSectionsOpened' => $this->defaultSectionsOpened,
);
}
}

View File

@ -56,6 +56,9 @@
<call method="setAuthentication">
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
</call>
<call method="setDefaultSectionsOpened">
<argument>%nelmio_api_doc.default_sections_opened%</argument>
</call>
</service>
<service id="nelmio_api_doc.formatter.swagger_formatter" class="%nelmio_api_doc.formatter.swagger_formatter.class%"
parent="nelmio_api_doc.formatter.abstract_formatter" />

View File

@ -439,6 +439,7 @@ Look at the built-in [Handlers](https://github.com/nelmio/NelmioApiDocBundle/tre
nelmio_api_doc:
name: 'API documentation'
exclude_sections: []
default_sections_opened: true
motd:
template: 'NelmioApiDocBundle::Components/motd.html.twig'
request_listener:

View File

@ -172,10 +172,37 @@ table tbody tr td {
}
.section {
border: 1px solid #ddd;
background: #f8f8f8;
padding: 5px 20px;
margin-bottom: 15px;
padding: 5px 20px;
border-bottom: 1px solid #ddd;
}
.section h1 {
padding: 0;
}
.section.active {
border: 1px solid #ddd;
background: #f8f8f8;
margin: 15px 0;
}
.section.active h1 {
padding: 10px 0;
}
.section .actions {
text-align: right;
float: right;
margin-top: 10px;
}
.section .actions a {
cursor: pointer;
margin-left: 10px;
}
.section .actions a:hover {
text-decoration: underline;
}
li.resource {

View File

@ -91,6 +91,11 @@
$('body,html').scrollTop(elem.position().top);
});
elem.find('.toggler').click();
var section = elem.parents('.section').first();
if (section) {
section.addClass('active');
section.find('.section-list').slideDown('fast');
}
}
});
@ -107,6 +112,36 @@
return false;
});
$('.action-show-hide, .section > h1').on('click', function(){
var section = $(this).parents('.section').first();
if (section.hasClass('active')) {
section.removeClass('active');
section.find('.section-list').slideUp('fast');
} else {
section.addClass('active');
section.find('.section-list').slideDown('fast');
}
});
$('.action-list').on('click', function(){
var section = $(this).parents('.section').first();
if (!section.hasClass('active')) {
section.addClass('active');
}
section.find('.section-list').slideDown('fast');
section.find('.content').slideUp('fast');
});
$('.action-expand').on('click', function(){
var section = $(this).parents('.section').first();
if (!section.hasClass('active')) {
section.addClass('active');
}
$(section).find('ul').slideDown('fast');
$(section).find('.content').slideDown('fast');
});
{% if enableSandbox %}
var setParameterType = function ($context,setType) {
// no 2nd argument, use default from parameters

View File

@ -3,9 +3,14 @@
{% block content %}
{% for section, sections in resources %}
{% if section != '_others' %}
<li class="section">
<li class="section{{ defaultSectionsOpened? ' active':'' }}">
<div class="actions">
<a class="action-show-hide">Show/hide</a>
<a class="action-list">List Operations</a>
<a class="action-expand">Expand Operations</a>
</div>
<h1>{{ section }}</h1>
<ul>
<ul class="section-list" {% if not defaultSectionsOpened %}style="display: none"{% endif %}>
{% endif %}
{% for resource, methods in sections %}
<li class="resource">