diff options
-rw-r--r-- | appinfo/routes.php | 3 | ||||
-rw-r--r-- | lib/Controller/APIController.php | 47 | ||||
-rw-r--r-- | lib/DetailManager.php | 7 | ||||
-rw-r--r-- | lib/Section.php | 8 |
4 files changed, 45 insertions, 20 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index 7dda8ac..5037b34 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -24,6 +24,7 @@ return [ 'routes' => [ ['name' => 'API#components', 'url' => '/components', 'verb' => 'GET'], - ['name' => 'API#details', 'url' => '/details/{app}', 'verb' => 'GET'] + ['name' => 'API#sections', 'url' => '/sections/{app}', 'verb' => 'GET'], + ['name' => 'API#details', 'url' => '/details/{app}/{sectionIdentifier}', 'verb' => 'GET'] ], ];
\ No newline at end of file diff --git a/lib/Controller/APIController.php b/lib/Controller/APIController.php index ec4a9ae..ad4537f 100644 --- a/lib/Controller/APIController.php +++ b/lib/Controller/APIController.php @@ -75,31 +75,42 @@ class APIController extends Controller { $this->eventDispatcher->dispatch('\OCA\IssueTemplate::requestInformation', $event); } - public function details($app) { + public function sections($app) { + $this->queryAppDetails($app); + + $sections = []; + + /** @var ISection $section */ + foreach ($this->detailManager->getSections() as $section) { + $sections[] = $section; + } + return $sections; + } + + public function details($app, $sectionIdentifier) { $this->queryAppDetails($app); $model = []; $schema = []; - $sections = $this->detailManager->getSections(); - /** @var ISection $section */ - foreach ($sections as $section) { - $model[$section->getIdentifier()] = []; - $group = [ - 'legend' => $section->getTitle(), - 'fields' => [] + $section = $this->detailManager->getSection($sectionIdentifier); + + $model[$section->getIdentifier()] = []; + $group = [ + 'legend' => $section->getTitle(), + 'fields' => [] + ]; + /** @var IDetail $detail */ + foreach ($section->getDetails() as $detail) { + $model[$section->getIdentifier()][$detail->getIdentifier()] = $detail->getInformation(); + $group['fields'][] = [ + 'type' => $this->getTypeFieldSchema($detail->getType()), + 'label' => $detail->getTitle(), + 'model' => $section->getIdentifier() . '.' . $detail->getIdentifier() ]; - /** @var IDetail $detail */ - foreach ($section->getDetails() as $detail) { - $model[$section->getIdentifier()][$detail->getIdentifier()] = $detail->getInformation(); - $group['fields'][] = [ - 'type' => $this->getTypeFieldSchema($detail->getType()), - 'label' => $detail->getTitle(), - 'model' => $section->getIdentifier() . '.' . $detail->getIdentifier() - ]; - } - $schema['groups'][] = $group; } + $schema['groups'][] = $group; + return [ 'model' => $model, 'schema' => $schema diff --git a/lib/DetailManager.php b/lib/DetailManager.php index 8bba6c5..6baf90d 100644 --- a/lib/DetailManager.php +++ b/lib/DetailManager.php @@ -71,6 +71,13 @@ class DetailManager { return $this->sections; } + /** + * @return ISection + */ + public function getSection($identifier) { + return $this->sections[$identifier]; + } + public function getRenderedDetails() { $result = ''; /** @var ISection $section */ diff --git a/lib/Section.php b/lib/Section.php index 05ffeee..4590c99 100644 --- a/lib/Section.php +++ b/lib/Section.php @@ -23,7 +23,7 @@ namespace OCA\IssueTemplate; -class Section implements ISection { +class Section implements ISection, \JsonSerializable { /** @var string */ private $identifier; @@ -77,4 +77,10 @@ class Section implements ISection { return $detail; } + public function jsonSerialize() { + return [ + 'identifier' => $this->getIdentifier(), + 'title' => $this->getTitle(), + ]; + } }
\ No newline at end of file |