From 416cf848abf18808e8353a865681f5c63e32e963 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 30 Sep 2015 08:41:51 +0200 Subject: [PATCH] inspect: studio-like tree --- application/controllers/InspectController.php | 44 ++++++++++++++++++ application/views/scripts/inspect/types.phtml | 37 +++++++++++++++ library/Director/Core/CoreApi.php | 22 +++++++++ public/img/leaf.gif | Bin 0 -> 945 bytes public/img/tree.png | Bin 0 -> 524 bytes 5 files changed, 103 insertions(+) create mode 100644 application/controllers/InspectController.php create mode 100644 application/views/scripts/inspect/types.phtml create mode 100644 public/img/leaf.gif create mode 100644 public/img/tree.png diff --git a/application/controllers/InspectController.php b/application/controllers/InspectController.php new file mode 100644 index 00000000..500e8111 --- /dev/null +++ b/application/controllers/InspectController.php @@ -0,0 +1,44 @@ +view->title = $this->translate('Icinga2 object types'); + $api = $this->api(); + $types = $api->getTypes(); + $rootNodes = array(); + foreach ($types as $name => $type) { + if (property_exists($type, 'base')) { + $base = $type->base; + if (! property_exists($types[$base], 'children')) { + $types[$base]->children = array(); + } + + $types[$base]->children[$name] = $type; + } else { + $rootNodes[$name] = $type; + } + } + $this->view->types = $rootNodes; + } + + public function typeAction() + { + print_r($this->api()->getType($this->params->get('name'))); + exit; + } + + protected function api() + { + $apiconfig = $this->Config()->getSection('api'); + $client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port')); + $client->setCredentials($apiconfig->get('username'), $apiconfig->get('password')); + $api = new CoreApi($client); + return $api; + } +} diff --git a/application/views/scripts/inspect/types.phtml b/application/views/scripts/inspect/types.phtml new file mode 100644 index 00000000..387f10bd --- /dev/null +++ b/application/views/scripts/inspect/types.phtml @@ -0,0 +1,37 @@ + $node) { + $html .= '
  • '; + $link = $self->qlink( + $name, + 'director/inspect/type', + array('name' => $name), + array('class' => $node->abstract ? 'abstract' : 'object') + ); + if (property_exists($node, 'children')) { + $html .= ' '; + $html .= $link; + $html .= ''; + } else { + $html .= $link; + } + $html .= '
  • '; + } + + return $html; +} + +?> +
    +tabs ?> +

    escape($this->title) ?>

    +
    + +
    + +
    diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index 86939476..a8f9947b 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -15,6 +15,28 @@ class CoreApi $this->client = $client; } + public function getTypes() + { + return $this->client->get('types')->getResult('name'); + } + + public function getType($type) + { + $res = $this->client->get('types', array('name' => $type))->getResult('name'); + return $res[$type]; // TODO: error checking + } + + public function listObjects($type, $pluralType) + { + // TODO: more abstraction needed + return $this->client->get( + 'objects/' . $pluralType, + array( + 'attrs' => array($type . '.__name', $type . '.name'), + ) + )->getResult('__name'); + } + public function getModules() { return $this->client->get('config/packages')->getResult('name'); diff --git a/public/img/leaf.gif b/public/img/leaf.gif new file mode 100644 index 0000000000000000000000000000000000000000..445769d3f863fff85bf8dae9e50ca2fbdd2d580f GIT binary patch literal 945 zcmZ?wbhEHb6krfwXlDQcQ_o~GuN3{H6Nag0EsGx6l|6PSd+b*I#H;qP!+!_A#wTHI zPb1o&CiOkbneseu`t#JOpR;CuEt~zKYW~Z@xnJuSzARt#t#2GZdv-WZP}~tRj*oB|LorIYr@vw({}!uwfFDhO(&LbJ2U^lzeR`sUwH800T8|T z00#d*{P_PLi2nZvyK9sf4FQ^mfZ|UUW(Ec>1|5)1pgh6A(Z?XlA>*-O!NF!$M-7&b z2M@Kd^GWGABrIrf5YP;mqG0Ic!oef1<ENsed*j@4Yk?RR_1qN#Xfm)wA literal 0 HcmV?d00001 diff --git a/public/img/tree.png b/public/img/tree.png new file mode 100644 index 0000000000000000000000000000000000000000..298343eeabadef1a893ddb8a2b8b7308cb129010 GIT binary patch literal 524 zcmV+n0`vWeP);feM+u$FYSrZhSkI6`5 z@5~!L&(1t^_w_n>jpMi~K2p9UrLU%GPS@+TFWqamfmoIWJ9hQbYIStegq3ZBC`nLj zG#)9XJYtjGVt%z;!j2P;Qs5j1)<~kMDs-F8jP+Fw`scmM}>pf1PKC##RmxoJy2L%A)OLVAkKtz zN;rWy`52F9hlFFRs;&%&sd%BFAHiqt--|A>ZJ`VBe{;~kagfH300RIq10%L(C2R}; O0000